@@ -136,12 +136,11 @@ import {
136136 AllCallEvents ,
137137 CallEventListener ,
138138 ErrorFromResponse ,
139- Logger ,
140139 RejectReason ,
141140 StreamCallEvent ,
142141} from './coordinator/connection/types' ;
143142import { getClientDetails } from './helpers/client-details' ;
144- import { getLogger } from './logger' ;
143+ import { getLogger , ScopedLogger } from './logger' ;
145144import {
146145 CameraManager ,
147146 MicrophoneManager ,
@@ -226,7 +225,7 @@ export class Call {
226225 */
227226 readonly permissionsContext = new PermissionsContext ( ) ;
228227 readonly tracer = new Tracer ( null ) ;
229- readonly logger : Logger ;
228+ readonly logger : ScopedLogger ;
230229
231230 /**
232231 * The event dispatcher instance dedicated to this Call instance.
@@ -309,7 +308,7 @@ export class Call {
309308 this . streamClient = streamClient ;
310309 this . clientStore = clientStore ;
311310 this . streamClientBasePath = `/call/${ this . type } /${ this . id } ` ;
312- this . logger = getLogger ( [ 'Call' ] ) ;
311+ this . logger = getLogger ( 'Call' ) ;
313312
314313 const callTypeConfig = CallTypes . get ( type ) ;
315314 const participantSorter =
@@ -393,9 +392,9 @@ export class Call {
393392 if ( ! blockedUserIds || blockedUserIds . length === 0 ) return ;
394393 const currentUserId = this . currentUserId ;
395394 if ( currentUserId && blockedUserIds . includes ( currentUserId ) ) {
396- this . logger ( ' info' , 'Leaving call because of being blocked' ) ;
395+ this . logger . info ( 'Leaving call because of being blocked' ) ;
397396 await this . leave ( { message : 'user blocked' } ) . catch ( ( err ) => {
398- this . logger ( ' error' , 'Error leaving call after being blocked' , err ) ;
397+ this . logger . error ( 'Error leaving call after being blocked' , err ) ;
399398 } ) ;
400399 }
401400 } ) ,
@@ -439,8 +438,7 @@ export class Call {
439438 ! hasPending ( this . joinLeaveConcurrencyTag )
440439 ) {
441440 this . leave ( ) . catch ( ( ) => {
442- this . logger (
443- 'error' ,
441+ this . logger . error (
444442 'Could not leave a call that was accepted or rejected elsewhere' ,
445443 ) ;
446444 } ) ;
@@ -523,8 +521,7 @@ export class Call {
523521 break ;
524522 }
525523 } catch ( err ) {
526- this . logger (
527- 'error' ,
524+ this . logger . error (
528525 `Can't disable mic/camera/screenshare after revoked permissions` ,
529526 err ,
530527 ) ;
@@ -883,12 +880,12 @@ export class Call {
883880 maxJoinRetries = Math . max ( maxJoinRetries , 1 ) ;
884881 for ( let attempt = 0 ; attempt < maxJoinRetries ; attempt ++ ) {
885882 try {
886- this . logger ( ' trace' , `Joining call (${ attempt } )` , this . cid ) ;
883+ this . logger . trace ( `Joining call (${ attempt } )` , this . cid ) ;
887884 await this . doJoin ( data ) ;
888885 delete joinData . migrating_from ;
889886 break ;
890887 } catch ( err ) {
891- this . logger ( ' warn' , `Failed to join call (${ attempt } )` , this . cid ) ;
888+ this . logger . warn ( `Failed to join call (${ attempt } )` , this . cid ) ;
892889 if ( err instanceof ErrorFromResponse && err . unrecoverable ) {
893890 // if the error is unrecoverable, we should not retry as that signals
894891 // that connectivity is good, but the coordinator doesn't allow the user
@@ -924,7 +921,7 @@ export class Call {
924921
925922 this . joinCallData = data ;
926923
927- this . logger ( ' debug' , 'Starting join flow' ) ;
924+ this . logger . debug ( 'Starting join flow' ) ;
928925 this . state . setCallingState ( CallingState . JOINING ) ;
929926
930927 const performingMigration =
@@ -1028,7 +1025,7 @@ export class Call {
10281025 ) ;
10291026 }
10301027 } catch ( error ) {
1031- this . logger ( ' warn' , 'Join SFU request failed' , error ) ;
1028+ this . logger . warn ( 'Join SFU request failed' , error ) ;
10321029 sfuClient . close (
10331030 StreamSfuClient . JOIN_FAILED ,
10341031 'Join request failed, connection considered unhealthy' ,
@@ -1100,7 +1097,7 @@ export class Call {
11001097 this . reconnectStrategy = WebsocketReconnectStrategy . UNSPECIFIED ;
11011098 this . reconnectReason = '' ;
11021099
1103- this . logger ( ' info' , `Joined call ${ this . cid } ` ) ;
1100+ this . logger . info ( `Joined call ${ this . cid } ` ) ;
11041101 } ;
11051102
11061103 /**
@@ -1247,7 +1244,7 @@ export class Call {
12471244 onReconnectionNeeded : ( kind , reason ) => {
12481245 this . reconnect ( kind , reason ) . catch ( ( err ) => {
12491246 const message = `[Reconnect] Error reconnecting after a subscriber error: ${ reason } ` ;
1250- this . logger ( ' warn' , message , err ) ;
1247+ this . logger . warn ( message , err ) ;
12511248 } ) ;
12521249 } ,
12531250 } ) ;
@@ -1270,7 +1267,7 @@ export class Call {
12701267 onReconnectionNeeded : ( kind , reason ) => {
12711268 this . reconnect ( kind , reason ) . catch ( ( err ) => {
12721269 const message = `[Reconnect] Error reconnecting after a publisher error: ${ reason } ` ;
1273- this . logger ( ' warn' , message , err ) ;
1270+ this . logger . warn ( message , err ) ;
12741271 } ) ;
12751272 } ,
12761273 } ) ;
@@ -1355,7 +1352,7 @@ export class Call {
13551352 sfuClient : StreamSfuClient ,
13561353 reason : string ,
13571354 ) => {
1358- this . logger ( ' debug' , '[Reconnect] SFU signal connection closed' ) ;
1355+ this . logger . debug ( '[Reconnect] SFU signal connection closed' ) ;
13591356 const { callingState } = this . state ;
13601357 if (
13611358 // SFU WS closed before we finished current join,
@@ -1378,7 +1375,7 @@ export class Call {
13781375 ? WebsocketReconnectStrategy . FAST
13791376 : WebsocketReconnectStrategy . REJOIN ;
13801377 this . reconnect ( strategy , reason ) . catch ( ( err ) => {
1381- this . logger ( ' warn' , '[Reconnect] Error reconnecting' , err ) ;
1378+ this . logger . warn ( '[Reconnect] Error reconnecting' , err ) ;
13821379 } ) ;
13831380 } ;
13841381
@@ -1424,8 +1421,7 @@ export class Call {
14241421 reconnectingTime / 1000 > this . disconnectionTimeoutSeconds ;
14251422
14261423 if ( shouldGiveUpReconnecting ) {
1427- this . logger (
1428- 'warn' ,
1424+ this . logger . warn (
14291425 '[Reconnect] Stopping reconnection attempts after reaching disconnection timeout' ,
14301426 ) ;
14311427 await markAsReconnectingFailed ( ) ;
@@ -1442,16 +1438,14 @@ export class Call {
14421438 // wait until the network is available
14431439 await this . networkAvailableTask ?. promise ;
14441440
1445- this . logger (
1446- 'info' ,
1441+ this . logger . info (
14471442 `[Reconnect] Reconnecting with strategy ${ WebsocketReconnectStrategy [ this . reconnectStrategy ] } ` ,
14481443 ) ;
14491444
14501445 switch ( this . reconnectStrategy ) {
14511446 case WebsocketReconnectStrategy . UNSPECIFIED :
14521447 case WebsocketReconnectStrategy . DISCONNECT :
1453- this . logger (
1454- 'debug' ,
1448+ this . logger . debug (
14551449 `[Reconnect] No-op strategy ${ currentStrategy } ` ,
14561450 ) ;
14571451 break ;
@@ -1474,17 +1468,15 @@ export class Call {
14741468 break ; // do-while loop, reconnection worked, exit the loop
14751469 } catch ( error ) {
14761470 if ( this . state . callingState === CallingState . OFFLINE ) {
1477- this . logger (
1478- 'debug' ,
1471+ this . logger . debug (
14791472 `[Reconnect] Can't reconnect while offline, stopping reconnection attempts` ,
14801473 ) ;
14811474 break ;
14821475 // we don't need to handle the error if the call is offline
14831476 // network change event will trigger the reconnection
14841477 }
14851478 if ( error instanceof ErrorFromResponse && error . unrecoverable ) {
1486- this . logger (
1487- 'warn' ,
1479+ this . logger . warn (
14881480 `[Reconnect] Can't reconnect due to coordinator unrecoverable error` ,
14891481 error ,
14901482 ) ;
@@ -1517,8 +1509,7 @@ export class Call {
15171509 : WebsocketReconnectStrategy . FAST ;
15181510 this . reconnectStrategy = nextStrategy ;
15191511
1520- this . logger (
1521- 'info' ,
1512+ this . logger . info (
15221513 `[Reconnect] ${ currentStrategy } (${ this . reconnectAttempts } ) failed. Attempting with ${ WebsocketReconnectStrategy [ nextStrategy ] } ` ,
15231514 error ,
15241515 ) ;
@@ -1528,7 +1519,7 @@ export class Call {
15281519 this . state . callingState !== CallingState . RECONNECTING_FAILED &&
15291520 this . state . callingState !== CallingState . LEFT
15301521 ) ;
1531- this . logger ( ' info' , '[Reconnect] Reconnection flow finished' ) ;
1522+ this . logger . info ( '[Reconnect] Reconnection flow finished' ) ;
15321523 } ) ;
15331524 } ;
15341525
@@ -1630,7 +1621,7 @@ export class Call {
16301621 // handles the legacy "goAway" event
16311622 const unregisterGoAway = this . on ( 'goAway' , ( ) => {
16321623 this . reconnect ( WebsocketReconnectStrategy . MIGRATE , 'goAway' ) . catch (
1633- ( err ) => this . logger ( ' warn' , '[Reconnect] Error reconnecting' , err ) ,
1624+ ( err ) => this . logger . warn ( '[Reconnect] Error reconnecting' , err ) ,
16341625 ) ;
16351626 } ) ;
16361627
@@ -1640,11 +1631,11 @@ export class Call {
16401631 if ( strategy === WebsocketReconnectStrategy . UNSPECIFIED ) return ;
16411632 if ( strategy === WebsocketReconnectStrategy . DISCONNECT ) {
16421633 this . leave ( { message : 'SFU instructed to disconnect' } ) . catch ( ( err ) => {
1643- this . logger ( ' warn' , `Can't leave call after disconnect request` , err ) ;
1634+ this . logger . warn ( `Can't leave call after disconnect request` , err ) ;
16441635 } ) ;
16451636 } else {
16461637 this . reconnect ( strategy , error ?. message || 'SFU Error' ) . catch ( ( err ) => {
1647- this . logger ( ' warn' , '[Reconnect] Error reconnecting' , err ) ;
1638+ this . logger . warn ( '[Reconnect] Error reconnecting' , err ) ;
16481639 } ) ;
16491640 }
16501641 } ) ;
@@ -1654,7 +1645,7 @@ export class Call {
16541645 ( e ) => {
16551646 this . tracer . trace ( 'network.changed' , e ) ;
16561647 if ( ! e . online ) {
1657- this . logger ( ' debug' , '[Reconnect] Going offline' ) ;
1648+ this . logger . debug ( '[Reconnect] Going offline' ) ;
16581649 if ( ! this . hasJoinedOnce ) return ;
16591650 this . lastOfflineTimestamp = Date . now ( ) ;
16601651 // create a new task that would resolve when the network is available
@@ -1671,8 +1662,7 @@ export class Call {
16711662 }
16721663
16731664 this . reconnect ( strategy , 'Going online' ) . catch ( ( err ) => {
1674- this . logger (
1675- 'warn' ,
1665+ this . logger . warn (
16761666 '[Reconnect] Error reconnecting after going online' ,
16771667 err ,
16781668 ) ;
@@ -1682,7 +1672,7 @@ export class Call {
16821672 this . sfuStatsReporter ?. stop ( ) ;
16831673 this . state . setCallingState ( CallingState . OFFLINE ) ;
16841674 } else {
1685- this . logger ( ' debug' , '[Reconnect] Going online' ) ;
1675+ this . logger . debug ( '[Reconnect] Going online' ) ;
16861676 this . sfuClient ?. close (
16871677 StreamSfuClient . DISPOSE_OLD_SOCKET ,
16881678 'Closing WS to reconnect after going online' ,
@@ -1872,14 +1862,12 @@ export class Call {
18721862 * @param options the options to use.
18731863 */
18741864 updatePublishOptions = ( options : ClientPublishOptions ) => {
1875- this . logger (
1876- 'warn' ,
1865+ this . logger . warn (
18771866 '[call.updatePublishOptions]: You are manually overriding the publish options for this call. ' +
18781867 'This is not recommended, and it can cause call stability/compatibility issues. Use with caution.' ,
18791868 ) ;
18801869 if ( this . state . callingState === CallingState . JOINED ) {
1881- this . logger (
1882- 'warn' ,
1870+ this . logger . warn (
18831871 'Updating publish options after joining the call does not have an effect' ,
18841872 ) ;
18851873 }
@@ -1893,7 +1881,7 @@ export class Call {
18931881 */
18941882 notifyNoiseCancellationStarting = async ( ) => {
18951883 return this . sfuClient ?. startNoiseCancellation ( ) . catch ( ( err ) => {
1896- this . logger ( ' warn' , 'Failed to notify start of noise cancellation' , err ) ;
1884+ this . logger . warn ( 'Failed to notify start of noise cancellation' , err ) ;
18971885 } ) ;
18981886 } ;
18991887
@@ -1904,7 +1892,7 @@ export class Call {
19041892 */
19051893 notifyNoiseCancellationStopped = async ( ) => {
19061894 return this . sfuClient ?. stopNoiseCancellation ( ) . catch ( ( err ) => {
1907- this . logger ( ' warn' , 'Failed to notify stop of noise cancellation' , err ) ;
1895+ this . logger . warn ( 'Failed to notify stop of noise cancellation' , err ) ;
19081896 } ) ;
19091897 } ;
19101898
@@ -2489,7 +2477,7 @@ export class Call {
24892477 reason : 'timeout' ,
24902478 message : `ringing timeout - ${ this . isCreatedByMe ? 'no one accepted' : `user didn't interact with incoming call screen` } ` ,
24912479 } ) . catch ( ( err ) => {
2492- this . logger ( ' error' , 'Failed to drop call' , err ) ;
2480+ this . logger . error ( 'Failed to drop call' , err ) ;
24932481 } ) ;
24942482 } , timeoutInMs ) ;
24952483 } ;
@@ -2616,10 +2604,10 @@ export class Call {
26162604 publish : boolean ,
26172605 ) => {
26182606 await this . camera . apply ( settings . video , publish ) . catch ( ( err ) => {
2619- this . logger ( ' warn' , 'Camera init failed' , err ) ;
2607+ this . logger . warn ( 'Camera init failed' , err ) ;
26202608 } ) ;
26212609 await this . microphone . apply ( settings . audio , publish ) . catch ( ( err ) => {
2622- this . logger ( ' warn' , 'Mic init failed' , err ) ;
2610+ this . logger . warn ( 'Mic init failed' , err ) ;
26232611 } ) ;
26242612 } ;
26252613
0 commit comments