Skip to content

Commit

Permalink
add disable/enable function
Browse files Browse the repository at this point in the history
  • Loading branch information
xdzqyyds committed Nov 21, 2024
1 parent a835815 commit c56ea65
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
19 changes: 17 additions & 2 deletions webapp/components/device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
deviceNone,
deviceScreen,
} from '../lib/device'
import { deviceSpeakerAtom } from './../store/atom'
import { deviceSpeakerAtom, SpeakerStatusAtom } from './../store/atom'

import Loading from './svg/loading'
import SvgSpeaker from './svg/speaker'
Expand All @@ -33,6 +33,7 @@ export default function DeviceBar(props: { streamId: string }) {
const [loadingScreen, setLoadingScreen] = useState(false)

const [currentDeviceSpeaker, setCurrentDeviceSpeaker] = useAtom(deviceSpeakerAtom)
const [SpeakerStatus, setSpeakerStatus] = useAtom(SpeakerStatusAtom)

const {
userStatus,
Expand Down Expand Up @@ -173,10 +174,24 @@ export default function DeviceBar(props: { streamId: string }) {
<center className="flex flex-row flex-wrap justify-around">
<section className="m-1 p-1 flex flex-row justify-center rounded-md border-1 border-indigo-500">
<button className="text-rose-400 rounded-md w-8 h-8" onClick={async () => {
setLoadingSpeaker(true)
setSpeakerStatus((prev) => !prev)
setLoadingSpeaker(false)
}}>
<center>{ loadingSpeaker ? <Loading/> : <SvgSpeaker/> }</center>
</button>
<div className="flex flex-col justify-between w-1 pointer-events-none"></div>
<div className="flex flex-col justify-between w-1 pointer-events-none">
<div></div>
{!SpeakerStatus
? <div></div>
: <div className="w-8 h-1 bg-red-500 rounded-full rotate-45"
style={{
position: 'relative',
right: '32px',
bottom: '14px',
}}></div>
}
</div>
<select
className="w-3.5 h-8 rounded-sm rotate-180"
value={currentDeviceSpeaker}
Expand Down
7 changes: 5 additions & 2 deletions webapp/components/player/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import WaveSurfer from 'wavesurfer.js'
import RecordPlugin from 'wavesurfer.js/dist/plugins/record'
import { isWechat } from '../../lib/util'
import SvgProgress from '../svg/progress'
import { deviceSpeakerAtom } from '../../store/atom'
import { deviceSpeakerAtom, SpeakerStatusAtom } from '../../store/atom'

function AudioWave(props: { stream: MediaStream }) {
const refWave = useRef<HTMLDivElement>(null)
Expand Down Expand Up @@ -37,6 +37,7 @@ export default function Player(props: { stream: MediaStream, muted: boolean, aud
const audioTrack = props.stream.getAudioTracks()[0]
const videoTrack = props.stream.getVideoTracks()[0]
const [currentDeviceSpeaker] = useAtom(deviceSpeakerAtom)
const [SpeakerStatus] = useAtom(SpeakerStatusAtom)


useEffect(() => {
Expand All @@ -52,6 +53,8 @@ export default function Player(props: { stream: MediaStream, muted: boolean, aud
if (el.setSinkId) {
el.setSinkId(currentDeviceSpeaker)
}

el.muted = SpeakerStatus
el.play()

return () => {
Expand All @@ -60,7 +63,7 @@ export default function Player(props: { stream: MediaStream, muted: boolean, aud
el.remove()
}
}
}, [audioTrack, videoTrack, currentDeviceSpeaker])
}, [audioTrack, videoTrack, currentDeviceSpeaker, SpeakerStatus])

useEffect(() => {
if (refVideo.current && videoTrack) {
Expand Down
1 change: 0 additions & 1 deletion webapp/components/use/whxp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Context extends EventTarget {
userStatus: Stream = {
name: '',
state: StreamState.New,
speaker: true,
audio: true,
video: true,
screen: false,
Expand Down
1 change: 0 additions & 1 deletion webapp/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ enum StreamState {
interface Stream {
name: string,
state: StreamState
speaker: boolean,
audio: boolean,
video: boolean,
screen: boolean,
Expand Down
5 changes: 3 additions & 2 deletions webapp/store/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface UserStatus {
*/
name: string
state: StreamState
speaker: boolean
audio: boolean
video: boolean
screen: boolean
Expand All @@ -36,7 +35,8 @@ presentationStreamAtom.debugLabel = 'presentationStream'
const enabledPresentationAtom = atom(get => get(presentationStreamAtom).stream.getVideoTracks().length !== 0)
enabledPresentationAtom.debugLabel = 'enabledPresentation'

const deviceSpeakerAtom = atom<string>('default')
const deviceSpeakerAtom = atom<string>('')
const SpeakerStatusAtom = atom<boolean>(false)

export {
locationAtom,
Expand All @@ -46,6 +46,7 @@ export {
meetingJoinedAtom,
enabledPresentationAtom,
deviceSpeakerAtom,
SpeakerStatusAtom,
}

export type {
Expand Down

0 comments on commit c56ea65

Please sign in to comment.