11import { useMonitoring } from '@monkvision/monitoring' ;
22import deepEqual from 'fast-deep-equal' ;
33import { RefObject , useCallback , useEffect , useRef , useState } from 'react' ;
4- import { PixelDimensions } from '@monkvision/types' ;
5- import { isMobileDevice , useIsMounted , useObjectMemo } from '@monkvision/common' ;
4+ import { useIsMounted , useObjectMemo } from '@monkvision/common' ;
65import { analyzeCameraDevices } from './utils' ;
76
87/**
@@ -17,10 +16,6 @@ export enum InvalidStreamErrorName {
1716 * The stream had too many video tracks (more than one).
1817 */
1918 TOO_MANY_VIDEO_TRACKS = 'TooManyVideoTracks' ,
20- /**
21- * The stream's video track had no dimensions.
22- */
23- NO_DIMENSIONS = 'NoDimensions' ,
2419}
2520
2621class InvalidStreamError extends Error {
@@ -105,11 +100,6 @@ export interface UserMediaResult {
105100 * The resulting video stream. The stream can be null when not initialized or in case of an error.
106101 */
107102 stream : MediaStream | null ;
108- /**
109- * The dimensions of the resulting camera stream. Note that these dimensions can differ from the ones given in the
110- * stream constraints if they are not supported or available on the current device.
111- */
112- dimensions : PixelDimensions | null ;
113103 /**
114104 * The error details. If no error has occurred, this object will be null.
115105 */
@@ -156,31 +146,6 @@ function getStreamDeviceId(stream: MediaStream): string | null {
156146 return settings . deviceId ?? null ;
157147}
158148
159- function swapDimensions ( dimensions : PixelDimensions ) : PixelDimensions {
160- return {
161- width : dimensions . height ,
162- height : dimensions . width ,
163- } ;
164- }
165-
166- function getStreamDimensions ( stream : MediaStream , checkOrientation : boolean ) : PixelDimensions {
167- const { width, height } = getStreamVideoTrackSettings ( stream ) ;
168- if ( ! width || ! height ) {
169- throw new InvalidStreamError (
170- 'Unable to set up the Monk camera screenshoter because the video stream does not have the properties width and height defined.' ,
171- InvalidStreamErrorName . NO_DIMENSIONS ,
172- ) ;
173- }
174- const dimensions = { width, height } ;
175- if ( ! isMobileDevice ( ) || ! checkOrientation ) {
176- return dimensions ;
177- }
178-
179- const isStreamInPortrait = width < height ;
180- const isDeviceInPortrait = window . matchMedia ( '(orientation: portrait)' ) . matches ;
181- return isStreamInPortrait !== isDeviceInPortrait ? swapDimensions ( dimensions ) : dimensions ;
182- }
183-
184149/**
185150 * React hook that wraps the `navigator.mediaDevices.getUserMedia` browser function in order to add React logic layers
186151 * and utility tools :
@@ -205,7 +170,6 @@ export function useUserMedia(
205170) : UserMediaResult {
206171 const streamRef = useRef < MediaStream | null > ( null ) ;
207172 const [ stream , setStream ] = useState < MediaStream | null > ( null ) ;
208- const [ dimensions , setDimensions ] = useState < PixelDimensions | null > ( null ) ;
209173 const [ isLoading , setIsLoading ] = useState ( false ) ;
210174 const [ error , setError ] = useState < UserMediaError | null > ( null ) ;
211175 const [ availableCameraDevices , setAvailableCameraDevices ] = useState < MediaDeviceInfo [ ] > ( [ ] ) ;
@@ -278,10 +242,9 @@ export function useUserMedia(
278242 if ( isMounted ( ) ) {
279243 setStream ( str ) ;
280244 streamRef . current = str ;
281- setDimensions ( getStreamDimensions ( str , true ) ) ;
282- setIsLoading ( false ) ;
283- setAvailableCameraDevices ( deviceDetails . availableDevices ) ;
284245 setSelectedCameraDeviceId ( getStreamDeviceId ( str ) ) ;
246+ setAvailableCameraDevices ( deviceDetails . availableDevices ) ;
247+ setIsLoading ( false ) ;
285248 }
286249 return str ;
287250 } , [ stream , constraints ] ) ;
@@ -323,17 +286,6 @@ export function useUserMedia(
323286 }
324287 } , [ constraints , stream , error , isLoading , lastConstraintsApplied , getUserMedia , videoRef ] ) ;
325288
326- useEffect ( ( ) => {
327- if ( stream && videoRef && videoRef . current ) {
328- // eslint-disable-next-line no-param-reassign
329- videoRef . current . onresize = ( ) => {
330- if ( isMounted ( ) ) {
331- setDimensions ( getStreamDimensions ( stream , false ) ) ;
332- }
333- } ;
334- }
335- } , [ stream , videoRef ] ) ;
336-
337289 useEffect ( ( ) => {
338290 return ( ) => {
339291 streamRef . current ?. getTracks ( ) . forEach ( ( track ) => {
@@ -345,7 +297,6 @@ export function useUserMedia(
345297 return useObjectMemo ( {
346298 getUserMedia,
347299 stream,
348- dimensions,
349300 error,
350301 retry,
351302 isLoading,
0 commit comments