@@ -5,12 +5,11 @@ import {
5
5
VIDEO_TRACK_CONSTRAINTS
6
6
} from "../../pages/room/consts" ;
7
7
import { PeerMetadata , TrackMetadata , useCamera , useClient , useMicrophone , useSetupMedia } from "../../jellyfish.types" ;
8
- import { ClientEvents , UseCameraResult } from "@jellyfish-dev/react-client-sdk" ;
8
+ import { ClientEvents , UseCameraResult , SimulcastConfig } from "@jellyfish-dev/react-client-sdk" ;
9
9
import { BlurProcessor } from "./BlurProcessor" ;
10
10
import { selectBandwidthLimit } from "../../pages/room/bandwidth.tsx" ;
11
11
import { useDeveloperInfo } from "../../contexts/DeveloperInfoContext.tsx" ;
12
12
import EmptyVideoWorker from "./emptyVideoWorker.ts?worker" ;
13
- import { SimulcastConfig } from "@jellyfish-dev/ts-client-sdk" ;
14
13
15
14
export type LocalPeerContext = {
16
15
video : UseCameraResult < TrackMetadata > ;
@@ -74,10 +73,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
74
73
const { simulcast } = useDeveloperInfo ( ) ;
75
74
const simulcastEnabled = simulcast . status ;
76
75
77
- useEffect ( ( ) => {
78
- console . log ( { simulcastEnabled } ) ;
79
- } , [ ] ) ;
80
-
81
76
const blurRef = useRef < boolean > ( false ) ;
82
77
83
78
const [ stream , setStream ] = useState < MediaStream | null > ( null ) ;
@@ -128,9 +123,13 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
128
123
}
129
124
130
125
if ( client . status === "joined" ) {
131
- if ( ! remoteTrackIdRef . current && streamRef . current && trackRef . current ) {
126
+ const lastCameraTrack = Object . values ( client ?. local ?. tracks || { } )
127
+ . some ( ( track ) => track ?. metadata ?. type === "camera" ) ;
128
+
129
+ const newTrack = trackRef . current ;
130
+ if ( ! lastCameraTrack && streamRef . current && newTrack ) {
132
131
const mediaStream = new MediaStream ( ) ;
133
- mediaStream . addTrack ( trackRef . current ) ;
132
+ mediaStream . addTrack ( newTrack ) ;
134
133
135
134
broadcastedStreamRef . current = mediaStream ;
136
135
@@ -140,7 +139,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
140
139
: undefined ;
141
140
142
141
remoteTrackIdRef . current = await client . addTrack (
143
- trackRef . current ,
142
+ newTrack ,
144
143
mediaStream ,
145
144
{ active : metadataActive , type : "camera" } ,
146
145
simulcastConfig ,
@@ -331,7 +330,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
331
330
const microphone = useMicrophone ( ) ;
332
331
333
332
const setDevice = useCallback ( async ( cameraId : string | null , microphoneId : string | null , blur : boolean ) => {
334
- if ( microphoneId ) {
333
+ if ( microphoneId && microphoneIntentionRef . current ) {
335
334
microphone . start ( microphoneId ) ;
336
335
}
337
336
@@ -347,7 +346,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
347
346
}
348
347
}
349
348
350
- if ( cameraId ) {
349
+ if ( cameraId && cameraIntentionRef . current ) {
351
350
video . start ( cameraId ) ;
352
351
}
353
352
} , [ video ] ) ;
0 commit comments