@@ -257,6 +257,22 @@ private async void Agent_OnIncomingCall(object sender, IncomingCall incomingcall
257
257
All remote participants are available through the ` RemoteParticipants ` collection on a call instance. Once the call is connected we can access the remote participants of the call and handle the remote video streams.
258
258
259
259
``` C#
260
+ private async void Call_OnVideoStreamsUpdated (object sender , RemoteVideoStreamsEventArgs args )
261
+ {
262
+ foreach (var remoteVideoStream in args .AddedRemoteVideoStreams )
263
+ {
264
+ await Dispatcher .RunAsync (Windows .UI .Core .CoreDispatcherPriority .Normal , async () =>
265
+ {
266
+ RemoteVideo .Source = await remoteVideoStream .Start ();
267
+ });
268
+ }
269
+
270
+ foreach (var remoteVideoStream in args .RemovedRemoteVideoStreams )
271
+ {
272
+ remoteVideoStream .Stop ();
273
+ }
274
+ }
275
+
260
276
private async void Agent_OnCallsUpdated (object sender , CallsUpdatedEventArgs args )
261
277
{
262
278
foreach (var call in args .AddedCalls )
@@ -266,7 +282,7 @@ private async void Agent_OnCallsUpdated(object sender, CallsUpdatedEventArgs arg
266
282
String remoteParticipantMRI = remoteParticipant .Identifier .ToString ();
267
283
remoteParticipantDictionary .TryAdd (remoteParticipantMRI , remoteParticipant );
268
284
await AddVideoStreams (remoteParticipant .VideoStreams );
269
- remoteParticipant .OnVideoStreamsUpdated += async ( s , a ) => await AddVideoStreams ( a . AddedRemoteVideoStreams ) ;
285
+ remoteParticipant .OnVideoStreamsUpdated += Call_OnVideoStreamsUpdated ;
270
286
}
271
287
}
272
288
}
@@ -278,7 +294,13 @@ private async void Call_OnRemoteParticipantsUpdated(object sender, ParticipantsU
278
294
String remoteParticipantMRI = remoteParticipant .Identifier .ToString ();
279
295
remoteParticipantDictionary .TryAdd (remoteParticipantMRI , remoteParticipant );
280
296
await AddVideoStreams (remoteParticipant .VideoStreams );
281
- remoteParticipant .OnVideoStreamsUpdated += async (s , a ) => await AddVideoStreams (a .AddedRemoteVideoStreams );
297
+ remoteParticipant .OnVideoStreamsUpdated += Call_OnVideoStreamsUpdated ;
298
+ }
299
+
300
+ foreach (var remoteParticipant in args .RemovedParticipants )
301
+ {
302
+ String remoteParticipantMRI = remoteParticipant .Identifier .ToString ();
303
+ remoteParticipantDictionary .Remove (remoteParticipantMRI );
282
304
}
283
305
}
284
306
```
@@ -305,7 +327,7 @@ private async Task AddVideoStreams(IReadOnlyList<RemoteVideoStream> streams)
305
327
```
306
328
307
329
## Call state update
308
- We need to clean the video renderers once the call is disconnected.
330
+ We need to clean the video renderers once the call is disconnected and handle the case when the remote participants initially join the call.
309
331
310
332
``` C#
311
333
private async void Call_OnStateChanged (object sender , PropertyChangedEventArgs args )
@@ -319,8 +341,18 @@ private async void Call_OnStateChanged(object sender, PropertyChangedEventArgs a
319
341
RemoteVideo .Source = null ;
320
342
});
321
343
break ;
344
+
345
+ case CallState .Connected :
346
+ foreach (var remoteParticipant in call .RemoteParticipants )
347
+ {
348
+ String remoteParticipantMRI = remoteParticipant .Identifier .ToString ();
349
+ remoteParticipantDictionary .TryAdd (remoteParticipantMRI , remoteParticipant );
350
+ await AddVideoStreams (remoteParticipant .VideoStreams );
351
+ remoteParticipant .OnVideoStreamsUpdated += Call_OnVideoStreamsUpdated ;
352
+ }
353
+ break ;
354
+
322
355
default :
323
- Debug .WriteLine (((Call )sender ).State );
324
356
break ;
325
357
}
326
358
}
0 commit comments