@@ -516,20 +516,15 @@ export class Call {
516516 await waitUntilCallJoined ( ) ;
517517 }
518518
519- if ( reject && this . ringing ) {
520- // I'm the one who started the call, so I should cancel it.
521- const hasOtherParticipants = this . state . remoteParticipants . length > 0 ;
522- if (
523- this . isCreatedByMe &&
524- ! hasOtherParticipants &&
525- callingState === CallingState . RINGING
526- ) {
527- // Signals other users that I have cancelled my call to them
528- // before they accepted it.
529- await this . reject ( ) ;
530- } else if ( callingState === CallingState . RINGING ) {
531- // Signals other users that I have rejected the incoming call.
532- await this . reject ( ) ;
519+ if ( callingState === CallingState . RINGING ) {
520+ if ( reject ) {
521+ await this . reject ( reason ) ;
522+ } else {
523+ const hasOtherParticipants = this . state . remoteParticipants . length > 0 ;
524+ if ( this . isCreatedByMe && ! hasOtherParticipants ) {
525+ // I'm the one who started the call, so I should cancel it when there are no other participants.
526+ await this . reject ( 'cancel' ) ;
527+ }
533528 }
534529 }
535530
@@ -725,6 +720,7 @@ export class Call {
725720 * @returns a promise which resolves once the call join-flow has finished.
726721 */
727722 join = async ( data ?: JoinCallData ) : Promise < void > => {
723+ const connectStartTime = Date . now ( ) ;
728724 await this . setup ( ) ;
729725 const callingState = this . state . callingState ;
730726 if ( [ CallingState . JOINED , CallingState . JOINING ] . includes ( callingState ) ) {
@@ -793,11 +789,11 @@ export class Call {
793789 : undefined ;
794790 const { callState, fastReconnectDeadlineSeconds } = await sfuClient . join ( {
795791 subscriberSdp : receivingCapabilitiesSdp ,
792+ publisherSdp : '' ,
796793 clientDetails,
797794 fastReconnect : performingFastReconnect ,
798795 reconnectDetails,
799796 } ) ;
800-
801797 this . fastReconnectDeadlineSeconds = fastReconnectDeadlineSeconds ;
802798 if ( callState ) {
803799 this . state . updateFromSfuCallState (
@@ -831,6 +827,16 @@ export class Call {
831827 } ) ;
832828 }
833829
830+ // make sure we only track connection timing if we are not calling this method as part of a reconnection flow
831+ if ( ! performingRejoin && ! performingFastReconnect && ! performingMigration ) {
832+ this . sfuStatsReporter ?. sendTelemetryData ( {
833+ data : {
834+ oneofKind : 'connectionTimeSeconds' ,
835+ connectionTimeSeconds : ( Date . now ( ) - connectStartTime ) / 1000 ,
836+ } ,
837+ } ) ;
838+ }
839+
834840 if ( performingRejoin ) {
835841 const strategy = WebsocketReconnectStrategy [ this . reconnectStrategy ] ;
836842 await previousSfuClient ?. leaveAndClose (
@@ -1130,28 +1136,49 @@ export class Call {
11301136 * @internal
11311137 */
11321138 private reconnectFast = async ( ) => {
1139+ let reconnectStartTime = Date . now ( ) ;
11331140 this . reconnectStrategy = WebsocketReconnectStrategy . FAST ;
11341141 this . state . setCallingState ( CallingState . RECONNECTING ) ;
1135- return this . join ( this . joinCallData ) ;
1142+ await this . join ( this . joinCallData ) ;
1143+ this . sfuStatsReporter ?. sendTelemetryData ( {
1144+ data : {
1145+ oneofKind : 'reconnection' ,
1146+ reconnection : {
1147+ timeSeconds : ( Date . now ( ) - reconnectStartTime ) / 1000 ,
1148+ strategy : WebsocketReconnectStrategy . FAST ,
1149+ } ,
1150+ } ,
1151+ } ) ;
11361152 } ;
11371153
11381154 /**
11391155 * Initiates the reconnection flow with the "rejoin" strategy.
11401156 * @internal
11411157 */
11421158 private reconnectRejoin = async ( ) => {
1159+ let reconnectStartTime = Date . now ( ) ;
11431160 this . reconnectStrategy = WebsocketReconnectStrategy . REJOIN ;
11441161 this . state . setCallingState ( CallingState . RECONNECTING ) ;
11451162 await this . join ( this . joinCallData ) ;
11461163 await this . restorePublishedTracks ( ) ;
11471164 this . restoreSubscribedTracks ( ) ;
1165+ this . sfuStatsReporter ?. sendTelemetryData ( {
1166+ data : {
1167+ oneofKind : 'reconnection' ,
1168+ reconnection : {
1169+ timeSeconds : ( Date . now ( ) - reconnectStartTime ) / 1000 ,
1170+ strategy : WebsocketReconnectStrategy . REJOIN ,
1171+ } ,
1172+ } ,
1173+ } ) ;
11481174 } ;
11491175
11501176 /**
11511177 * Initiates the reconnection flow with the "migrate" strategy.
11521178 * @internal
11531179 */
11541180 private reconnectMigrate = async ( ) => {
1181+ let reconnectStartTime = Date . now ( ) ;
11551182 const currentSfuClient = this . sfuClient ;
11561183 if ( ! currentSfuClient ) {
11571184 throw new Error ( 'Cannot migrate without an active SFU client' ) ;
@@ -1196,6 +1223,15 @@ export class Call {
11961223 // and close the previous SFU client, without specifying close code
11971224 currentSfuClient . close ( ) ;
11981225 }
1226+ this . sfuStatsReporter ?. sendTelemetryData ( {
1227+ data : {
1228+ oneofKind : 'reconnection' ,
1229+ reconnection : {
1230+ timeSeconds : ( Date . now ( ) - reconnectStartTime ) / 1000 ,
1231+ strategy : WebsocketReconnectStrategy . MIGRATE ,
1232+ } ,
1233+ } ,
1234+ } ) ;
11991235 } ;
12001236
12011237 /**
@@ -1919,13 +1955,16 @@ export class Call {
19191955 // ignore if the call is not ringing
19201956 if ( this . state . callingState !== CallingState . RINGING ) return ;
19211957
1922- const timeoutInMs = settings . ring . auto_cancel_timeout_ms ;
1958+ const timeoutInMs = this . isCreatedByMe
1959+ ? settings . ring . auto_cancel_timeout_ms
1960+ : settings . ring . incoming_call_timeout_ms ;
1961+
19231962 // 0 means no auto-drop
19241963 if ( timeoutInMs <= 0 ) return ;
19251964
19261965 clearTimeout ( this . dropTimeout ) ;
19271966 this . dropTimeout = setTimeout ( ( ) => {
1928- this . leave ( { reason : 'ring: timeout' } ) . catch ( ( err ) => {
1967+ this . leave ( { reject : true , reason : ' timeout' } ) . catch ( ( err ) => {
19291968 this . logger ( 'error' , 'Failed to drop call' , err ) ;
19301969 } ) ;
19311970 } , timeoutInMs ) ;
0 commit comments