@@ -65,10 +65,15 @@ import type { ChatMessage, DataPublishOptions } from '../types';
6565import {
6666 Future ,
6767 compareVersions ,
68+ isAudioTrack ,
6869 isE2EESimulcastSupported ,
6970 isFireFox ,
71+ isLocalAudioTrack ,
72+ isLocalTrack ,
73+ isLocalVideoTrack ,
7074 isSVCCodec ,
7175 isSafari17 ,
76+ isVideoTrack ,
7277 isWeb ,
7378 sleep ,
7479 supportsAV1 ,
@@ -640,9 +645,9 @@ export default class LocalParticipant extends Participant {
640645 track . setAudioContext ( this . audioContext ) ;
641646 }
642647 track . mediaStream = stream ;
643- if ( track instanceof LocalAudioTrack && audioProcessor ) {
648+ if ( isAudioTrack ( track ) && audioProcessor ) {
644649 await track . setProcessor ( audioProcessor ) ;
645- } else if ( track instanceof LocalVideoTrack && videoProcessor ) {
650+ } else if ( isVideoTrack ( track ) && videoProcessor ) {
646651 await track . setProcessor ( videoProcessor ) ;
647652 }
648653 return track ;
@@ -717,15 +722,15 @@ export default class LocalParticipant extends Participant {
717722 options ?: TrackPublishOptions ,
718723 isRepublish = false ,
719724 ) : Promise < LocalTrackPublication > {
720- if ( track instanceof LocalAudioTrack ) {
725+ if ( isLocalAudioTrack ( track ) ) {
721726 track . setAudioContext ( this . audioContext ) ;
722727 }
723728
724729 await this . reconnectFuture ?. promise ;
725730 if ( this . republishPromise && ! isRepublish ) {
726731 await this . republishPromise ;
727732 }
728- if ( track instanceof LocalTrack && this . pendingPublishPromises . has ( track ) ) {
733+ if ( isLocalTrack ( track ) && this . pendingPublishPromises . has ( track ) ) {
729734 await this . pendingPublishPromises . get ( track ) ;
730735 }
731736 let defaultConstraints : MediaTrackConstraints | undefined ;
@@ -857,15 +862,15 @@ export default class LocalParticipant extends Participant {
857862
858863 private async publish ( track : LocalTrack , opts : TrackPublishOptions , isStereo : boolean ) {
859864 const existingTrackOfSource = Array . from ( this . trackPublications . values ( ) ) . find (
860- ( publishedTrack ) => track instanceof LocalTrack && publishedTrack . source === track . source ,
865+ ( publishedTrack ) => isLocalTrack ( track ) && publishedTrack . source === track . source ,
861866 ) ;
862867 if ( existingTrackOfSource && track . source !== Track . Source . Unknown ) {
863868 this . log . info ( `publishing a second track with the same source: ${ track . source } ` , {
864869 ...this . logContext ,
865870 ...getLogContextFromTrack ( track ) ,
866871 } ) ;
867872 }
868- if ( opts . stopMicTrackOnMute && track instanceof LocalAudioTrack ) {
873+ if ( opts . stopMicTrackOnMute && isAudioTrack ( track ) ) {
869874 track . stopOnMute = true ;
870875 }
871876
@@ -950,7 +955,7 @@ export default class LocalParticipant extends Participant {
950955 req . width = dims . width ;
951956 req . height = dims . height ;
952957 // for svc codecs, disable simulcast and use vp8 for backup codec
953- if ( track instanceof LocalVideoTrack ) {
958+ if ( isLocalVideoTrack ( track ) ) {
954959 if ( isSVCCodec ( videoCodec ) ) {
955960 if ( track . source === Track . Source . ScreenShare ) {
956961 // vp9 svc with screenshare cannot encode multiple spatial layers
@@ -1036,7 +1041,7 @@ export default class LocalParticipant extends Participant {
10361041
10371042 track . sender = await this . engine . createSender ( track , opts , encodings ) ;
10381043
1039- if ( track instanceof LocalVideoTrack ) {
1044+ if ( isLocalVideoTrack ( track ) ) {
10401045 opts . degradationPreference ??= getDefaultDegradationPreference ( track ) ;
10411046 track . setDegradationPreference ( opts . degradationPreference ) ;
10421047 }
@@ -1126,9 +1131,9 @@ export default class LocalParticipant extends Participant {
11261131 trackInfo : ti ,
11271132 } ) ;
11281133
1129- if ( track instanceof LocalVideoTrack ) {
1134+ if ( isLocalVideoTrack ( track ) ) {
11301135 track . startMonitor ( this . engine . client ) ;
1131- } else if ( track instanceof LocalAudioTrack ) {
1136+ } else if ( isLocalAudioTrack ( track ) ) {
11321137 track . startMonitor ( ) ;
11331138 }
11341139
@@ -1169,7 +1174,7 @@ export default class LocalParticipant extends Participant {
11691174 throw new TrackInvalidError ( 'track is not published' ) ;
11701175 }
11711176
1172- if ( ! ( track instanceof LocalVideoTrack ) ) {
1177+ if ( ! isLocalVideoTrack ( track ) ) {
11731178 throw new TrackInvalidError ( 'track is not a video track' ) ;
11741179 }
11751180
@@ -1236,7 +1241,7 @@ export default class LocalParticipant extends Participant {
12361241 track : LocalTrack | MediaStreamTrack ,
12371242 stopOnUnpublish ?: boolean ,
12381243 ) : Promise < LocalTrackPublication | undefined > {
1239- if ( track instanceof LocalTrack ) {
1244+ if ( isLocalTrack ( track ) ) {
12401245 const publishPromise = this . pendingPublishPromises . get ( track ) ;
12411246 if ( publishPromise ) {
12421247 this . log . info ( 'awaiting publish promise before attempting to unpublish' , {
@@ -1303,7 +1308,7 @@ export default class LocalParticipant extends Participant {
13031308 if ( this . engine . removeTrack ( trackSender ) ) {
13041309 negotiationNeeded = true ;
13051310 }
1306- if ( track instanceof LocalVideoTrack ) {
1311+ if ( isLocalVideoTrack ( track ) ) {
13071312 for ( const [ , trackInfo ] of track . simulcastCodecs ) {
13081313 if ( trackInfo . sender ) {
13091314 if ( this . engine . removeTrack ( trackInfo . sender ) ) {
@@ -1349,9 +1354,7 @@ export default class LocalParticipant extends Participant {
13491354 tracks : LocalTrack [ ] | MediaStreamTrack [ ] ,
13501355 ) : Promise < LocalTrackPublication [ ] > {
13511356 const results = await Promise . all ( tracks . map ( ( track ) => this . unpublishTrack ( track ) ) ) ;
1352- return results . filter (
1353- ( track ) => track instanceof LocalTrackPublication ,
1354- ) as LocalTrackPublication [ ] ;
1357+ return results . filter ( ( track ) => ! ! track ) ;
13551358 }
13561359
13571360 async republishAllTracks ( options ?: TrackPublishOptions , restartTracks : boolean = true ) {
@@ -1379,7 +1382,7 @@ export default class LocalParticipant extends Participant {
13791382 ! track . isMuted &&
13801383 track . source !== Track . Source . ScreenShare &&
13811384 track . source !== Track . Source . ScreenShareAudio &&
1382- ( track instanceof LocalAudioTrack || track instanceof LocalVideoTrack ) &&
1385+ ( isLocalAudioTrack ( track ) || isLocalVideoTrack ( track ) ) &&
13831386 ! track . isUserProvided
13841387 ) {
13851388 // generally we need to restart the track before publishing, often a full reconnect
@@ -1962,7 +1965,7 @@ export default class LocalParticipant extends Participant {
19621965 this . unpublishTrack ( track ) ;
19631966 } else if ( track . isUserProvided ) {
19641967 await track . mute ( ) ;
1965- } else if ( track instanceof LocalAudioTrack || track instanceof LocalVideoTrack ) {
1968+ } else if ( isLocalAudioTrack ( track ) || isLocalVideoTrack ( track ) ) {
19661969 try {
19671970 if ( isWeb ( ) ) {
19681971 try {
@@ -1997,7 +2000,7 @@ export default class LocalParticipant extends Participant {
19972000 ...this . logContext ,
19982001 ...getLogContextFromTrack ( track ) ,
19992002 } ) ;
2000- if ( track instanceof LocalAudioTrack ) {
2003+ if ( isLocalAudioTrack ( track ) ) {
20012004 // fall back to default device if available
20022005 await track . restartTrack ( { deviceId : 'default' } ) ;
20032006 } else {
@@ -2026,7 +2029,7 @@ export default class LocalParticipant extends Participant {
20262029
20272030 // this looks overly complicated due to this object tree
20282031 if ( track instanceof MediaStreamTrack ) {
2029- if ( localTrack instanceof LocalAudioTrack || localTrack instanceof LocalVideoTrack ) {
2032+ if ( isLocalAudioTrack ( localTrack ) || isLocalVideoTrack ( localTrack ) ) {
20302033 if ( localTrack . mediaStreamTrack === track ) {
20312034 publication = < LocalTrackPublication > pub ;
20322035 }
0 commit comments