-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] RecordingOptions + disconnect stops worker
Created RecordingOptions component to start or stop data recording. Modified worker to stop on headset disconnect. References #25, #27.
- Loading branch information
1 parent
1f00bf2
commit 41d6ebf
Showing
8 changed files
with
141 additions
and
57 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
client/src/components/RecordingOptions/RecordingOptions.lazy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyRecordingOptions = lazy(() => import('./RecordingOptions')); | ||
|
||
const RecordingOptions = (props: JSX.IntrinsicAttributes & { children?: React.ReactNode; }) => ( | ||
<Suspense fallback={null}> | ||
<LazyRecordingOptions {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default RecordingOptions; |
1 change: 1 addition & 0 deletions
1
client/src/components/RecordingOptions/RecordingOptions.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.RecordingOptions {} |
12 changes: 12 additions & 0 deletions
12
client/src/components/RecordingOptions/RecordingOptions.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable */ | ||
import RecordingOptions from './RecordingOptions'; | ||
|
||
export default { | ||
title: "RecordingOptions", | ||
}; | ||
|
||
export const Default = () => <RecordingOptions />; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
14 changes: 14 additions & 0 deletions
14
client/src/components/RecordingOptions/RecordingOptions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import RecordingOptions from './RecordingOptions'; | ||
|
||
describe('<RecordingOptions />', () => { | ||
test('it should mount', () => { | ||
render(<RecordingOptions />); | ||
|
||
const recordingOptions = screen.getByTestId('RecordingOptions'); | ||
|
||
expect(recordingOptions).toBeInTheDocument(); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
client/src/components/RecordingOptions/RecordingOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { FC, useContext } from 'react'; | ||
import { Button, Container } from '@mui/material'; | ||
import styles from './RecordingOptions.module.scss'; | ||
import { FiberManualRecord, Stop } from '@mui/icons-material'; | ||
import { HeadsetContext } from '../../contexts/HeadsetContext'; | ||
|
||
const RecordingOptions: FC<{}> = () => { | ||
const { headset, isRecording, startRecording, stopRecording } = | ||
useContext(HeadsetContext); | ||
return ( | ||
<Container | ||
className={styles.RecordingOptions} | ||
data-testid="RecordingOptions" | ||
> | ||
{!isRecording ? ( | ||
<Button | ||
disabled={!headset} | ||
variant="outlined" | ||
onClick={() => startRecording()} | ||
> | ||
<FiberManualRecord /> Record | ||
</Button> | ||
) : ( | ||
<Button variant="outlined" onClick={() => stopRecording()}> | ||
<Stop /> Stop | ||
</Button> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default RecordingOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
let isRecording = false; | ||
const headsetRecording: number[][][] = []; | ||
|
||
export interface HeadsetRecordingWorkerRequest { | ||
eventType: 'data' | 'start' | 'stop'; | ||
headsetData?: number[][]; | ||
} | ||
|
||
export interface HeadsetRecordingWorkerResponse { | ||
headsetRecording: number[][][]; | ||
} | ||
|
||
addEventListener( | ||
'message', | ||
(event: MessageEvent<HeadsetRecordingWorkerRequest>) => { | ||
const { eventType, headsetData } = event.data; | ||
|
||
switch (eventType) { | ||
case 'data': | ||
isRecording && headsetData && headsetRecording.push(headsetData); | ||
break; | ||
|
||
case 'start': | ||
isRecording = true; | ||
break; | ||
|
||
case 'stop': | ||
isRecording = false; | ||
postMessage({ headsetRecording }); | ||
break; | ||
} | ||
}, | ||
); |