This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1462 from ecency/feature/video-upload-camera-swit…
…ching Video recorder: Added camera switcher
- Loading branch information
Showing
7 changed files
with
147 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./use-get-camera-list"; |
18 changes: 18 additions & 0 deletions
18
src/common/components/video-upload-threespeak/utils/use-get-camera-list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState } from "react"; | ||
import useMount from "react-use/lib/useMount"; | ||
|
||
/** | ||
* Retrieves a list of available cameras. | ||
* | ||
* @return {MediaDeviceInfo[]} The list of available cameras. | ||
*/ | ||
export function useGetCameraList() { | ||
const [list, setList] = useState<MediaDeviceInfo[]>([]); | ||
|
||
useMount(async () => { | ||
const devices = await navigator.mediaDevices.enumerateDevices(); | ||
setList(devices.filter(({ kind }) => kind === "videoinput")); | ||
}); | ||
|
||
return list; | ||
} |
77 changes: 52 additions & 25 deletions
77
src/common/components/video-upload-threespeak/video-upload-recorder-actions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,66 @@ | ||
import { circleSvg, rectSvg } from "../../img/svg"; | ||
import { circleSvg, rectSvg, switchCameraSvg } from "../../img/svg"; | ||
import React, { useState } from "react"; | ||
import { useGetCameraList } from "./utils"; | ||
|
||
interface Props { | ||
noPermission: boolean; | ||
mediaRecorder?: MediaRecorder; | ||
onCameraSelect: (camera: MediaDeviceInfo) => void; | ||
} | ||
|
||
export function VideoUploadRecorderActions({ noPermission, mediaRecorder }: Props) { | ||
export function VideoUploadRecorderActions({ noPermission, mediaRecorder, onCameraSelect }: Props) { | ||
const cameraList = useGetCameraList(); | ||
|
||
const [currentCameraIndex, setCurrentCameraIndex] = useState(0); | ||
const [recordStarted, setRecordStarted] = useState(false); | ||
|
||
const getNextCameraIndex = (index: number) => (index + 1) % cameraList.length; | ||
|
||
return ( | ||
<div className="actions"> | ||
{recordStarted ? ( | ||
<div | ||
aria-disabled={noPermission} | ||
className="record-btn" | ||
onClick={() => { | ||
mediaRecorder?.stop(); | ||
setRecordStarted(false); | ||
}} | ||
> | ||
{rectSvg} | ||
</div> | ||
) : ( | ||
<div | ||
aria-disabled={noPermission} | ||
className="record-btn" | ||
onClick={() => { | ||
mediaRecorder?.start(); | ||
setRecordStarted(true); | ||
}} | ||
> | ||
{circleSvg} | ||
</div> | ||
)} | ||
<div> | ||
{!recordStarted && cameraList.length > 1 ? ( | ||
<div | ||
className="switch-camera" | ||
onClick={() => { | ||
const nextCameraIndex = getNextCameraIndex(currentCameraIndex); | ||
onCameraSelect(cameraList[nextCameraIndex]); | ||
setCurrentCameraIndex(nextCameraIndex); | ||
}} | ||
> | ||
{switchCameraSvg} | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
|
||
<div> | ||
{recordStarted ? ( | ||
<div | ||
aria-disabled={noPermission} | ||
className="record-btn" | ||
onClick={() => { | ||
mediaRecorder?.stop(); | ||
setRecordStarted(false); | ||
}} | ||
> | ||
{rectSvg} | ||
</div> | ||
) : ( | ||
<div | ||
aria-disabled={noPermission} | ||
className="record-btn" | ||
onClick={() => { | ||
mediaRecorder?.start(); | ||
setRecordStarted(true); | ||
}} | ||
> | ||
{circleSvg} | ||
</div> | ||
)} | ||
</div> | ||
<div /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters