diff --git a/app/components/AudioStream.tsx b/app/components/AudioStream.tsx index 9598319..deddeb9 100644 --- a/app/components/AudioStream.tsx +++ b/app/components/AudioStream.tsx @@ -1,20 +1,104 @@ import type { FC } from 'react' -import { useEffect, useRef } from 'react' +import { useEffect, useMemo, useRef } from 'react' +import { of } from 'rxjs' +import { useSubscribedState } from '~/hooks/rxjsHooks' +import { useRoomContext } from '~/hooks/useRoomContext' interface AudioStreamProps { - mediaStreamTrack: MediaStreamTrack + tracksToPull: string[] + onTrackAdded: (id: string, track: MediaStreamTrack) => void + onTrackRemoved: (id: string, track: MediaStreamTrack) => void } -export const AudioStream: FC = ({ mediaStreamTrack }) => { +export const AudioStream: FC = ({ + tracksToPull, + onTrackAdded, + onTrackRemoved, +}) => { + const mediaStreamRef = useRef(new MediaStream()) const ref = useRef(null) useEffect(() => { const audio = ref.current if (!audio) return - const mediaStream = new MediaStream() - mediaStream.addTrack(mediaStreamTrack) + const mediaStream = mediaStreamRef.current audio.srcObject = mediaStream - }, [mediaStreamTrack]) + }, []) - return