Skip to content

Commit

Permalink
Fix camera light bug (#350)
Browse files Browse the repository at this point in the history
* Fix bug where camera light stays on

* Cleanup tests
  • Loading branch information
timmydoza authored Oct 30, 2020
1 parent 679c5b8 commit cf36ac3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,42 @@ describe('the useLocalTracks hook', () => {
});
});

it('should set isAcquiringLocalTracks to true while acquiring tracks', async () => {
const { result, waitForNextUpdate } = renderHook(useLocalTracks);

expect(result.current.isAcquiringLocalTracks).toBe(false);

act(() => {
result.current.getAudioAndVideoTracks();
});

expect(result.current.isAcquiringLocalTracks).toBe(true);

await act(async () => {
await waitForNextUpdate();
});

expect(result.current.isAcquiringLocalTracks).toBe(false);
});

it('should ignore calls to getAudioAndVideoTracks while isAcquiringLocalTracks is true', async () => {
const { result, waitForNextUpdate } = renderHook(useLocalTracks);

act(() => {
expect(result.current.isAcquiringLocalTracks).toBe(false);
result.current.getAudioAndVideoTracks(); // This call is not ignored
});

expect(result.current.isAcquiringLocalTracks).toBe(true);
result.current.getAudioAndVideoTracks(); // This call is ignored

await act(async () => {
await waitForNextUpdate();
});

expect(Video.createLocalTracks).toHaveBeenCalledTimes(1);
});

it('should not create any tracks when no input devices are present', async () => {
mockUseAudioInputDevices.mockImplementation(() => []);
mockUseVideoInputDevices.mockImplementation(() => []);
Expand Down
4 changes: 2 additions & 2 deletions src/components/VideoProvider/useLocalTracks/useLocalTracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function useLocalTracks() {

const getAudioAndVideoTracks = useCallback(() => {
if (!hasAudio && !hasVideo) return Promise.resolve();
if (audioTrack || videoTrack) return Promise.resolve();
if (isAcquiringLocalTracks || audioTrack || videoTrack) return Promise.resolve();

setIsAcquiringLocalTracks(true);

Expand Down Expand Up @@ -84,7 +84,7 @@ export default function useLocalTracks() {
}
})
.finally(() => setIsAcquiringLocalTracks(false));
}, [hasAudio, hasVideo, audioTrack, videoTrack, localAudioDevices, localVideoDevices]);
}, [hasAudio, hasVideo, audioTrack, videoTrack, localAudioDevices, localVideoDevices, isAcquiringLocalTracks]);

const localTracks = [audioTrack, videoTrack].filter(track => track !== undefined) as (
| LocalAudioTrack
Expand Down

0 comments on commit cf36ac3

Please sign in to comment.