@wazo/sdk 1.0.0-alpha.1 → 1.0.0-alpha.10

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.
Files changed (148) hide show
  1. package/README.md +16 -7
  2. package/dist/wazo-sdk.js +6 -6
  3. package/esm/__tests__/__voice__/call.test.js +57 -2
  4. package/esm/api/auth.js +3 -0
  5. package/esm/checker/checks/webrtc.js +2 -2
  6. package/esm/domain/CallLog.js +2 -3
  7. package/esm/domain/Phone/CTIPhone.js +2 -2
  8. package/esm/domain/Phone/WebRTCPhone.js +64 -63
  9. package/esm/index.js +3 -1
  10. package/esm/service/CallApi.js +4 -4
  11. package/esm/simple/Auth.js +13 -3
  12. package/esm/simple/Phone.js +6 -5
  13. package/esm/simple/index.js +2 -1
  14. package/esm/simple/room/Room.js +2 -2
  15. package/esm/simple/room/SipRoom.js +2 -2
  16. package/esm/state-machine/call-state-machine.js +2 -2
  17. package/esm/state-machine/softphone-state-machine.js +1 -2
  18. package/esm/state-machine/utils.js +8 -3
  19. package/esm/types/api/auth.d.ts +3 -0
  20. package/esm/types/api/auth.d.ts.map +1 -1
  21. package/esm/types/checker/checks/index.d.ts +1 -1
  22. package/esm/types/checker/checks/webrtc-transport.d.ts +2 -2
  23. package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  24. package/esm/types/domain/CallLog.d.ts.map +1 -1
  25. package/esm/types/domain/CallSession.d.ts +3 -3
  26. package/esm/types/domain/CallSession.d.ts.map +1 -1
  27. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  28. package/esm/types/domain/Phone/WebRTCPhone.d.ts +22 -22
  29. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  30. package/esm/types/domain/types.d.ts +0 -4
  31. package/esm/types/domain/types.d.ts.map +1 -1
  32. package/esm/types/index.d.ts +3 -1
  33. package/esm/types/index.d.ts.map +1 -1
  34. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
  35. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  36. package/esm/types/service/CallApi.d.ts +5 -5
  37. package/esm/types/service/CallApi.d.ts.map +1 -1
  38. package/esm/types/simple/Auth.d.ts +6 -1
  39. package/esm/types/simple/Auth.d.ts.map +1 -1
  40. package/esm/types/simple/Phone.d.ts +8 -8
  41. package/esm/types/simple/Phone.d.ts.map +1 -1
  42. package/esm/types/simple/index.d.ts +3 -1
  43. package/esm/types/simple/index.d.ts.map +1 -1
  44. package/esm/types/state-machine/softphone-state-machine.d.ts +1 -2
  45. package/esm/types/state-machine/softphone-state-machine.d.ts.map +1 -1
  46. package/esm/types/state-machine/utils.d.ts +2 -2
  47. package/esm/types/state-machine/utils.d.ts.map +1 -1
  48. package/esm/types/utils/sdp.d.ts +3 -2
  49. package/esm/types/utils/sdp.d.ts.map +1 -1
  50. package/esm/types/utils/webrtc.d.ts +1 -0
  51. package/esm/types/utils/webrtc.d.ts.map +1 -1
  52. package/esm/types/voice/call.d.ts +30 -12
  53. package/esm/types/voice/call.d.ts.map +1 -1
  54. package/esm/types/voice/softphone.d.ts +25 -13
  55. package/esm/types/voice/softphone.d.ts.map +1 -1
  56. package/esm/types/web-rtc-client.d.ts +39 -38
  57. package/esm/types/web-rtc-client.d.ts.map +1 -1
  58. package/esm/utils/sdp.js +22 -9
  59. package/esm/utils/webrtc.js +23 -3
  60. package/esm/voice/call.js +130 -38
  61. package/esm/voice/softphone.js +145 -35
  62. package/esm/web-rtc-client.js +61 -58
  63. package/lib/__tests__/__voice__/call.test.js +56 -1
  64. package/lib/api/auth.js +3 -0
  65. package/lib/checker/checks/webrtc.js +1 -1
  66. package/lib/domain/CallLog.js +2 -3
  67. package/lib/domain/Phone/CTIPhone.js +2 -2
  68. package/lib/domain/Phone/WebRTCPhone.js +63 -62
  69. package/lib/index.js +7 -3
  70. package/lib/service/CallApi.js +2 -2
  71. package/lib/simple/Auth.js +15 -3
  72. package/lib/simple/Phone.js +3 -2
  73. package/lib/simple/index.js +2 -1
  74. package/lib/simple/room/Room.js +1 -1
  75. package/lib/simple/room/SipRoom.js +1 -1
  76. package/lib/state-machine/call-state-machine.js +2 -2
  77. package/lib/state-machine/softphone-state-machine.js +1 -2
  78. package/lib/state-machine/utils.js +8 -3
  79. package/lib/types/api/auth.d.ts +3 -0
  80. package/lib/types/api/auth.d.ts.map +1 -1
  81. package/lib/types/checker/checks/index.d.ts +1 -1
  82. package/lib/types/checker/checks/webrtc-transport.d.ts +2 -2
  83. package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -1
  84. package/lib/types/domain/CallLog.d.ts.map +1 -1
  85. package/lib/types/domain/CallSession.d.ts +3 -3
  86. package/lib/types/domain/CallSession.d.ts.map +1 -1
  87. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -1
  88. package/lib/types/domain/Phone/WebRTCPhone.d.ts +22 -22
  89. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  90. package/lib/types/domain/types.d.ts +0 -4
  91. package/lib/types/domain/types.d.ts.map +1 -1
  92. package/lib/types/index.d.ts +3 -1
  93. package/lib/types/index.d.ts.map +1 -1
  94. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +3 -3
  95. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -1
  96. package/lib/types/service/CallApi.d.ts +5 -5
  97. package/lib/types/service/CallApi.d.ts.map +1 -1
  98. package/lib/types/simple/Auth.d.ts +6 -1
  99. package/lib/types/simple/Auth.d.ts.map +1 -1
  100. package/lib/types/simple/Phone.d.ts +8 -8
  101. package/lib/types/simple/Phone.d.ts.map +1 -1
  102. package/lib/types/simple/index.d.ts +3 -1
  103. package/lib/types/simple/index.d.ts.map +1 -1
  104. package/lib/types/state-machine/softphone-state-machine.d.ts +1 -2
  105. package/lib/types/state-machine/softphone-state-machine.d.ts.map +1 -1
  106. package/lib/types/state-machine/utils.d.ts +2 -2
  107. package/lib/types/state-machine/utils.d.ts.map +1 -1
  108. package/lib/types/utils/sdp.d.ts +3 -2
  109. package/lib/types/utils/sdp.d.ts.map +1 -1
  110. package/lib/types/utils/webrtc.d.ts +1 -0
  111. package/lib/types/utils/webrtc.d.ts.map +1 -1
  112. package/lib/types/voice/call.d.ts +30 -12
  113. package/lib/types/voice/call.d.ts.map +1 -1
  114. package/lib/types/voice/softphone.d.ts +25 -13
  115. package/lib/types/voice/softphone.d.ts.map +1 -1
  116. package/lib/types/web-rtc-client.d.ts +39 -38
  117. package/lib/types/web-rtc-client.d.ts.map +1 -1
  118. package/lib/utils/sdp.js +25 -10
  119. package/lib/utils/webrtc.js +24 -3
  120. package/lib/voice/call.js +131 -36
  121. package/lib/voice/softphone.js +150 -35
  122. package/lib/web-rtc-client.js +59 -57
  123. package/package.json +1 -1
  124. package/src/__tests__/__voice__/call.test.ts +63 -2
  125. package/src/api/auth.ts +5 -0
  126. package/src/checker/checks/webrtc-transport.ts +2 -2
  127. package/src/checker/checks/webrtc.ts +2 -2
  128. package/src/domain/CallLog.ts +2 -3
  129. package/src/domain/CallSession.ts +3 -3
  130. package/src/domain/Phone/CTIPhone.ts +3 -2
  131. package/src/domain/Phone/WebRTCPhone.ts +95 -93
  132. package/src/domain/types.ts +0 -5
  133. package/src/index.ts +4 -1
  134. package/src/lib/WazoSessionDescriptionHandler.ts +3 -3
  135. package/src/service/CallApi.ts +7 -7
  136. package/src/simple/Auth.ts +15 -3
  137. package/src/simple/Phone.ts +12 -11
  138. package/src/simple/index.ts +2 -1
  139. package/src/simple/room/Room.ts +3 -3
  140. package/src/simple/room/SipRoom.ts +3 -3
  141. package/src/state-machine/call-state-machine.ts +2 -2
  142. package/src/state-machine/softphone-state-machine.ts +1 -2
  143. package/src/state-machine/utils.ts +12 -5
  144. package/src/utils/sdp.ts +26 -11
  145. package/src/utils/webrtc.ts +26 -4
  146. package/src/voice/call.ts +169 -50
  147. package/src/voice/softphone.ts +180 -41
  148. package/src/web-rtc-client.ts +106 -99
@@ -29,9 +29,9 @@ import Emitter from './utils/Emitter';
29
29
  import ApiClient from './api-client';
30
30
  import IssueReporter from './service/IssueReporter';
31
31
  import Heartbeat from './utils/Heartbeat';
32
- import { getSipSessionId, makeURI, replaceLocalIpModifier, SIP_ID_LENGTH } from './utils/sdp';
33
- import type { MediaConfig, UserAgentConfigOverrides, WebRtcConfig, IncomingResponse, PeerConnection, WazoSession, WazoTransport } from './domain/types';
34
- import { cleanupStream, createUaOptions, fetchNetworkStats, getAudioConstraints, getLocalStream, getLocalTracks, getLocalVideoStream, getMediaConfiguration, getPeerConnection, getRemoteStream, getRemoteTracks, getRemoteVideoStream, getRemoteVideoStreamFromPc, getStreamFromConstraints, getVideoConstraints, hasALocalVideoTrack, hasARemoteVideoTrack, hasAVideoTrack, hasLocalVideo, hasRemoteVideo, hasVideoTrack, isAudioOnly, isVideoRemotelyHeld, isWeb, sessionWantsToDoVideo, setLocalMediaStream, toggleAudio, toggleVideo, updateRemoteStream } from './utils/webrtc';
32
+ import { getSipCallId, makeURI, replaceLocalIpModifier } from './utils/sdp';
33
+ import type { MediaConfig, UserAgentConfigOverrides, WebRtcConfig, IncomingResponse, PeerConnection, SipCall, WazoTransport } from './domain/types';
34
+ import { cleanupStream, createUaOptions, fetchNetworkStats, getAudioConstraints, getLocalStream, getLocalTracks, getLocalVideoStream, getMediaConfiguration, getPeerConnection, getRemoteStream, getRemoteTracks, getRemoteVideoStream, getRemoteVideoStreamFromPc, getVideoConstraints, hasALocalVideoTrack, hasARemoteVideoTrack, hasAVideoTrack, hasLocalVideo, hasRemoteVideo, hasVideoTrack, isAudioOnly, isVideoRemotelyHeld, isWeb, sessionWantsToDoVideo, setLocalMediaStream, toggleAudio, toggleVideo, updateRemoteStream } from './utils/webrtc';
35
35
 
36
36
  const SEND_STATS_DELAY = 5000;
37
37
  const states = ['STATUS_NULL', 'STATUS_NEW', 'STATUS_CONNECTING', 'STATUS_CONNECTED', 'STATUS_COMPLETED'];
@@ -39,6 +39,7 @@ const logger = IssueReporter ? IssueReporter.loggerFor('webrtc-client') : consol
39
39
  const statsLogger = IssueReporter ? IssueReporter.loggerFor('webrtc-stats') : console;
40
40
  // events
41
41
  const REGISTERED = 'registered';
42
+ const REGISTERING = 'registering';
42
43
  const UNREGISTERED = 'unregistered';
43
44
  const REGISTRATION_FAILED = 'registrationFailed';
44
45
  const INVITE = 'invite';
@@ -57,7 +58,7 @@ const ON_SCREEN_SHARING_REINVITE = 'onScreenSharingReinvite';
57
58
  const ON_NETWORK_STATS = 'onNetworkStats';
58
59
  const ON_DISCONNECTED = 'onDisconnected';
59
60
 
60
- export const events = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
61
+ export const events = [REGISTERED, REGISTERING, UNREGISTERED, REGISTRATION_FAILED, INVITE];
61
62
  export const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
62
63
  export class CanceledCallError extends Error {}
63
64
 
@@ -102,7 +103,7 @@ export default class WebRTCClient extends Emitter {
102
103
 
103
104
  statsIntervals: Record<string, any>;
104
105
 
105
- sipSessions: Record<string, WazoSession>;
106
+ sipSessions: Record<string, SipCall>;
106
107
 
107
108
  conferences: Record<string, boolean>;
108
109
 
@@ -119,6 +120,8 @@ export default class WebRTCClient extends Emitter {
119
120
 
120
121
  REGISTERED: string;
121
122
 
123
+ REGISTERING: string;
124
+
122
125
  UNREGISTERED: string;
123
126
 
124
127
  REGISTRATION_FAILED: string;
@@ -153,7 +156,7 @@ export default class WebRTCClient extends Emitter {
153
156
 
154
157
  ON_DISCONNECTED: string;
155
158
 
156
- constructor(config: WebRtcConfig, session?: WazoSession, uaConfigOverrides?: UserAgentConfigOverrides) {
159
+ constructor(config: WebRtcConfig, session?: SipCall, uaConfigOverrides?: UserAgentConfigOverrides) {
157
160
  super();
158
161
 
159
162
  // For debug purpose
@@ -166,7 +169,9 @@ export default class WebRTCClient extends Emitter {
166
169
 
167
170
  this._buildConfig(config, session).then((newConfig: WebRtcConfig) => {
168
171
  this.config = newConfig;
169
- this.userAgent = this.createUserAgent(uaConfigOverrides);
172
+ if (!this.userAgent) {
173
+ this.userAgent = this.createUserAgent(uaConfigOverrides);
174
+ }
170
175
  });
171
176
 
172
177
  this.audioOutputDeviceId = config.audioDeviceOutput;
@@ -194,6 +199,7 @@ export default class WebRTCClient extends Emitter {
194
199
  this.heartbeat.setOnHeartbeatTimeout(this._onHeartbeatTimeout.bind(this));
195
200
  // sugar
196
201
  this.REGISTERED = REGISTERED;
202
+ this.REGISTERING = REGISTERING;
197
203
  this.UNREGISTERED = UNREGISTERED;
198
204
  this.REGISTRATION_FAILED = REGISTRATION_FAILED;
199
205
  this.INVITE = INVITE;
@@ -239,7 +245,7 @@ export default class WebRTCClient extends Emitter {
239
245
  logger.info('sdk webrtc on invite', {
240
246
  method: 'delegate.onInvite',
241
247
  clientId: this.clientId,
242
- id: invitation.id,
248
+ id: getSipCallId(invitation),
243
249
  remoteURI: (invitation as any).remoteURI,
244
250
  });
245
251
 
@@ -316,7 +322,7 @@ export default class WebRTCClient extends Emitter {
316
322
  this.registerer.waitingToggle(false);
317
323
  }
318
324
 
319
- this.eventEmitter.emit(UNREGISTERED);
325
+ this.eventEmitter.emit(UNREGISTERED, error);
320
326
  }
321
327
  }
322
328
 
@@ -341,6 +347,8 @@ export default class WebRTCClient extends Emitter {
341
347
 
342
348
  logger.info('sdk webrtc registering...', logInfo);
343
349
 
350
+ this.eventEmitter.emit(REGISTERING);
351
+
344
352
  if (!this.userAgent) {
345
353
  logger.info('sdk webrtc recreating User Agent');
346
354
  this.userAgent = this.createUserAgent(this.uaConfigOverrides);
@@ -521,7 +529,7 @@ export default class WebRTCClient extends Emitter {
521
529
  });
522
530
  }
523
531
 
524
- call(number: string, enableVideo?: boolean, audioOnly = false, conference = false, options = {}): WazoSession | null {
532
+ call(number: string, enableVideo?: boolean, audioOnly = false, conference = false, options = {}): SipCall | null {
525
533
  logger.info('sdk webrtc creating call', {
526
534
  clientId: this.clientId,
527
535
  number,
@@ -544,7 +552,7 @@ export default class WebRTCClient extends Emitter {
544
552
  }
545
553
 
546
554
  const uri = makeURI(number, this.config.host);
547
- let session: WazoSession | null = null;
555
+ let session: SipCall | null = null;
548
556
 
549
557
  if (uri) {
550
558
  session = this.userAgent ? new Inviter(this.userAgent, uri, inviterOptions) : null;
@@ -559,7 +567,7 @@ export default class WebRTCClient extends Emitter {
559
567
  }
560
568
 
561
569
  if (conference) {
562
- this.conferences[getSipSessionId(session)] = true;
570
+ this.conferences[getSipCallId(session)] = true;
563
571
  }
564
572
 
565
573
  const inviteOptions: InviterInviteOptions = {
@@ -568,21 +576,21 @@ export default class WebRTCClient extends Emitter {
568
576
  if ((session?.sessionDescriptionHandler as any)?.peerConnection) {
569
577
  (session?.sessionDescriptionHandler as any).peerConnection.sfu = conference;
570
578
  }
571
- this._onAccepted(session as WazoSession, response.session, true);
579
+ this._onAccepted(session as SipCall, response.session, true);
572
580
  },
573
581
  onProgress: (payload: IncomingResponse) => {
574
582
  this._onProgress(payload.session, payload.message.statusCode === 183);
575
583
  },
576
584
  onReject: (response: IncomingResponse) => {
577
585
  logger.info('on call rejected', {
578
- id: session?.id,
586
+ id: getSipCallId(session),
579
587
  // @ts-ignore: fromTag does not exist
580
588
  fromTag: session?.fromTag,
581
589
  });
582
590
 
583
- this._stopSendingStats(session as WazoSession);
591
+ this._stopSendingStats(session as SipCall);
584
592
 
585
- this.stopNetworkMonitoring(session as WazoSession);
593
+ this.stopNetworkMonitoring(session as SipCall);
586
594
  this.eventEmitter.emit(REJECTED, session, response);
587
595
  },
588
596
  },
@@ -612,7 +620,7 @@ export default class WebRTCClient extends Emitter {
612
620
  answer(session: Invitation, enableVideo?: boolean): Promise<void> {
613
621
  logger.info('sdk webrtc answer call', {
614
622
  clientId: this.clientId,
615
- id: session.id,
623
+ id: getSipCallId(session),
616
624
  enableVideo,
617
625
  });
618
626
 
@@ -630,7 +638,7 @@ export default class WebRTCClient extends Emitter {
630
638
  if (session.isCanceled) {
631
639
  const message = 'accepted a canceled session (or was canceled during the accept phase).';
632
640
  logger.error(message, {
633
- id: session.id,
641
+ id: getSipCallId(session),
634
642
  });
635
643
  this.onCallEnded(session);
636
644
  throw new CanceledCallError(message);
@@ -640,12 +648,12 @@ export default class WebRTCClient extends Emitter {
640
648
 
641
649
  this._onAccepted(session);
642
650
  }).catch(e => {
643
- logger.error(`answer call error for ${session ? session.id : 'n/a'}`, e);
651
+ logger.error(`answer call error for ${getSipCallId(session)}`, e);
644
652
  throw e;
645
653
  });
646
654
  }
647
655
 
648
- async hangup(session: WazoSession): Promise<OutgoingByeRequest | null> {
656
+ async hangup(session: SipCall): Promise<OutgoingByeRequest | null> {
649
657
  const { state, id } = session;
650
658
  logger.info('sdk webrtc hangup call', { clientId: this.clientId, id, state });
651
659
 
@@ -654,7 +662,7 @@ export default class WebRTCClient extends Emitter {
654
662
 
655
663
  this._cleanupMedia(session);
656
664
 
657
- delete this.sipSessions[getSipSessionId(session)];
665
+ delete this.sipSessions[getSipCallId(session)];
658
666
  // Check if Invitation or Inviter (Invitation = incoming call)
659
667
  const isInviter = session instanceof Inviter;
660
668
 
@@ -679,8 +687,8 @@ export default class WebRTCClient extends Emitter {
679
687
  }
680
688
 
681
689
  // Fetch and emit an event at `interval` with session network stats
682
- startNetworkMonitoring(session: WazoSession, interval = 1000): void {
683
- const sessionId = getSipSessionId(session);
690
+ startNetworkMonitoring(session: SipCall, interval = 1000): void {
691
+ const sessionId = getSipCallId(session);
684
692
  logger.info('starting network inspection', {
685
693
  id: sessionId,
686
694
  clientId: this.clientId,
@@ -689,8 +697,8 @@ export default class WebRTCClient extends Emitter {
689
697
  this.networkMonitoringInterval[sessionId] = setInterval(() => this._fetchNetworkStats(sessionId), interval);
690
698
  }
691
699
 
692
- stopNetworkMonitoring(session: WazoSession): void {
693
- const sessionId = getSipSessionId(session);
700
+ stopNetworkMonitoring(session: SipCall): void {
701
+ const sessionId = getSipCallId(session);
694
702
  const exists = (sessionId in this.networkMonitoringInterval);
695
703
  logger.info('stopping network inspection', {
696
704
  clientId: this.clientId,
@@ -705,10 +713,10 @@ export default class WebRTCClient extends Emitter {
705
713
  }
706
714
  }
707
715
 
708
- async reject(session: WazoSession): Promise<void> {
716
+ async reject(session: SipCall): Promise<void> {
709
717
  logger.info('sdk webrtc reject call', {
710
718
  clientId: this.clientId,
711
- id: session.id,
719
+ id: getSipCallId(session),
712
720
  });
713
721
 
714
722
  try {
@@ -769,23 +777,23 @@ export default class WebRTCClient extends Emitter {
769
777
  logger.info('sdk webrtc client closed', { clientId: this.clientId });
770
778
  }
771
779
 
772
- mute(session: WazoSession): void {
780
+ mute(session: SipCall): void {
773
781
  logger.info('sdk webrtc mute', {
774
- id: session.id,
782
+ id: getSipCallId(session),
775
783
  });
776
784
 
777
785
  toggleAudio(session, true);
778
786
  }
779
787
 
780
- unmute(session: WazoSession): void {
788
+ unmute(session: SipCall): void {
781
789
  logger.info('sdk webrtc unmute', {
782
- id: session.id,
790
+ id: getSipCallId(session),
783
791
  });
784
792
 
785
793
  toggleAudio(session, false);
786
794
  }
787
795
 
788
- isAudioMuted(session: WazoSession): boolean {
796
+ isAudioMuted(session: SipCall): boolean {
789
797
  if (!session || !session.sessionDescriptionHandler) {
790
798
  return false;
791
799
  }
@@ -822,24 +830,24 @@ export default class WebRTCClient extends Emitter {
822
830
  return muted;
823
831
  }
824
832
 
825
- toggleCameraOn(session: WazoSession): void {
833
+ toggleCameraOn(session: SipCall): void {
826
834
  logger.info('sdk webrtc toggle camera on', {
827
- id: session.id,
835
+ id: getSipCallId(session),
828
836
  });
829
837
 
830
838
  toggleVideo(session, false);
831
839
  }
832
840
 
833
- toggleCameraOff(session: WazoSession): void {
841
+ toggleCameraOff(session: SipCall): void {
834
842
  logger.info('sdk webrtc toggle camera off', {
835
- id: session.id,
843
+ id: getSipCallId(session),
836
844
  });
837
845
 
838
846
  toggleVideo(session, true);
839
847
  }
840
848
 
841
- hold(session: WazoSession, isConference = false, hadVideo = false): Promise<OutgoingInviteRequest | void> {
842
- const sessionId = getSipSessionId(session);
849
+ hold(session: SipCall, isConference = false, hadVideo = false): Promise<OutgoingInviteRequest | void> {
850
+ const sessionId = getSipCallId(session);
843
851
  const hasVideo = hadVideo || this.hasLocalVideo(sessionId);
844
852
  logger.info('sdk webrtc hold', {
845
853
  sessionId,
@@ -896,8 +904,8 @@ export default class WebRTCClient extends Emitter {
896
904
  });
897
905
  }
898
906
 
899
- unhold(session: WazoSession, isConference = false): Promise<OutgoingInviteRequest | void> {
900
- const sessionId = getSipSessionId(session);
907
+ unhold(session: SipCall, isConference = false): Promise<OutgoingInviteRequest | void> {
908
+ const sessionId = getSipCallId(session);
901
909
  const hasVideo = sessionId in this.heldSessions && this.heldSessions[sessionId].hasVideo;
902
910
  logger.info('sdk webrtc unhold', {
903
911
  sessionId,
@@ -915,7 +923,7 @@ export default class WebRTCClient extends Emitter {
915
923
 
916
924
  this.unmute(session);
917
925
 
918
- delete this.heldSessions[getSipSessionId(session)];
926
+ delete this.heldSessions[getSipCallId(session)];
919
927
  session.sessionDescriptionHandlerOptionsReInvite = {
920
928
  hold: false,
921
929
  conference: isConference,
@@ -943,21 +951,21 @@ export default class WebRTCClient extends Emitter {
943
951
  return this.heldSessions[sessionId];
944
952
  }
945
953
 
946
- isCallHeld(session: WazoSession): boolean {
947
- return getSipSessionId(session) in this.heldSessions;
954
+ isCallHeld(session: SipCall): boolean {
955
+ return getSipCallId(session) in this.heldSessions;
948
956
  }
949
957
 
950
958
  isVideoRemotelyHeld(sessionId: string): boolean {
951
959
  return isVideoRemotelyHeld(this.heldSessions[sessionId]);
952
960
  }
953
961
 
954
- sendDTMF(session: WazoSession, tone: string): boolean {
962
+ sendDTMF(session: SipCall, tone: string): boolean {
955
963
  if (!session.sessionDescriptionHandler) {
956
964
  return false;
957
965
  }
958
966
 
959
967
  logger.info('Sending DTMF', {
960
- id: getSipSessionId(session),
968
+ id: getSipCallId(session),
961
969
  tone,
962
970
  });
963
971
  return session.sessionDescriptionHandler.sendDtmf(tone);
@@ -973,10 +981,10 @@ export default class WebRTCClient extends Emitter {
973
981
  messager.message();
974
982
  }
975
983
 
976
- transfer(session: WazoSession, target: string): void {
984
+ transfer(session: SipCall, target: string): void {
977
985
  this.hold(session);
978
986
  logger.info('Transfering a session', {
979
- id: getSipSessionId(session),
987
+ id: getSipCallId(session),
980
988
  target,
981
989
  });
982
990
  const options = {
@@ -997,24 +1005,24 @@ export default class WebRTCClient extends Emitter {
997
1005
  }
998
1006
 
999
1007
  // check https://sipjs.com/api/0.12.0/refer/referClientContext/
1000
- atxfer(session: WazoSession): Record<string, any> {
1008
+ atxfer(session: SipCall): Record<string, any> {
1001
1009
  this.hold(session);
1002
1010
  logger.info('webrtc transfer started', {
1003
- id: getSipSessionId(session),
1011
+ id: getSipCallId(session),
1004
1012
  });
1005
1013
  const result: Record<string, any> = {
1006
1014
  newSession: null,
1007
1015
  init: async (target: string) => {
1008
1016
  logger.info('webrtc transfer initialized', {
1009
- id: getSipSessionId(session),
1017
+ id: getSipCallId(session),
1010
1018
  target,
1011
1019
  });
1012
1020
  result.newSession = await this.call(target);
1013
1021
  },
1014
1022
  complete: () => {
1015
1023
  logger.info('webrtc transfer completed', {
1016
- id: getSipSessionId(session),
1017
- referId: getSipSessionId(result.newSession),
1024
+ id: getSipCallId(session),
1025
+ referId: getSipCallId(result.newSession),
1018
1026
  });
1019
1027
  session.refer(result.newSession);
1020
1028
  },
@@ -1027,13 +1035,13 @@ export default class WebRTCClient extends Emitter {
1027
1035
  }
1028
1036
 
1029
1037
  // eslint-disable-next-line @typescript-eslint/default-param-last
1030
- sendMessage(sipSession: WazoSession | null = null, body: string, contentType = 'text/plain'): void {
1038
+ sendMessage(sipSession: SipCall | null = null, body: string, contentType = 'text/plain'): void {
1031
1039
  if (!sipSession) {
1032
1040
  return;
1033
1041
  }
1034
1042
 
1035
1043
  logger.info('send WebRTC message', {
1036
- sipId: sipSession.id,
1044
+ sipId: getSipCallId(sipSession),
1037
1045
  contentType,
1038
1046
  });
1039
1047
 
@@ -1107,7 +1115,7 @@ export default class WebRTCClient extends Emitter {
1107
1115
  await Promise.allSettled(promises);
1108
1116
  }
1109
1117
 
1110
- async changeAudioInputDevice(id: string, session: WazoSession | null | undefined, force?: boolean): Promise<MediaStream | null> {
1118
+ async changeAudioInputDevice(id: string, session: SipCall | null | undefined, force?: boolean): Promise<MediaStream | null> {
1111
1119
  const currentId = this.getAudioDeviceId();
1112
1120
  logger.info('setting audio input device', {
1113
1121
  id,
@@ -1178,7 +1186,7 @@ export default class WebRTCClient extends Emitter {
1178
1186
  return null;
1179
1187
  }
1180
1188
 
1181
- async changeVideoInputDevice(id: string, session?: WazoSession): Promise<MediaStream | void> {
1189
+ async changeVideoInputDevice(id: string, session?: SipCall): Promise<MediaStream | void> {
1182
1190
  this.setVideoInputDevice(id);
1183
1191
 
1184
1192
  if (session) {
@@ -1206,14 +1214,14 @@ export default class WebRTCClient extends Emitter {
1206
1214
  };
1207
1215
  }
1208
1216
 
1209
- changeSessionVideoInputDevice(id: string | null | undefined, session: WazoSession): Promise<MediaStream | void> {
1217
+ changeSessionVideoInputDevice(id: string | null | undefined, session: SipCall): Promise<MediaStream | void> {
1210
1218
  if (!sessionWantsToDoVideo(session)) {
1211
1219
  return Promise.resolve();
1212
1220
  }
1213
1221
 
1214
1222
  const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
1215
1223
  const pc = sdh.peerConnection;
1216
- const sessionId = getSipSessionId(session);
1224
+ const sessionId = getSipCallId(session);
1217
1225
  const localStream = this.getLocalStream(sessionId);
1218
1226
  logger.info('changing video input device', {
1219
1227
  id,
@@ -1270,7 +1278,7 @@ export default class WebRTCClient extends Emitter {
1270
1278
  return this.video && typeof this.video === 'object' && 'deviceId' in this.video ? (this.video.deviceId as any)?.exact : undefined;
1271
1279
  }
1272
1280
 
1273
- reinvite(sipSession: WazoSession, newConstraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
1281
+ reinvite(sipSession: SipCall, newConstraints: Record<string, any> | null | undefined = null, conference = false, audioOnly = false, iceRestart = false): Promise<OutgoingInviteRequest | void> {
1274
1282
  if (!sipSession) {
1275
1283
  return Promise.resolve();
1276
1284
  }
@@ -1286,7 +1294,7 @@ export default class WebRTCClient extends Emitter {
1286
1294
  const desktop = newConstraints && newConstraints.desktop;
1287
1295
  logger.info('Sending reinvite', {
1288
1296
  clientId: this.clientId,
1289
- id: getSipSessionId(sipSession),
1297
+ id: getSipCallId(sipSession),
1290
1298
  newConstraints,
1291
1299
  conference,
1292
1300
  audioOnly,
@@ -1324,7 +1332,7 @@ export default class WebRTCClient extends Emitter {
1324
1332
  }
1325
1333
 
1326
1334
  logger.info('on re-INVITE accepted', {
1327
- id: getSipSessionId(sipSession),
1335
+ id: getSipCallId(sipSession),
1328
1336
  wasMuted,
1329
1337
  shouldDoScreenSharing,
1330
1338
  });
@@ -1461,10 +1469,10 @@ export default class WebRTCClient extends Emitter {
1461
1469
  this.heartbeatCb = cb;
1462
1470
  }
1463
1471
 
1464
- onCallEnded(session: WazoSession): void {
1472
+ onCallEnded(session: SipCall): void {
1465
1473
  this._cleanupMedia(session);
1466
1474
 
1467
- delete this.sipSessions[getSipSessionId(session)];
1475
+ delete this.sipSessions[getSipCallId(session)];
1468
1476
 
1469
1477
  this._stopSendingStats(session);
1470
1478
 
@@ -1482,18 +1490,18 @@ export default class WebRTCClient extends Emitter {
1482
1490
  this.userAgent.attemptReconnection();
1483
1491
  }
1484
1492
 
1485
- storeSipSession(session: WazoSession): void {
1486
- const id = getSipSessionId(session);
1493
+ storeSipSession(session: SipCall): void {
1494
+ const id = getSipCallId(session);
1487
1495
  logger.info('storing sip session', { id, clientId: this.clientId });
1488
1496
 
1489
1497
  this.sipSessions[id] = session;
1490
1498
  }
1491
1499
 
1492
- getSipSession(id: string): WazoSession | null | undefined {
1493
- return id in this.sipSessions ? this.sipSessions[id.substring(0, SIP_ID_LENGTH)] : null;
1500
+ getSipSession(id: string): SipCall | null | undefined {
1501
+ return id in this.sipSessions ? this.sipSessions[id] : null;
1494
1502
  }
1495
1503
 
1496
- getSipSessionIds(): string[] {
1504
+ getSipCallIds(): string[] {
1497
1505
  return Object.keys(this.sipSessions);
1498
1506
  }
1499
1507
 
@@ -1545,8 +1553,8 @@ export default class WebRTCClient extends Emitter {
1545
1553
  return audio;
1546
1554
  }
1547
1555
 
1548
- _onTransportError(): void {
1549
- logger.error('on transport error');
1556
+ _onTransportError(reason?: string): void {
1557
+ logger.warn('on transport error', { reason });
1550
1558
  this.eventEmitter.emit(TRANSPORT_ERROR);
1551
1559
  this.attemptReconnection();
1552
1560
  }
@@ -1608,7 +1616,7 @@ export default class WebRTCClient extends Emitter {
1608
1616
  }
1609
1617
 
1610
1618
  // We can invoke disconnect() with an error that can be catcher by `onDisconnect`, so we have to trigger it here.
1611
- this._onTransportError();
1619
+ this._onTransportError('heartbeat timeout');
1612
1620
  }
1613
1621
  }
1614
1622
 
@@ -1664,7 +1672,7 @@ export default class WebRTCClient extends Emitter {
1664
1672
  return this.connectionPromise;
1665
1673
  }
1666
1674
 
1667
- _buildConfig(config: WebRtcConfig, session: WazoSession | null | undefined): Promise<WebRtcConfig> {
1675
+ _buildConfig(config: WebRtcConfig, session: SipCall | null | undefined): Promise<WebRtcConfig> {
1668
1676
  // If no session provided, return the configuration directly
1669
1677
  if (!session) {
1670
1678
  return new Promise(resolve => resolve(config));
@@ -1685,8 +1693,8 @@ export default class WebRTCClient extends Emitter {
1685
1693
  }
1686
1694
 
1687
1695
  // Invitation and Inviter extends Session
1688
- _setupSession(session: WazoSession): void {
1689
- const sipSessionId = getSipSessionId(session);
1696
+ _setupSession(session: SipCall): void {
1697
+ const sipSessionId = getSipCallId(session);
1690
1698
 
1691
1699
  // When receiving an Invitation, the delegate is not defined.
1692
1700
  if (!session.delegate) {
@@ -1758,21 +1766,20 @@ export default class WebRTCClient extends Emitter {
1758
1766
  };
1759
1767
  }
1760
1768
 
1761
- async _onProgress(session: WazoSession, early = false): Promise<void> {
1769
+ async _onProgress(session: SipCall, early = false): Promise<void> {
1762
1770
  await this._setupMedias(session);
1763
1771
 
1764
- const sessionId = getSipSessionId(session).substr(0, 20);
1772
+ const sessionId = getSipCallId(session);
1773
+
1765
1774
  updateRemoteStream(session);
1766
- logger.info('progress received', {
1767
- sessionId,
1768
- early,
1769
- });
1775
+
1776
+ logger.info('progress received', { sessionId, early });
1770
1777
  this.eventEmitter.emit(early ? ON_EARLY_MEDIA : ON_PROGRESS, session);
1771
1778
  }
1772
1779
 
1773
- async _onAccepted(session: WazoSession, sessionDialog?: SessionDialog, withEvent = true, initAllTracks = true): Promise<void> {
1780
+ async _onAccepted(session: SipCall, sessionDialog?: SessionDialog, withEvent = true, initAllTracks = true): Promise<void> {
1774
1781
  logger.info('on call accepted', {
1775
- id: session.id,
1782
+ id: getSipCallId(session),
1776
1783
  clientId: this.clientId,
1777
1784
  remoteTag: session.remoteTag,
1778
1785
  });
@@ -1822,14 +1829,14 @@ export default class WebRTCClient extends Emitter {
1822
1829
  this._startSendingStats(session);
1823
1830
  }
1824
1831
 
1825
- async _setupMedias(session: WazoSession, newStream: MediaStream | null | undefined = null): Promise<void> {
1832
+ async _setupMedias(session: SipCall, newStream: MediaStream | null | undefined = null): Promise<void> {
1826
1833
  if (!isWeb()) {
1827
1834
  logger.info('Setup media on mobile, no need to setup html element, bailing');
1828
1835
  return;
1829
1836
  }
1830
1837
 
1831
1838
  // Safari hack, because you cannot call .play() from a non user action
1832
- const sessionId = getSipSessionId(session);
1839
+ const sessionId = getSipCallId(session);
1833
1840
  const isConference = this.isConference(sessionId);
1834
1841
 
1835
1842
  if (sessionId in this.audioElements) {
@@ -1883,8 +1890,8 @@ export default class WebRTCClient extends Emitter {
1883
1890
  audioElement.play().catch(() => {});
1884
1891
  }
1885
1892
 
1886
- _cleanupMedia(session?: WazoSession): void {
1887
- const sessionId = getSipSessionId(session);
1893
+ _cleanupMedia(session?: SipCall): void {
1894
+ const sessionId = getSipCallId(session);
1888
1895
  const localStream = this.getLocalStream(sessionId);
1889
1896
 
1890
1897
  if (localStream) {
@@ -1910,7 +1917,7 @@ export default class WebRTCClient extends Emitter {
1910
1917
 
1911
1918
  if (this._hasAudio() && isWeb()) {
1912
1919
  if (session) {
1913
- cleanLocalElement(getSipSessionId(session));
1920
+ cleanLocalElement(getSipCallId(session));
1914
1921
  } else {
1915
1922
  Object.keys(this.audioElements).forEach(id => cleanLocalElement(id));
1916
1923
  }
@@ -1925,7 +1932,7 @@ export default class WebRTCClient extends Emitter {
1925
1932
  }
1926
1933
  }
1927
1934
 
1928
- _startSendingStats(session: WazoSession): void {
1935
+ _startSendingStats(session: SipCall): void {
1929
1936
  const sdh = session.sessionDescriptionHandler as SessionDescriptionHandler;
1930
1937
  const pc = sdh.peerConnection;
1931
1938
 
@@ -1933,7 +1940,7 @@ export default class WebRTCClient extends Emitter {
1933
1940
  return;
1934
1941
  }
1935
1942
 
1936
- const sessionId = getSipSessionId(session);
1943
+ const sessionId = getSipCallId(session);
1937
1944
  getStats(pc, (result: Record<string, any>) => {
1938
1945
  const {
1939
1946
  results,
@@ -1949,8 +1956,8 @@ export default class WebRTCClient extends Emitter {
1949
1956
  }, SEND_STATS_DELAY);
1950
1957
  }
1951
1958
 
1952
- _stopSendingStats(session: WazoSession): void {
1953
- const sessionId = getSipSessionId(session);
1959
+ _stopSendingStats(session: SipCall): void {
1960
+ const sessionId = getSipCallId(session);
1954
1961
  logger.trace('Check for stopping stats', {
1955
1962
  sessionId,
1956
1963
  ids: Object.keys(this.statsIntervals),
@@ -2010,20 +2017,20 @@ export default class WebRTCClient extends Emitter {
2010
2017
  async _accept(session: Invitation, options: InvitationAcceptOptions = {}) {
2011
2018
  if (session.state === SessionState.Terminated || session.state === SessionState.Terminating) {
2012
2019
  const error = 'Trying to accept a terminated sipSession.';
2013
- logger.warn(error, { state: session.state, sessionId: session.id });
2020
+ logger.warn(error, { state: session.state, sessionId: getSipCallId(session) });
2014
2021
  throw new Error(error);
2015
2022
  }
2016
2023
 
2017
2024
  if (session.state !== SessionState.Initial) {
2018
2025
  const error = 'Trying to accept a non Initial sipSession.';
2019
- logger.warn(error, { state: session.state, sessionId: session.id });
2026
+ logger.warn(error, { state: session.state, sessionId: getSipCallId(session) });
2020
2027
  throw new Error(error);
2021
2028
  }
2022
2029
 
2023
2030
  // @ts-ignore: private
2024
2031
  if (!session.incomingInviteRequest.acceptable) {
2025
2032
  const error = 'Trying to reject a non `acceptable` session';
2026
- logger.warn(error, { state: session.state, sessionId: session.id });
2033
+ logger.warn(error, { state: session.state, sessionId: getSipCallId(session) });
2027
2034
  throw new Error(error);
2028
2035
  }
2029
2036
 
@@ -2036,13 +2043,13 @@ export default class WebRTCClient extends Emitter {
2036
2043
 
2037
2044
  async _reject(session: Invitation, options: InvitationRejectOptions = {}) {
2038
2045
  if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
2039
- logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: session.id });
2046
+ logger.warn('Trying to reject a session in a wrong state', { state: session.state, sessionId: getSipCallId(session) });
2040
2047
  return;
2041
2048
  }
2042
2049
 
2043
2050
  // @ts-ignore: private
2044
2051
  if (!session.incomingInviteRequest.rejectable) {
2045
- logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: session.id });
2052
+ logger.warn('Trying to reject a non `rejectable` session', { state: session.state, sessionId: getSipCallId(session) });
2046
2053
  return;
2047
2054
  }
2048
2055
 
@@ -2055,7 +2062,7 @@ export default class WebRTCClient extends Emitter {
2055
2062
 
2056
2063
  async _cancel(session: Inviter, options: InviterCancelOptions = {}) {
2057
2064
  if (session.state !== SessionState.Initial && session.state !== SessionState.Establishing) {
2058
- logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: session.id });
2065
+ logger.warn('Trying to cancel a session in a wrong state', { state: session.state, sessionId: getSipCallId(session) });
2059
2066
  return;
2060
2067
  }
2061
2068
 
@@ -2066,9 +2073,9 @@ export default class WebRTCClient extends Emitter {
2066
2073
  }
2067
2074
  }
2068
2075
 
2069
- async _bye(session: WazoSession, options: SessionByeOptions = {}) {
2076
+ async _bye(session: SipCall, options: SessionByeOptions = {}) {
2070
2077
  if (session.state !== SessionState.Established) {
2071
- logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: session.id });
2078
+ logger.warn('Trying to end a session in a wrong state', { state: session.state, sessionId: getSipCallId(session) });
2072
2079
  return null;
2073
2080
  }
2074
2081