From b86268c1912633e46d59747e627f9503d55ef198 Mon Sep 17 00:00:00 2001 From: Michael Mironychev Date: Wed, 21 Feb 2024 02:09:21 +0700 Subject: [PATCH] release/1.0.1 :hot_pepper: README upd & SSR fix --- README.md | 4 ++-- src/utils/helpers/stream/getUserMedia.ts | 9 +++++---- src/utils/helpers/stream/stopMediaStream.ts | 4 +++- src/utils/hooks/useMediaStream.ts | 1 - 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 58b0a4b..e05a984 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ The component also supports many properties for more specific work: | mainCamera | boolean | false | should use a main camera (requires Navigator.mediaDevices.enumerateDevices) | | frontCamera | boolean | false | should use a front camera (MediaTrackConstraints['facingFront'] === 'user') | | applyConstraints | boolean | false | should new constraints be applied to the media stream | -| cameraResolutionType | string | | video track resolution size - 'UHD' | 'QHD' | 'FHD' | 'HD' | -| cameraResolutionMode | string | 'ideal' | video track resolution mode - 'min' | 'max' | 'ideal' | 'exact' | +| cameraResolutionType | string | | video track resolution size - `('UHD' \| 'QHD' \| 'FHD' \| 'HD')` | +| cameraResolutionMode | string | 'ideal' | video track resolution mode - `('min' \| 'max' \| 'ideal' \| 'exact')` | | audioConstraints | object | | audio track constraints - MediaStreamConstraints['audio'] | | videoConstraints | object | | video track constraints - MediaStreamConstraints['video'] | | requestTimeLimit | number | | limiting the media stream request by time | diff --git a/src/utils/helpers/stream/getUserMedia.ts b/src/utils/helpers/stream/getUserMedia.ts index 4b4ff6b..52a0fb3 100644 --- a/src/utils/helpers/stream/getUserMedia.ts +++ b/src/utils/helpers/stream/getUserMedia.ts @@ -3,10 +3,11 @@ import { hasGetUserMedia } from './hasGetUserMedia'; // ✅ important // Implementations for each browser need to be supported export const getUserMediaFunction = - navigator.getUserMedia || - navigator.webkitGetUserMedia || - navigator.mozGetUserMedia || - navigator.msGetUserMedia; + typeof window !== 'undefined' && + (navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia); // ✅ important // Polyfill to support legacy web-api diff --git a/src/utils/helpers/stream/stopMediaStream.ts b/src/utils/helpers/stream/stopMediaStream.ts index db027b6..6ee4ca9 100644 --- a/src/utils/helpers/stream/stopMediaStream.ts +++ b/src/utils/helpers/stream/stopMediaStream.ts @@ -1,4 +1,6 @@ -export const stopMediaStream = (stream: MediaStreamTrack | MediaStream) => { +export const stopMediaStream = (stream?: MediaStreamTrack | MediaStream) => { + if (!stream) return; + if (stream instanceof MediaStreamTrack) { stream.stop(); return; diff --git a/src/utils/hooks/useMediaStream.ts b/src/utils/hooks/useMediaStream.ts index 3c5647a..19975f1 100644 --- a/src/utils/hooks/useMediaStream.ts +++ b/src/utils/hooks/useMediaStream.ts @@ -95,7 +95,6 @@ export const useMediaStream = ({ return () => { handlerRef.current.stop?.(runningStream); - if (!runningStream) return; stopMediaStream(runningStream); }; }, [