File tree Expand file tree Collapse file tree 2 files changed +22
-26
lines changed Expand file tree Collapse file tree 2 files changed +22
-26
lines changed Original file line number Diff line number Diff line change @@ -82,24 +82,22 @@ const Example = (props) => {
82
82
const _onParticipantAddedVideoTrack = ( { participant, track } ) => {
83
83
console . log ( "onParticipantAddedVideoTrack: " , participant , track ) ;
84
84
85
- setVideoTracks (
86
- new Map ( [
87
- ...videoTracks ,
88
- [
89
- track . trackSid ,
90
- { participantSid : participant . sid , videoTrackSid : track . trackSid } ,
91
- ] ,
92
- ] )
93
- ) ;
85
+ setVideoTracks ( ( originalVideoTracks ) => {
86
+ originalVideoTracks . set ( track . trackSid , {
87
+ participantSid : participant . sid ,
88
+ videoTrackSid : track . trackSid ,
89
+ } ) ;
90
+ return new Map ( originalVideoTracks ) ;
91
+ } ) ;
94
92
} ;
95
93
96
94
const _onParticipantRemovedVideoTrack = ( { participant, track } ) => {
97
95
console . log ( "onParticipantRemovedVideoTrack: " , participant , track ) ;
98
96
99
- const newVideoTracks = new Map ( videoTracks ) ;
100
- newVideoTracks . delete ( track . trackSid ) ;
101
-
102
- setVideoTracks ( newVideoTracks ) ;
97
+ setVideoTracks ( ( originalVideoTracks ) => {
98
+ originalVideoTracks . delete ( track . trackSid ) ;
99
+ return new Map ( originalVideoTracks ) ;
100
+ } ) ;
103
101
} ;
104
102
105
103
const _onNetworkLevelChanged = ( { participant, isLocalUser, quality } ) => {
Original file line number Diff line number Diff line change @@ -302,24 +302,22 @@ const Example = (props) => {
302
302
const _onParticipantAddedVideoTrack = ({ participant, track }) => {
303
303
console .log (" onParticipantAddedVideoTrack: " , participant, track);
304
304
305
- setVideoTracks (
306
- new Map ([
307
- ... videoTracks,
308
- [
309
- track .trackSid ,
310
- { participantSid: participant .sid , videoTrackSid: track .trackSid },
311
- ],
312
- ])
313
- );
305
+ setVideoTracks ((originalVideoTracks ) => {
306
+ originalVideoTracks .set (track .trackSid , {
307
+ participantSid: participant .sid ,
308
+ videoTrackSid: track .trackSid ,
309
+ });
310
+ return new Map (originalVideoTracks);
311
+ });
314
312
};
315
313
316
314
const _onParticipantRemovedVideoTrack = ({ participant, track }) => {
317
315
console .log (" onParticipantRemovedVideoTrack: " , participant, track);
318
316
319
- const videoTracksLocal = videoTracks;
320
- videoTracksLocal .delete (track .trackSid );
321
-
322
- setVideoTracks (videoTracksLocal );
317
+ setVideoTracks (( originalVideoTracks ) => {
318
+ originalVideoTracks .delete (track .trackSid );
319
+ return new Map (originalVideoTracks);
320
+ } );
323
321
};
324
322
325
323
return (
You can’t perform that action at this time.
0 commit comments