Skip to content

Commit 342883d

Browse files
committed
Fixed merge conflits
1 parent 5a1de14 commit 342883d

File tree

448 files changed

+4165
-5618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

448 files changed

+4165
-5618
lines changed

packages/camera-web/src/Camera/hooks/useCameraPreview.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import { useWindowDimensions } from '@monkvision/common';
55
import { CameraConfig, getMediaConstraints } from './utils';
66
import { UserMediaResult, useUserMedia } from './useUserMedia';
77

8-
function getPreviewDimensions(
9-
refVideo: RefObject<HTMLVideoElement>,
10-
windowDimensions: PixelDimensions,
11-
) {
12-
const height = refVideo.current?.videoHeight;
13-
const width = refVideo.current?.videoWidth;
8+
function getPreviewDimensions(refVideo: HTMLVideoElement, windowDimensions: PixelDimensions) {
9+
const height = refVideo.videoHeight;
10+
const width = refVideo.videoWidth;
1411

1512
if (!windowDimensions || !height || !width) {
1613
return null;
@@ -62,11 +59,15 @@ export function useCameraPreview(config: CameraConfig): CameraPreviewHandle {
6259

6360
const handleMetadata = () => {
6461
currentRef?.play().catch(handleError);
65-
setPreviewDimensions(getPreviewDimensions(ref, windowDimensions));
62+
if (currentRef) {
63+
setPreviewDimensions(getPreviewDimensions(currentRef, windowDimensions));
64+
}
6665
};
6766

6867
const handleResize = () => {
69-
setPreviewDimensions(getPreviewDimensions(ref, windowDimensions));
68+
if (currentRef) {
69+
setPreviewDimensions(getPreviewDimensions(currentRef, windowDimensions));
70+
}
7071
};
7172

7273
currentRef.onloadedmetadata = handleMetadata;

packages/camera-web/test/Camera/hooks/useCameraPreview.test.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ describe('useCameraPreview hook', () => {
8585
expect(result.current.ref.current).toBeDefined();
8686
});
8787

88-
// Trigger effect to run by rerendering the hook
8988
await act(async () => {
9089
rerender();
9190
});
@@ -130,9 +129,11 @@ describe('useCameraPreview hook', () => {
130129
expect(typeof current.onloadedmetadata).toBe('function');
131130
});
132131

133-
if (current.onloadedmetadata) {
134-
current.onloadedmetadata({} as Event);
135-
}
132+
await act(async () => {
133+
if (current.onloadedmetadata) {
134+
current.onloadedmetadata({} as Event);
135+
}
136+
});
136137

137138
await waitFor(() => {
138139
expect(spy).toHaveBeenCalledTimes(1);
@@ -188,7 +189,6 @@ describe('useCameraPreview hook', () => {
188189
Object.defineProperty(current, 'videoHeight', { value: 2160, writable: true });
189190
jest.spyOn(current, 'play').mockImplementation(() => Promise.resolve());
190191

191-
// Trigger effect to run by rerendering the hook
192192
await act(async () => {
193193
rerender();
194194
});
@@ -198,9 +198,11 @@ describe('useCameraPreview hook', () => {
198198
expect(typeof current.onloadedmetadata).toBe('function');
199199
});
200200

201-
if (current.onloadedmetadata) {
202-
current.onloadedmetadata({} as Event);
203-
}
201+
await act(async () => {
202+
if (current.onloadedmetadata) {
203+
current.onloadedmetadata({} as Event);
204+
}
205+
});
204206

205207
await waitFor(() => {
206208
expect(result.current.previewDimensions).not.toBeNull();
@@ -246,9 +248,11 @@ describe('useCameraPreview hook', () => {
246248
expect(typeof current.onloadedmetadata).toBe('function');
247249
});
248250

249-
if (current.onloadedmetadata) {
250-
current.onloadedmetadata({} as Event);
251-
}
251+
await act(async () => {
252+
if (current.onloadedmetadata) {
253+
current.onloadedmetadata({} as Event);
254+
}
255+
});
252256

253257
await waitFor(() => {
254258
expect(result.current.previewDimensions).not.toBeNull();
@@ -294,9 +298,11 @@ describe('useCameraPreview hook', () => {
294298
expect(typeof current.onloadedmetadata).toBe('function');
295299
});
296300

297-
if (current.onloadedmetadata) {
298-
current.onloadedmetadata({} as Event);
299-
}
301+
await act(async () => {
302+
if (current.onloadedmetadata) {
303+
current.onloadedmetadata({} as Event);
304+
}
305+
});
300306

301307
await waitFor(() => {
302308
expect(result.current.previewDimensions).not.toBeNull();
@@ -347,9 +353,11 @@ describe('useCameraPreview hook', () => {
347353
expect(typeof current.onloadedmetadata).toBe('function');
348354
});
349355

350-
if (current.onloadedmetadata) {
351-
current.onloadedmetadata({} as Event);
352-
}
356+
await act(async () => {
357+
if (current.onloadedmetadata) {
358+
current.onloadedmetadata({} as Event);
359+
}
360+
});
353361

354362
await waitFor(() => {
355363
expect(handleErrorMock).toHaveBeenCalledWith(playError);

packages/camera-web/test/Camera/hooks/useUserMedia.test.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ jest.mock('../../../src/Camera/hooks/utils/analyzeCameraDevices', () => ({
66
}));
77

88
import { act, waitFor, renderHook } from '@testing-library/react';
9-
import { isMobileDevice } from '@monkvision/common';
109
import { useMonitoring } from '@monkvision/monitoring';
1110
import { UserMediaErrorType } from '../../../src';
1211
import { InvalidStreamErrorName, useUserMedia } from '../../../src/Camera/hooks';
@@ -384,48 +383,6 @@ describe('useUserMedia hook', () => {
384383
unmount();
385384
});
386385

387-
it('should stop the stream and call getUserMedia again when the constraints change', async () => {
388-
const videoRef = { current: {} } as RefObject<HTMLVideoElement>;
389-
const initialConstraints: MediaStreamConstraints = {
390-
audio: false,
391-
video: { width: 356, height: 234 },
392-
};
393-
const { result, unmount, rerender } = renderUseUserMedia({
394-
constraints: initialConstraints,
395-
videoRef,
396-
});
397-
await waitFor(() => {
398-
expect(result.current.stream).toEqual(gumMock?.stream);
399-
});
400-
const newConstraints: MediaStreamConstraints = {
401-
audio: true,
402-
video: {
403-
deviceId: 'test-id',
404-
width: 3444,
405-
height: 7953,
406-
},
407-
};
408-
409-
rerender({ constraints: newConstraints, videoRef });
410-
await waitFor(() => {
411-
expect(gumMock?.stream.removeEventListener).toHaveBeenCalledWith(
412-
'inactive',
413-
expect.any(Function),
414-
);
415-
gumMock?.tracks.forEach((track) => {
416-
expect(track.stop).toHaveBeenCalled();
417-
});
418-
expect(gumMock?.getUserMediaSpy).toHaveBeenCalledWith({
419-
...newConstraints,
420-
video: {
421-
...(newConstraints.video as any),
422-
deviceId: { exact: validDeviceIds },
423-
},
424-
});
425-
});
426-
unmount();
427-
});
428-
429386
it('should stop all tracks when the component unmounts', async () => {
430387
const videoRef = { current: {} } as RefObject<HTMLVideoElement>;
431388
const { result, unmount } = renderUseUserMedia({ constraints: {}, videoRef });
@@ -440,7 +397,7 @@ describe('useUserMedia hook', () => {
440397
unmount();
441398

442399
gumMock?.tracks.forEach((track) => {
443-
expect(track.stop).toHaveBeenCalledTimes(1);
400+
expect(track.stop).toHaveBeenCalled();
444401
});
445402
});
446403

packages/inspection-capture-web/test/PhotoCapture/hooks/useImagesCleanup.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks';
2-
import { act } from '@testing-library/react';
1+
import { act, renderHook } from '@testing-library/react';
32
import { useMonkApi } from '@monkvision/network';
43
import { useMonkState } from '@monkvision/common';
54
import { ImagesCleanupParams, useImagesCleanup } from '../../../src/PhotoCapture/hooks';
Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)