@@ -10,6 +10,7 @@ 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" ;
13
14
14
15
export type LocalPeerContext = {
15
16
video : UseCameraResult < TrackMetadata > ;
@@ -73,6 +74,10 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
73
74
const { simulcast } = useDeveloperInfo ( ) ;
74
75
const simulcastEnabled = simulcast . status ;
75
76
77
+ useEffect ( ( ) => {
78
+ console . log ( { simulcastEnabled } ) ;
79
+ } , [ ] ) ;
80
+
76
81
const blurRef = useRef < boolean > ( false ) ;
77
82
78
83
const [ stream , setStream ] = useState < MediaStream | null > ( null ) ;
@@ -129,20 +134,25 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
129
134
130
135
broadcastedStreamRef . current = mediaStream ;
131
136
137
+ const simulcastConfig : SimulcastConfig | undefined =
138
+ simulcastEnabled
139
+ ? { enabled : true , activeEncodings : [ "l" , "m" , "h" ] , disabledEncodings : [ ] }
140
+ : undefined ;
141
+
132
142
remoteTrackIdRef . current = await client . addTrack (
133
143
trackRef . current ,
134
144
mediaStream ,
135
- // todo think about track.enabled
136
145
{ active : metadataActive , type : "camera" } ,
137
- simulcastEnabled ? { enabled : true , activeEncodings : [ "l" , "m" , "h" ] , disabledEncodings : [ ] } : undefined ,
146
+ simulcastConfig ,
138
147
selectBandwidthLimit ( "camera" , simulcastEnabled )
139
148
) ;
140
149
} else if ( remoteTrackIdRef . current && trackRef . current ) {
141
- // todo add setter as an alternative to setting whole object
142
150
broadcastedStreamRef . current ?. removeTrack ( broadcastedStreamRef . current ?. getVideoTracks ( ) [ 0 ] ) ;
143
151
broadcastedStreamRef . current ?. addTrack ( trackRef . current ) ;
144
152
145
- // todo when you replaceTrack this not affects stream so local peer don't know that something changes
153
+ // todo
154
+ // When you replaceTrack, this does not affect the stream, so the local peer doesn't know that something has changed.
155
+ // add localTrackReplaced event
146
156
const newMetadata : TrackMetadata = { active : metadataActive , type : "camera" } ;
147
157
148
158
await client . replaceTrack ( remoteTrackIdRef . current , trackRef . current , newMetadata ) ;
@@ -151,7 +161,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
151
161
remoteTrackIdRef . current = null ;
152
162
}
153
163
}
154
- } , [ setStream , setTrack ] ) ;
164
+ } , [ setStream , setTrack , simulcastEnabled ] ) ;
155
165
156
166
useEffect ( ( ) => {
157
167
const managerInitialized : ClientEvents < PeerMetadata , TrackMetadata > [ "managerInitialized" ] = ( event ) => {
@@ -163,35 +173,13 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
163
173
trackRef . current = event . video ?. media ?. track || null ;
164
174
streamRef . current = event . video ?. media ?. stream || null ;
165
175
166
- const snapshot = client ;
167
-
168
- const cameraId = snapshot ?. media ?. video ?. media ?. deviceInfo ?. deviceId || null ;
176
+ const cameraId = client ?. media ?. video ?. media ?. deviceInfo ?. deviceId || null ;
169
177
170
178
if ( cameraId ) {
171
179
lastCameraIdRef . current = cameraId ;
172
180
}
173
181
} ;
174
182
175
-
176
- /*
177
- * Przypadki:
178
- * 1) uruchamiam kamerę i następnie wchodze do pokoju
179
- * - intencja: true, ma być włączona
180
- * - leci event
181
- * - disconnect (czyli wyłączam)
182
- * - i następnie joined (czyli uruchamiam bo intencja true)
183
- * - sprawdzam intencje i wiem, że muszę uruchomić ponownie
184
- * 2) Wychodzę z pokoju i wracam
185
- * - leci event disconnect -> czyli wyłączam
186
- * - intencja jest true
187
- * - wracam do pokoju czyli leci
188
- * - connect (uruchamiam bo intencja jest true)
189
- * - disconnect (wyłączam)
190
- * - connect uruchamiam (bo inencja jest true)
191
- *
192
- * Czy z tego powodu wynika, że za każdym razem jak uruchamiam urządzenie, to sprawdzam czy jestem joined
193
- * i jak tak to dodaję
194
- */
195
183
const joinedHandler : ClientEvents < PeerMetadata , TrackMetadata > [ "joined" ] = async ( ) => {
196
184
const stream = client . devices . camera . stream ;
197
185
const track = client . devices . camera . track ;
0 commit comments