@wazo/sdk 0.43.8 → 0.43.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,7 +159,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
159
159
  async sendReinvite(callSession?: CallSession, constraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
160
160
  const sipSession = this.findSipSession(callSession);
161
161
  logger.info('WebRTC phone - send reinvite', {
162
- sessionId: sipSession ? sipSession.id : null,
162
+ sessionId: this.getSipSessionId(sipSession),
163
163
  constraints,
164
164
  audioOnly,
165
165
  conference,
@@ -380,7 +380,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
380
380
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
381
381
  const callSession = this._createCallSession(sipSession);
382
382
 
383
- delete this.callSessions[sipSessionId];
383
+ if (sipSessionId) {
384
+ delete this.callSessions[sipSessionId];
385
+ }
384
386
  this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
385
387
  };
386
388
  }
@@ -389,7 +391,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
389
391
  switch (newState) {
390
392
  case SessionState.Terminating:
391
393
  logger.info('WebRTC phone - call terminating', {
392
- sipId: sipSession.id,
394
+ sipId: this.getSipSessionId(sipSession),
393
395
  });
394
396
  this.eventEmitter.emit(ON_CALL_ENDING, this._createCallSession(sipSession));
395
397
  break;
@@ -397,7 +399,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
397
399
  case SessionState.Terminated:
398
400
  {
399
401
  logger.info('WebRTC phone - call terminated', {
400
- sipId: sipSession.id,
402
+ sipId: this.getSipSessionId(sipSession),
401
403
  });
402
404
 
403
405
  // Should be called before `_onCallTerminated` or the callCount will not decrement...
@@ -580,7 +582,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
580
582
 
581
583
  _onCallAccepted(sipSession: WazoSession, cameraEnabled: boolean): CallSession {
582
584
  logger.info('WebRTC phone - on call accepted', {
583
- sipId: sipSession.id,
585
+ sipId: this.getSipSessionId(sipSession),
584
586
  cameraEnabled,
585
587
  });
586
588
 
@@ -588,7 +590,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
588
590
 
589
591
  if (this.currentSipSession && !this.isCurrentCallSipSession(callSession)) {
590
592
  logger.info('WebRTC phone - on call accepted with another ongoing call, holding it', {
591
- sipId: sipSession.id,
593
+ sipId: this.getSipSessionId(sipSession),
592
594
  cameraEnabled,
593
595
  });
594
596
 
@@ -673,7 +675,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
673
675
  const sipSessionId = this.getSipSessionId(sipSession);
674
676
 
675
677
  logger.info('WebRTC phone - on call terminated', {
676
- sipId: sipSession.id,
678
+ sipId: this.getSipSessionId(sipSession),
677
679
  sipSessionId,
678
680
  ids: Object.keys(this.callSessions),
679
681
  });
@@ -697,9 +699,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
697
699
 
698
700
  if (sipSessionId) {
699
701
  this.removeIncomingSessions(sipSessionId);
700
- }
701
702
 
702
- delete this.callSessions[sipSessionId];
703
+ delete this.callSessions[sipSessionId];
704
+ }
703
705
 
704
706
  if (isCurrentSession) {
705
707
  this.currentSipSession = undefined;
@@ -709,7 +711,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
709
711
  const hasIncomingCallSession = this.hasIncomingCallSession();
710
712
  // Re-trigger incoming call event for remaining incoming calls
711
713
  logger.info('WebRTC phone - check to re-trigger incoming call', {
712
- sipId: sipSession.id,
714
+ sipId: this.getSipSessionId(sipSession),
713
715
  shouldRetrigger,
714
716
  hasIncomingCallSession,
715
717
  });
@@ -853,7 +855,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
853
855
  const sipSession = this.client.getSipSession(callSession.getId()) as Invitation;
854
856
 
855
857
  if (sipSession) {
856
- logger.info('accept call, session found', { sipId: sipSession.id });
858
+ logger.info('accept call, session found', { sipId: this.getSipSessionId(sipSession) });
857
859
 
858
860
  return this.client.answer(sipSession, this.allowVideo ? cameraEnabled : false).then(() => {
859
861
  return callSession.sipCallId;
@@ -898,7 +900,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
898
900
 
899
901
  if (sipSession) {
900
902
  logger.info('WebRTC rejecting', {
901
- sipId: sipSession.id,
903
+ sipId: this.getSipSessionId(sipSession),
902
904
  });
903
905
  this.client.hangup(sipSession);
904
906
  }
@@ -919,7 +921,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
919
921
 
920
922
  if (sipSession) {
921
923
  logger.info('WebRTC atxfer', {
922
- sipId: sipSession.id,
924
+ sipId: this.getSipSessionId(sipSession),
923
925
  });
924
926
  return this.client.atxfer(sipSession);
925
927
  }
@@ -950,13 +952,13 @@ export default class WebRTCPhone extends Emitter implements Phone {
950
952
  }
951
953
 
952
954
  logger.info('WebRTC resuming', {
953
- sipId: sipSession.id,
955
+ sipId: this.getSipSessionId(sipSession),
954
956
  });
955
957
 
956
958
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
957
- if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
959
+ if (this.currentSipSession && this.getSipSessionId(this.currentSipSession) !== this.getSipSessionId(sipSession)) {
958
960
  logger.info('WebRTC hold call after resume', {
959
- id: this.currentSipSession.id,
961
+ id: this.getSipSessionId(this.currentSipSession),
960
962
  });
961
963
  this.holdSipSession(this.currentSipSession, this.currentCallSession, withEvent);
962
964
  }
@@ -979,7 +981,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
979
981
  const sessionId = this.getSipSessionId(sipSession);
980
982
  const hasVideo = this.client.hasLocalVideo(sessionId);
981
983
  logger.info('WebRTC hold sip session', {
982
- sipId: sipSession.id,
984
+ sipId: this.getSipSessionId(sipSession),
983
985
  hasVideo,
984
986
  });
985
987
 
@@ -1076,7 +1078,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1076
1078
  }
1077
1079
 
1078
1080
  logger.info('WebRTC muting', {
1079
- sipId: sipSession.id,
1081
+ sipId: this.getSipSessionId(sipSession),
1080
1082
  });
1081
1083
  this.client.mute(sipSession);
1082
1084
 
@@ -1104,7 +1106,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1104
1106
  }
1105
1107
 
1106
1108
  logger.info('WebRTC unmuting', {
1107
- sipId: sipSession.id,
1109
+ sipId: this.getSipSessionId(sipSession),
1108
1110
  });
1109
1111
  this.client.unmute(sipSession);
1110
1112
 
@@ -1139,7 +1141,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1139
1141
  }
1140
1142
 
1141
1143
  logger.info('WebRTC turn camera on', {
1142
- sipId: sipSession.id,
1144
+ sipId: this.getSipSessionId(sipSession),
1143
1145
  });
1144
1146
  this.client.toggleCameraOn(sipSession);
1145
1147
  this.eventEmitter.emit(ON_CAMERA_RESUMED, this._createCameraResumedCallSession(sipSession, callSession));
@@ -1153,7 +1155,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1153
1155
  }
1154
1156
 
1155
1157
  logger.info('WebRTC turn camera off', {
1156
- sipId: sipSession.id,
1158
+ sipId: this.getSipSessionId(sipSession),
1157
1159
  });
1158
1160
  this.client.toggleCameraOff(sipSession);
1159
1161
  this.eventEmitter.emit(ON_CAMERA_DISABLED, this._createCameraDisabledCallSession(sipSession, callSession));
@@ -1167,7 +1169,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1167
1169
  }
1168
1170
 
1169
1171
  logger.info('WebRTC send key', {
1170
- sipId: sipSession.id,
1172
+ sipId: this.getSipSessionId(sipSession),
1171
1173
  tone,
1172
1174
  });
1173
1175
  this.client.sendDTMF(sipSession, tone);
@@ -1245,7 +1247,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1245
1247
  }
1246
1248
 
1247
1249
  logger.info('WebRTC transfer', {
1248
- sipId: sipSession.id,
1250
+ sipId: this.getSipSessionId(sipSession),
1249
1251
  target,
1250
1252
  });
1251
1253
  this.client.transfer(sipSession, target);
@@ -1255,8 +1257,8 @@ export default class WebRTCPhone extends Emitter implements Phone {
1255
1257
  const sipSession = this.client.getSipSession(source.sipCallId);
1256
1258
  const sipSessionTarget = this.client.getSipSession(destination.sipCallId);
1257
1259
  logger.info('WebRTC indirect transfer', {
1258
- sipId: sipSession ? sipSession.id : null,
1259
- target: sipSessionTarget ? sipSessionTarget.id : null,
1260
+ sipId: sipSession ? this.getSipSessionId(sipSession) : null,
1261
+ target: sipSessionTarget ? this.getSipSessionId(sipSessionTarget) : null,
1260
1262
  });
1261
1263
 
1262
1264
  if (!sipSessionTarget) {
@@ -1295,7 +1297,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1295
1297
  const sipSessionId = this.getSipSessionId(sipSession);
1296
1298
 
1297
1299
  logger.info('WebRTC hangup', {
1298
- sipId: sipSession.id,
1300
+ sipId: this.getSipSessionId(sipSession),
1299
1301
  sipSessionId,
1300
1302
  });
1301
1303
  await this.client.hangup(sipSession);
@@ -1484,7 +1486,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1484
1486
  const autoAnswer = sipSession.request.getHeader('Answer-Mode') === 'Auto';
1485
1487
  const withVideo = this.allowVideo ? wantsToDoVideo : false;
1486
1488
  logger.info('WebRTC invite received', {
1487
- sipId: sipSession.id,
1489
+ sipId: this.getSipSessionId(sipSession),
1488
1490
  withVideo,
1489
1491
  autoAnswer,
1490
1492
  });
@@ -1555,7 +1557,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
1555
1557
  this.eventEmitter.emit(ON_CALL_ERROR, e);
1556
1558
  });
1557
1559
  this.client.on(this.client.REJECTED, session => {
1558
- logger.info('WebRTC call rejected', session.id);
1560
+ logger.info('WebRTC call rejected', { id: this.getSipSessionId(session) });
1559
1561
 
1560
1562
  const callSession = this._createCallSession(session);
1561
1563
 
@@ -1687,7 +1689,10 @@ export default class WebRTCPhone extends Emitter implements Phone {
1687
1689
  return this.callSessions[sipSessionId];
1688
1690
  }
1689
1691
 
1690
- getSipSessionId(sipSession: WazoSession): string {
1692
+ getSipSessionId(sipSession: WazoSession | null | undefined): string {
1693
+ if (!sipSession) {
1694
+ return '';
1695
+ }
1691
1696
  return this.client.getSipSessionId(sipSession);
1692
1697
  }
1693
1698
 
@@ -42,7 +42,6 @@ export const replaceLocalIpModifier = (description: Record<string, any>) => Prom
42
42
  ...JSON.parse(JSON.stringify(description)),
43
43
  sdp: description.sdp.replace('c=IN IP4 0.0.0.0', 'c=IN IP4 127.0.0.1'),
44
44
  });
45
- const SIP_ID_LENGTH = 36;
46
45
  const DEFAULT_ICE_TIMEOUT = 3000;
47
46
  const SEND_STATS_DELAY = 5000;
48
47
  const states = ['STATUS_NULL', 'STATUS_NEW', 'STATUS_CONNECTING', 'STATUS_CONNECTED', 'STATUS_COMPLETED'];
@@ -268,7 +267,7 @@ export default class WebRTCClient extends Emitter {
268
267
  logger.info('sdk webrtc on invite', {
269
268
  method: 'delegate.onInvite',
270
269
  clientId: this.clientId,
271
- id: invitation.id,
270
+ id: this.getSipSessionId(invitation),
272
271
  remoteURI: (invitation as any).remoteURI,
273
272
  });
274
273
 
@@ -604,7 +603,7 @@ export default class WebRTCClient extends Emitter {
604
603
  },
605
604
  onReject: (response: IncomingResponse) => {
606
605
  logger.info('on call rejected', {
607
- id: session?.id,
606
+ id: this.getSipSessionId(session),
608
607
  // @ts-ignore: fromTag does not exist
609
608
  fromTag: session?.fromTag,
610
609
  });
@@ -641,7 +640,7 @@ export default class WebRTCClient extends Emitter {
641
640
  answer(session: Invitation, enableVideo?: boolean): Promise<void> {
642
641
  logger.info('sdk webrtc answer call', {
643
642
  clientId: this.clientId,
644
- id: session.id,
643
+ id: this.getSipSessionId(session),
645
644
  enableVideo,
646
645
  });
647
646
 
@@ -659,7 +658,7 @@ export default class WebRTCClient extends Emitter {
659
658
  if (session.isCanceled) {
660
659
  const message = 'accepted a canceled session (or was canceled during the accept phase).';
661
660
  logger.error(message, {
662
- id: session.id,
661
+ id: this.getSipSessionId(session),
663
662
  });
664
663
  this.onCallEnded(session);
665
664
  throw new CanceledCallError(message);
@@ -669,7 +668,7 @@ export default class WebRTCClient extends Emitter {
669
668
 
670
669
  this._onAccepted(session);
671
670
  }).catch(e => {
672
- logger.error(`answer call error for ${session ? session.id : 'n/a'}`, e);
671
+ logger.error(`answer call error for ${this.getSipSessionId(session)}`, e);
673
672
  throw e;
674
673
  });
675
674
  }
@@ -747,7 +746,7 @@ export default class WebRTCClient extends Emitter {
747
746
  async reject(session: WazoSession): Promise<void> {
748
747
  logger.info('sdk webrtc reject call', {
749
748
  clientId: this.clientId,
750
- id: session.id,
749
+ id: this.getSipSessionId(session),
751
750
  });
752
751
 
753
752
  try {
@@ -819,7 +818,7 @@ export default class WebRTCClient extends Emitter {
819
818
 
820
819
  mute(session: WazoSession): void {
821
820
  logger.info('sdk webrtc mute', {
822
- id: session.id,
821
+ id: this.getSipSessionId(session),
823
822
  });
824
823
 
825
824
  this._toggleAudio(session, true);
@@ -827,7 +826,7 @@ export default class WebRTCClient extends Emitter {
827
826
 
828
827
  unmute(session: WazoSession): void {
829
828
  logger.info('sdk webrtc unmute', {
830
- id: session.id,
829
+ id: this.getSipSessionId(session),
831
830
  });
832
831
 
833
832
  this._toggleAudio(session, false);
@@ -872,7 +871,7 @@ export default class WebRTCClient extends Emitter {
872
871
 
873
872
  toggleCameraOn(session: WazoSession): void {
874
873
  logger.info('sdk webrtc toggle camera on', {
875
- id: session.id,
874
+ id: this.getSipSessionId(session),
876
875
  });
877
876
 
878
877
  this._toggleVideo(session, false);
@@ -880,7 +879,7 @@ export default class WebRTCClient extends Emitter {
880
879
 
881
880
  toggleCameraOff(session: WazoSession): void {
882
881
  logger.info('sdk webrtc toggle camera off', {
883
- id: session.id,
882
+ id: this.getSipSessionId(session),
884
883
  });
885
884
 
886
885
  this._toggleVideo(session, true);
@@ -1178,7 +1177,7 @@ export default class WebRTCClient extends Emitter {
1178
1177
  }
1179
1178
 
1180
1179
  logger.info('send WebRTC message', {
1181
- sipId: sipSession.id,
1180
+ sipId: this.getSipSessionId(sipSession),
1182
1181
  contentType,
1183
1182
  });
1184
1183
 
@@ -1611,20 +1610,21 @@ export default class WebRTCClient extends Emitter {
1611
1610
  return '';
1612
1611
  }
1613
1612
 
1614
- const message = sipSession.message as Partial<{ callId?: string }>;
1615
- if (message?.callId) {
1616
- return message.callId.substring(0, SIP_ID_LENGTH);
1617
- }
1618
-
1619
1613
  // For Inviter
1620
1614
  // @ts-ignore: private
1621
1615
  if (sipSession instanceof Inviter && sipSession.outgoingRequestMessage) {
1622
1616
  // @ts-ignore: private
1623
- return sipSession.outgoingRequestMessage.callId.substring(0, SIP_ID_LENGTH);
1617
+ return sipSession.outgoingRequestMessage.callId;
1624
1618
  }
1625
1619
 
1626
1620
  // For Invitation
1627
- return (sipSession.id || '').substring(0, SIP_ID_LENGTH);
1621
+ // @ts-ignore: private
1622
+ if (sipSession instanceof Invitation && sipSession.incomingInviteRequest.message) {
1623
+ // @ts-ignore: private
1624
+ return sipSession.incomingInviteRequest.message.callId;
1625
+ }
1626
+
1627
+ return '';
1628
1628
  }
1629
1629
 
1630
1630
  async waitForRegister(): Promise<void> {
@@ -1704,7 +1704,7 @@ export default class WebRTCClient extends Emitter {
1704
1704
  }
1705
1705
 
1706
1706
  getSipSession(id: string): WazoSession | null | undefined {
1707
- return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_LENGTH)] : null;
1707
+ return id in this.sipSessions ? this.sipSessions[id] : null;
1708
1708
  }
1709
1709
 
1710
1710
  getSipSessionIds(): string[] {
@@ -2168,7 +2168,7 @@ export default class WebRTCClient extends Emitter {
2168
2168
  async _onProgress(session: WazoSession, early = false): Promise<void> {
2169
2169
  await this._setupMedias(session);
2170
2170
 
2171
- const sessionId = this.getSipSessionId(session).substr(0, 20);
2171
+ const sessionId = this.getSipSessionId(session);
2172
2172
  this.updateRemoteStream(sessionId);
2173
2173
  logger.info('progress received', {
2174
2174
  sessionId,
@@ -2179,7 +2179,7 @@ export default class WebRTCClient extends Emitter {
2179
2179
 
2180
2180
  async _onAccepted(session: WazoSession, sessionDialog?: SessionDialog, withEvent = true, initAllTracks = true): Promise<void> {
2181
2181
  logger.info('on call accepted', {
2182
- id: session.id,
2182
+ id: this.getSipSessionId(session),
2183
2183
  clientId: this.clientId,
2184
2184
  remoteTag: session.remoteTag,
2185
2185
  });
@@ -2610,20 +2610,20 @@ export default class WebRTCClient extends Emitter {
2610
2610
  async _accept(session: Invitation, options: InvitationAcceptOptions = {}) {
2611
2611
  if (session.state === SessionState.Terminated || session.state === SessionState.Terminating) {
2612
2612
  const error = 'Trying to accept a terminated sipSession.';
2613
- logger.warn(error, { state: session.state, sessionId: session.id });
2613
+ logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2614
2614
  throw new Error(error);
2615
2615
  }
2616
2616
 
2617
2617
  if (session.state !== SessionState.Initial) {
2618
2618
  const error = 'Trying to accept a non Initial sipSession.';
2619
- logger.warn(error, { state: session.state, sessionId: session.id });
2619
+ logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2620
2620
  throw new Error(error);
2621
2621
  }
2622
2622
 
2623
2623
  // @ts-ignore: private
2624
2624
  if (!session.incomingInviteRequest.acceptable) {
2625
2625
  const error = 'Trying to reject a non `acceptable` session';
2626
- logger.warn(error, { state: session.state, sessionId: session.id });
2626
+ logger.warn(error, { state: session.state, sessionId: this.getSipSessionId(session) });
2627
2627
  throw new Error(error);
2628
2628
  }
2629
2629
 
@@ -2636,13 +2636,13 @@ export default class WebRTCClient extends Emitter {
2636
2636
 
2637
2637
  async _reject(session: Invitation, options: InvitationRejectOptions = {}) {
2638
2638
  if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
2639
- logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: session.id });
2639
+ logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2640
2640
  return;
2641
2641
  }
2642
2642
 
2643
2643
  // @ts-ignore: private
2644
2644
  if (!session.incomingInviteRequest.rejectable) {
2645
- logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: session.id });
2645
+ logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: this.getSipSessionId(session) });
2646
2646
  return;
2647
2647
  }
2648
2648
 
@@ -2655,7 +2655,7 @@ export default class WebRTCClient extends Emitter {
2655
2655
 
2656
2656
  async _cancel(session: Inviter, options: InviterCancelOptions = {}) {
2657
2657
  if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
2658
- logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: session.id });
2658
+ logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2659
2659
  return;
2660
2660
  }
2661
2661
 
@@ -2668,7 +2668,7 @@ export default class WebRTCClient extends Emitter {
2668
2668
 
2669
2669
  async _bye(session: WazoSession, options: SessionByeOptions = {}) {
2670
2670
  if (session.state !== SessionState.Established) {
2671
- logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: session.id });
2671
+ logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: this.getSipSessionId(session) });
2672
2672
  return null;
2673
2673
  }
2674
2674