@@ -20,8 +20,8 @@ import {
20
20
VideoCaptureOptions ,
21
21
VideoCodec ,
22
22
VideoPresets ,
23
- VideoQuality ,
24
- } from '../src/index' ;
23
+ VideoQuality
24
+ } from '../src/index'
25
25
26
26
const $ = ( id : string ) => document . getElementById ( id ) ;
27
27
@@ -110,12 +110,12 @@ const appActions = {
110
110
. on ( RoomEvent . LocalTrackPublished , ( ) => {
111
111
renderParticipant ( room . localParticipant ) ;
112
112
updateButtonsForPublishState ( ) ;
113
- renderScreenShare ( ) ;
113
+ renderScreenShare ( room ) ;
114
114
} )
115
115
. on ( RoomEvent . LocalTrackUnpublished , ( ) => {
116
116
renderParticipant ( room . localParticipant ) ;
117
117
updateButtonsForPublishState ( ) ;
118
- renderScreenShare ( ) ;
118
+ renderScreenShare ( room ) ;
119
119
} )
120
120
. on ( RoomEvent . RoomMetadataChanged , ( metadata ) => {
121
121
appendLog ( 'new metadata for room' , metadata ) ;
@@ -138,9 +138,15 @@ const appActions = {
138
138
appendLog ( 'connection quality changed' , participant ?. identity , quality ) ;
139
139
} ,
140
140
)
141
- . on ( RoomEvent . TrackSubscribed , ( _1 , _2 , participant : RemoteParticipant ) => {
141
+ . on ( RoomEvent . TrackSubscribed , ( _1 , pub , participant ) => {
142
+ appendLog ( 'subscribed to track' , pub . trackSid , participant . identity ) ;
142
143
renderParticipant ( participant ) ;
143
- renderScreenShare ( ) ;
144
+ renderScreenShare ( room ) ;
145
+ } )
146
+ . on ( RoomEvent . TrackUnsubscribed , ( _ , pub , participant ) => {
147
+ appendLog ( 'unsubscribed from track' , pub . trackSid ) ;
148
+ renderParticipant ( participant ) ;
149
+ renderScreenShare ( room ) ;
144
150
} )
145
151
. on ( RoomEvent . SignalConnected , async ( ) => {
146
152
if ( shouldPublish ) {
@@ -351,16 +357,6 @@ function handleData(msg: Uint8Array, participant?: RemoteParticipant) {
351
357
function participantConnected ( participant : Participant ) {
352
358
appendLog ( 'participant' , participant . identity , 'connected' , participant . metadata ) ;
353
359
participant
354
- . on ( ParticipantEvent . TrackSubscribed , ( _ , pub : TrackPublication ) => {
355
- appendLog ( 'subscribed to track' , pub . trackSid , participant . identity ) ;
356
- renderParticipant ( participant ) ;
357
- renderScreenShare ( ) ;
358
- } )
359
- . on ( ParticipantEvent . TrackUnsubscribed , ( _ , pub : TrackPublication ) => {
360
- appendLog ( 'unsubscribed from track' , pub . trackSid ) ;
361
- renderParticipant ( participant ) ;
362
- renderScreenShare ( ) ;
363
- } )
364
360
. on ( ParticipantEvent . TrackMuted , ( pub : TrackPublication ) => {
365
361
appendLog ( 'track was muted' , pub . trackSid , participant . identity ) ;
366
362
renderParticipant ( participant ) ;
@@ -391,7 +387,7 @@ function handleRoomDisconnect() {
391
387
currentRoom . participants . forEach ( ( p ) => {
392
388
renderParticipant ( p , true ) ;
393
389
} ) ;
394
- renderScreenShare ( ) ;
390
+ renderScreenShare ( currentRoom ) ;
395
391
396
392
const container = $ ( 'participants-area' ) ;
397
393
if ( container ) {
@@ -572,19 +568,19 @@ function renderParticipant(participant: Participant, remove: boolean = false) {
572
568
}
573
569
}
574
570
575
- function renderScreenShare ( ) {
571
+ function renderScreenShare ( room : Room ) {
576
572
const div = $ ( 'screenshare-area' ) ! ;
577
- if ( ! currentRoom || currentRoom . state !== ConnectionState . Connected ) {
573
+ if ( room . state !== ConnectionState . Connected ) {
578
574
div . style . display = 'none' ;
579
575
return ;
580
576
}
581
577
let participant : Participant | undefined ;
582
- let screenSharePub : TrackPublication | undefined = currentRoom . localParticipant . getTrack (
578
+ let screenSharePub : TrackPublication | undefined = room . localParticipant . getTrack (
583
579
Track . Source . ScreenShare ,
584
580
) ;
585
581
let screenShareAudioPub : RemoteTrackPublication | undefined ;
586
582
if ( ! screenSharePub ) {
587
- currentRoom . participants . forEach ( ( p ) => {
583
+ room . participants . forEach ( ( p ) => {
588
584
if ( screenSharePub ) {
589
585
return ;
590
586
}
@@ -599,7 +595,7 @@ function renderScreenShare() {
599
595
}
600
596
} ) ;
601
597
} else {
602
- participant = currentRoom . localParticipant ;
598
+ participant = room . localParticipant ;
603
599
}
604
600
605
601
if ( screenSharePub && participant ) {
0 commit comments