-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
14 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,64 @@ | ||
import { Phone } from 'lucide-react' | ||
import { useEffect, useRef } from 'react' | ||
|
||
export const MediaCaller = ({ onCancel }: { onCancel: () => void }) => { | ||
const localVideoRef = useRef<HTMLVideoElement>(null) | ||
|
||
useEffect(() => { | ||
startStream() | ||
|
||
return () => { | ||
stopStream() | ||
} | ||
}, []) | ||
|
||
const startStream = async () => { | ||
try { | ||
const stream = await navigator.mediaDevices.getUserMedia({ | ||
video: true, | ||
audio: true, | ||
}) | ||
if (localVideoRef.current) { | ||
localVideoRef.current.srcObject = stream | ||
} | ||
} catch (error) { | ||
// TODO: handle stream error | ||
} | ||
} | ||
|
||
const handleCancelStream = () => { | ||
stopStream() | ||
onCancel() | ||
} | ||
|
||
const stopStream = () => { | ||
if (localVideoRef.current?.srcObject) { | ||
const stream = localVideoRef.current.srcObject as MediaStream | ||
stream.getTracks().forEach(track => track.stop()) | ||
localVideoRef.current.srcObject = null | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className='mb-5 flex justify-center'> | ||
<video ref={localVideoRef} autoPlay playsInline controls={false} /> | ||
</div> | ||
<div className='mt-3 inline-flex w-full items-center justify-around'> | ||
{/* <button type='button' aria-label='toggle video visibility'> | ||
{isVideoShared ? <Video /> : <VideoOff />} | ||
</button> | ||
<button type='button' aria-label='toggle audio visibility'> | ||
{isMuted ? <Mic /> : <MicOff />} | ||
</button> */} | ||
<button | ||
type='button' | ||
aria-label='cancel call' | ||
onClick={handleCancelStream} | ||
> | ||
<Phone /> | ||
</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { MediaCaller } from './MediaCaller' |
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,2 @@ | ||
export type DeviceArrayMap = Record<MediaDeviceKind, MediaDeviceInfo[]> | ||
export type DeviceMap = Record<MediaDeviceKind, string> |
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