Skip to content

Commit

Permalink
fix: update the default values
Browse files Browse the repository at this point in the history
  • Loading branch information
malkiii committed Nov 4, 2023
1 parent e08c6e4 commit f2da846
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package/src/useMediaDevices/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type MediaDevicesOptions = MediaStreamConstraints & {
};

export const useMediaDevices = (options: MediaDevicesOptions = {}) => {
const { ref, startOnMount = true, ...globalConstraints } = options;
const { ref, startOnMount = false, ...globalConstraints } = options;

const videoRef = useNewRef<HTMLVideoElement>(options.ref);
const streamRef = useRef<MediaStream>(new MediaStream());
Expand Down
7 changes: 4 additions & 3 deletions package/src/useMediaRecorder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const useMediaRecorder = (options: MediaRecorderOptions = {}) => {
const controls = useMemo(
() => ({
start(stream: MediaStream, timeslice?: number) {
if (recorderRef.current?.state !== 'inactive') return;
const state = recorderRef.current?.state ?? 'inactive';
if (state !== 'inactive') return;

recorderRef.current = new MediaRecorder(stream, options);
recorderRef.current.ondataavailable = event => {
Expand All @@ -37,7 +38,8 @@ export const useMediaRecorder = (options: MediaRecorderOptions = {}) => {
}
},
async stop(options: RecorderDownloadOptions = {}) {
if (recorderRef.current?.state == 'inactive') return;
const state = recorderRef.current?.state ?? 'inactive';
if (state === 'inactive') return;
recorderRef.current?.resume();
recorderRef.current?.stop();

Expand All @@ -51,7 +53,6 @@ export const useMediaRecorder = (options: MediaRecorderOptions = {}) => {
return blob;
},
togglePlayState(play?: boolean) {
if (recorderRef.current?.state == 'inactive') return;
const shouldPlay = play ?? recorderRef.current?.state == 'paused';
shouldPlay ? this.resume() : this.pause();
},
Expand Down

0 comments on commit f2da846

Please sign in to comment.