diff --git a/webapp/components/device.tsx b/webapp/components/device.tsx index 7659fee..8d80ffa 100644 --- a/webapp/components/device.tsx +++ b/webapp/components/device.tsx @@ -7,6 +7,7 @@ import { } from '../lib/device' import Loading from './svg/loading' +import SvgSpeaker from './svg/speaker' import SvgAudio from './svg/audio' import SvgVideo from './svg/video' import { SvgPresentCancel, SvgPresentToAll } from './svg/present' @@ -24,20 +25,25 @@ export default function DeviceBar(props: { streamId: string }) { const [permissionAudio, setPermissionAudio] = useState('') const [permissionVideo, setPermissionVideo] = useState('') + const [loadingSpeaker, setLoadingSpeaker] = useState(false) const [loadingAudio, setLoadingAudio] = useState(false) const [loadingVideo, setLoadingVideo] = useState(false) const [loadingScreen, setLoadingScreen] = useState(false) const { userStatus, + currentDeviceSpeaker, currentDeviceAudio, currentDeviceVideo, + setCurrentDeviceSpeaker, setCurrentDeviceAudio, setCurrentDeviceVideo, + toggleEnableSpeaker, toggleEnableAudio, toggleEnableVideo, } = useWhipClient(props.streamId) + const [deviceSpeaker, setDeviceSpeaker] = useState([deviceNone]) const [deviceAudio, setDeviceAudio] = useState([deviceNone]) const [deviceVideo, setDeviceVideo] = useState([deviceNone]) @@ -82,9 +88,15 @@ export default function DeviceBar(props: { streamId: string }) { const devices = (await navigator.mediaDevices.enumerateDevices()).filter(i => !!i.deviceId) + const speakers = devices.filter(i => i.kind === 'audiooutput').map(toDevice) const audios = devices.filter(i => i.kind === 'audioinput').map(toDevice) const videos = devices.filter(i => i.kind === 'videoinput').map(toDevice) + if ( currentDeviceSpeaker === deviceNone.deviceId) { + let device = speakers[0]; + if (device) await setCurrentDeviceSpeaker(device.deviceId); + } + if (currentDeviceAudio === deviceNone.deviceId) { const device = audios[0] if (device) await setCurrentDeviceAudio(device.deviceId) @@ -95,6 +107,7 @@ export default function DeviceBar(props: { streamId: string }) { if (device) await setCurrentDeviceVideo(device.deviceId) } + setDeviceSpeaker([...speakers]) setDeviceAudio([...audios]) setDeviceVideo([...videos, deviceScreen]) } @@ -130,6 +143,12 @@ export default function DeviceBar(props: { streamId: string }) { return () => { navigator.mediaDevices.removeEventListener('devicechange', updateDeviceList) } }, []) + const onChangedDeviceSpeaker = async (current: string) => { + setLoadingSpeaker(true) + await setCurrentDeviceSpeaker(current) + setLoadingSpeaker(false) + } + const onChangedDeviceAudio = async (current: string) => { setLoadingAudio(true) await setCurrentDeviceAudio(current) @@ -151,6 +170,24 @@ export default function DeviceBar(props: { streamId: string }) { return (
+
+ +
+
+ +
+