@wazo/sdk 0.37.33 → 0.37.36

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 (98) hide show
  1. package/README.md +1 -0
  2. package/dist/wazo-sdk.js +2 -2
  3. package/esm/__tests__/api-client.test.js +17 -0
  4. package/esm/__tests__/web-rtc-client.test.js +18 -1
  5. package/esm/api/auth.js +5 -0
  6. package/esm/api/call-logd.js +6 -0
  7. package/esm/api/chatd.js +6 -0
  8. package/esm/api/confd.js +6 -0
  9. package/esm/api-client.js +17 -0
  10. package/esm/checker/Checker.js +18 -1
  11. package/esm/checker/checks/aor.js +17 -0
  12. package/esm/checker/checks/api.js +17 -0
  13. package/esm/checker/checks/index.js +18 -1
  14. package/esm/checker/checks/webrtc-transport.js +18 -1
  15. package/esm/checker/checks/webrtc.js +18 -1
  16. package/esm/domain/AdHocAPIConference.js +21 -0
  17. package/esm/domain/CallLog.js +6 -0
  18. package/esm/domain/CallSession.js +14 -0
  19. package/esm/domain/Features.js +17 -0
  20. package/esm/domain/Phone/CTIPhone.js +31 -0
  21. package/esm/domain/Phone/WebRTCPhone.js +65 -15
  22. package/esm/domain/Profile.js +6 -0
  23. package/esm/domain/__tests__/CallLog.test.js +10 -0
  24. package/esm/domain/__tests__/CallSession.test.js +14 -0
  25. package/esm/domain/__tests__/IndirectTransfer.test.js +14 -0
  26. package/esm/domain/__tests__/Profile.test.js +6 -0
  27. package/esm/domain/__tests__/Room.test.js +14 -0
  28. package/esm/domain/__tests__/Session.test.js +6 -0
  29. package/esm/index.js +93 -22
  30. package/esm/service/CallApi.js +17 -0
  31. package/esm/service/getApiClient.js +17 -0
  32. package/esm/simple/Auth.js +93 -22
  33. package/esm/simple/Configuration.js +93 -22
  34. package/esm/simple/Directory.js +17 -0
  35. package/esm/simple/Phone.js +93 -22
  36. package/esm/simple/index.js +93 -22
  37. package/esm/simple/room/LocalParticipant.js +93 -22
  38. package/esm/simple/room/Participant.js +93 -22
  39. package/esm/simple/room/RemoteParticipant.js +93 -22
  40. package/esm/simple/room/Room.js +93 -22
  41. package/esm/simple/room/SipRoom.js +93 -22
  42. package/esm/simple/room/Stream.js +93 -22
  43. package/esm/simple/room/__tests__/RemoteParticipant.test.js +93 -22
  44. package/esm/simple/utils.js +93 -22
  45. package/esm/web-rtc-client.js +18 -1
  46. package/lib/__tests__/api-client.test.js +17 -0
  47. package/lib/__tests__/web-rtc-client.test.js +18 -1
  48. package/lib/api/auth.js +5 -0
  49. package/lib/api/call-logd.js +6 -0
  50. package/lib/api/chatd.js +6 -0
  51. package/lib/api/confd.js +6 -0
  52. package/lib/api-client.js +17 -0
  53. package/lib/checker/Checker.js +18 -1
  54. package/lib/checker/checks/aor.js +17 -0
  55. package/lib/checker/checks/api.js +17 -0
  56. package/lib/checker/checks/index.js +18 -1
  57. package/lib/checker/checks/webrtc-transport.js +18 -1
  58. package/lib/checker/checks/webrtc.js +18 -1
  59. package/lib/domain/AdHocAPIConference.js +21 -0
  60. package/lib/domain/CallLog.js +6 -0
  61. package/lib/domain/CallSession.js +14 -0
  62. package/lib/domain/Features.js +17 -0
  63. package/lib/domain/Phone/CTIPhone.js +31 -0
  64. package/lib/domain/Phone/WebRTCPhone.js +65 -15
  65. package/lib/domain/Profile.js +6 -0
  66. package/lib/domain/__tests__/CallLog.test.js +10 -0
  67. package/lib/domain/__tests__/CallSession.test.js +14 -0
  68. package/lib/domain/__tests__/IndirectTransfer.test.js +14 -0
  69. package/lib/domain/__tests__/Profile.test.js +6 -0
  70. package/lib/domain/__tests__/Room.test.js +14 -0
  71. package/lib/domain/__tests__/Session.test.js +6 -0
  72. package/lib/index.js +93 -22
  73. package/lib/service/CallApi.js +17 -0
  74. package/lib/service/getApiClient.js +17 -0
  75. package/lib/simple/Auth.js +93 -22
  76. package/lib/simple/Configuration.js +93 -22
  77. package/lib/simple/Directory.js +17 -0
  78. package/lib/simple/Phone.js +93 -22
  79. package/lib/simple/index.js +93 -22
  80. package/lib/simple/room/LocalParticipant.js +93 -22
  81. package/lib/simple/room/Participant.js +93 -22
  82. package/lib/simple/room/RemoteParticipant.js +93 -22
  83. package/lib/simple/room/Room.js +93 -22
  84. package/lib/simple/room/SipRoom.js +93 -22
  85. package/lib/simple/room/Stream.js +93 -22
  86. package/lib/simple/room/__tests__/RemoteParticipant.test.js +93 -22
  87. package/lib/simple/utils.js +93 -22
  88. package/lib/web-rtc-client.js +18 -1
  89. package/package.json +1 -1
  90. package/src/api/auth.js +5 -0
  91. package/src/domain/AdHocAPIConference.js +4 -0
  92. package/src/domain/CallLog.js +6 -0
  93. package/src/domain/CallSession.js +14 -0
  94. package/src/domain/Phone/WebRTCPhone.js +51 -15
  95. package/src/domain/Profile.js +6 -0
  96. package/src/domain/__tests__/CallLog.test.js +4 -0
  97. package/src/simple/Phone.js +6 -6
  98. package/src/web-rtc-client.js +1 -1
@@ -285,6 +285,7 @@ var updateFrom = (instance , from ) => {
285
285
 
286
286
 
287
287
 
288
+
288
289
 
289
290
 
290
291
  class CallSession {
@@ -347,6 +348,8 @@ class CallSession {
347
348
 
348
349
 
349
350
 
351
+
352
+
350
353
 
351
354
 
352
355
 
@@ -378,6 +381,7 @@ class CallSession {
378
381
  videoRemotelyDowngraded,
379
382
  sipSession,
380
383
  answerTime,
384
+ conference,
381
385
  } ) {
382
386
  this.callId = callId;
383
387
  this.sipCallId = sipCallId;
@@ -406,6 +410,7 @@ class CallSession {
406
410
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
407
411
  this.sipSession = sipSession;
408
412
  this.answerTime = answerTime || this.answerTime;
413
+ this.conference = conference;
409
414
 
410
415
  // Useful to compare instead of instanceof with minified code
411
416
  this.type = 'CallSession';
@@ -463,6 +468,10 @@ class CallSession {
463
468
  this.screensharing = false;
464
469
  }
465
470
 
471
+ setIsConference(conference ) {
472
+ this.conference = conference;
473
+ }
474
+
466
475
  isIncoming() {
467
476
  return !this.isCaller && !this.answered;
468
477
  }
@@ -539,6 +548,10 @@ class CallSession {
539
548
  return this.sipStatus === sessionState.SessionState.Terminated;
540
549
  }
541
550
 
551
+ isConference() {
552
+ return this.conference;
553
+ }
554
+
542
555
  getElapsedTimeInSeconds() {
543
556
  if (!this.startTime) {
544
557
  return 0;
@@ -630,6 +643,7 @@ class CallSession {
630
643
  cameraEnabled: false,
631
644
  dialedExtension: call.dialedExtension,
632
645
  call,
646
+ conference: false, // @FIXME?
633
647
  });
634
648
  }
635
649
  }
@@ -1670,6 +1684,7 @@ const LINE_STATE = {
1670
1684
 
1671
1685
 
1672
1686
 
1687
+
1673
1688
 
1674
1689
 
1675
1690
 
@@ -1706,6 +1721,7 @@ const LINE_STATE = {
1706
1721
 
1707
1722
 
1708
1723
 
1724
+
1709
1725
 
1710
1726
 
1711
1727
 
@@ -1737,6 +1753,7 @@ class Profile {
1737
1753
 
1738
1754
 
1739
1755
 
1756
+
1740
1757
 
1741
1758
 
1742
1759
 
@@ -1753,6 +1770,7 @@ class Profile {
1753
1770
  lines: plain.lines.map(line => Line.parse(line)),
1754
1771
  username: plain.username,
1755
1772
  mobileNumber: plain.mobile_phone_number || '',
1773
+ ringSeconds: plain.ring_seconds,
1756
1774
  forwards: [
1757
1775
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
1758
1776
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -1789,6 +1807,7 @@ class Profile {
1789
1807
  switchboards,
1790
1808
  agent,
1791
1809
  status,
1810
+ ringSeconds,
1792
1811
  sipLines,
1793
1812
  callPickupTargetUsers,
1794
1813
  onlineCallRecordEnabled,
@@ -1810,6 +1829,7 @@ class Profile {
1810
1829
  this.status = status;
1811
1830
  this.callPickupTargetUsers = callPickupTargetUsers;
1812
1831
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
1832
+ this.ringSeconds = ringSeconds;
1813
1833
 
1814
1834
  this.sipLines = sipLines || [];
1815
1835
  }
@@ -2815,6 +2835,7 @@ var authMethods = (client , baseUrl ) => ({
2815
2835
 
2816
2836
 
2817
2837
 
2838
+
2818
2839
  ) {
2819
2840
  const body = {
2820
2841
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2834,6 +2855,10 @@ var authMethods = (client , baseUrl ) => ({
2834
2855
  headers['Wazo-Session-Type'] = 'mobile';
2835
2856
  }
2836
2857
 
2858
+ if (params.tenantId) {
2859
+ body.tenant_id = params.tenantId;
2860
+ }
2861
+
2837
2862
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2838
2863
  },
2839
2864
 
@@ -3719,11 +3744,13 @@ class Recording {
3719
3744
 
3720
3745
 
3721
3746
 
3747
+
3722
3748
 
3723
3749
 
3724
3750
 
3725
3751
 
3726
3752
 
3753
+
3727
3754
 
3728
3755
 
3729
3756
 
@@ -3744,10 +3771,12 @@ class Recording {
3744
3771
 
3745
3772
 
3746
3773
 
3774
+
3747
3775
 
3748
3776
 
3749
3777
 
3750
3778
 
3779
+
3751
3780
 
3752
3781
 
3753
3782
 
@@ -3809,10 +3838,12 @@ class CallLog {
3809
3838
  || plain.destination_extension
3810
3839
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3811
3840
  name: plain.requested_name || plain.destination_name || '',
3841
+ uuid: plain.destination_user_uuid,
3812
3842
  },
3813
3843
  source: {
3814
3844
  extension: plain.source_extension,
3815
3845
  name: plain.source_name,
3846
+ uuid: plain.source_user_uuid,
3816
3847
  },
3817
3848
  id: plain.id,
3818
3849
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -5655,6 +5686,10 @@ class AdHocAPIConference {
5655
5686
  this.conferenceId = conferenceId || '';
5656
5687
  this.muted = muted || false;
5657
5688
  this.paused = paused || false;
5689
+
5690
+ if (this.host) {
5691
+ this.host.setIsConference(true);
5692
+ }
5658
5693
  }
5659
5694
 
5660
5695
  async start() {
@@ -6409,7 +6444,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6409
6444
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6410
6445
  class CanceledCallError extends Error {}
6411
6446
 
6412
- const MAX_REGISTER_TRIES = 10;
6447
+ const MAX_REGISTER_TRIES = 5;
6413
6448
 
6414
6449
 
6415
6450
 
@@ -9364,7 +9399,11 @@ class WebRTCPhone extends Emitter {
9364
9399
  accept(callSession , cameraEnabled ) {
9365
9400
  logger$8.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9366
9401
  if (this.currentSipSession) {
9367
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9402
+ this.holdSipSession(
9403
+ this.currentSipSession,
9404
+ this.currentCallSession,
9405
+ true,
9406
+ );
9368
9407
  }
9369
9408
 
9370
9409
  if (!callSession) {
@@ -9372,6 +9411,12 @@ class WebRTCPhone extends Emitter {
9372
9411
  return Promise.resolve(null);
9373
9412
  }
9374
9413
 
9414
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9415
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9416
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9417
+ return Promise.resolve(null);
9418
+ }
9419
+
9375
9420
  if (callSession.getId() in this.acceptedSessions) {
9376
9421
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9377
9422
  return Promise.resolve(callSession.sipCallId);
@@ -9451,22 +9496,22 @@ class WebRTCPhone extends Emitter {
9451
9496
  }
9452
9497
  }
9453
9498
 
9454
- hold(callSession , withEvent = true, isConference = false) {
9499
+ hold(callSession , withEvent = true) {
9455
9500
  logger$8.info('WebRTC hold', { id: callSession.getId() });
9456
9501
 
9457
9502
  const sipSession = this.findSipSession(callSession);
9458
9503
 
9459
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9504
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9460
9505
  }
9461
9506
 
9462
9507
  // @Deprecated
9463
- unhold(callSession , withEvent = true, isConference = false) {
9508
+ unhold(callSession , withEvent = true) {
9464
9509
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9465
9510
 
9466
- return this.resume(callSession, isConference, withEvent);
9511
+ return this.resume(callSession, withEvent);
9467
9512
  }
9468
9513
 
9469
- resume(callSession , isConference = false, withEvent = true) {
9514
+ resume(callSession , withEvent = true) {
9470
9515
  logger$8.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9471
9516
 
9472
9517
  const sipSession = this.findSipSession(callSession);
@@ -9479,10 +9524,14 @@ class WebRTCPhone extends Emitter {
9479
9524
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9480
9525
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9481
9526
  logger$8.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9482
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9527
+ this.holdSipSession(
9528
+ this.currentSipSession,
9529
+ this.currentCallSession,
9530
+ withEvent,
9531
+ );
9483
9532
  }
9484
9533
 
9485
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9534
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9486
9535
  this.currentSipSession = sipSession;
9487
9536
  if (callSession) {
9488
9537
  this.currentCallSession = callSession;
@@ -9495,7 +9544,6 @@ class WebRTCPhone extends Emitter {
9495
9544
  sipSession ,
9496
9545
  callSession ,
9497
9546
  withEvent = true,
9498
- isConference = false,
9499
9547
  ) {
9500
9548
  if (!sipSession) {
9501
9549
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9516,6 +9564,8 @@ class WebRTCPhone extends Emitter {
9516
9564
  await this.client.downgradeToAudio(sipSession);
9517
9565
  }
9518
9566
 
9567
+ const isConference = !!callSession && callSession.isConference();
9568
+
9519
9569
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9520
9570
  if (withEvent) {
9521
9571
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9528,11 +9578,13 @@ class WebRTCPhone extends Emitter {
9528
9578
  sipSession ,
9529
9579
  callSession ,
9530
9580
  withEvent = true,
9531
- isConference = false,
9532
9581
  ) {
9533
9582
  if (!sipSession) {
9534
9583
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9535
9584
  }
9585
+
9586
+ const isConference = !!callSession && callSession.isConference();
9587
+
9536
9588
  const sessionId = this.getSipSessionId(sipSession);
9537
9589
  logger$8.info('WebRTC unhold sip session', { sessionId, isConference });
9538
9590
 
@@ -9674,7 +9726,11 @@ class WebRTCPhone extends Emitter {
9674
9726
  await this.client.register();
9675
9727
  }
9676
9728
  if (this.currentSipSession) {
9677
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9729
+ this.holdSipSession(
9730
+ this.currentSipSession,
9731
+ this.currentCallSession,
9732
+ true,
9733
+ ).catch(e => {
9678
9734
  logger$8.warn('Unable to hold current session when making another call', e);
9679
9735
  });
9680
9736
  }
@@ -9689,6 +9745,7 @@ class WebRTCPhone extends Emitter {
9689
9745
  return Promise.resolve(null);
9690
9746
  }
9691
9747
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9748
+ callSession.setIsConference(conference);
9692
9749
  callSession.creationTime = new Date();
9693
9750
  this._updateCallSession(callSession);
9694
9751
 
@@ -9996,9 +10053,17 @@ class WebRTCPhone extends Emitter {
9996
10053
  });
9997
10054
 
9998
10055
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
9999
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10056
+ const sessionId = this.getSipSessionId(sipSession);
10057
+ const hasSession = sessionId in this.callSessions;
10000
10058
 
10001
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10059
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10060
+
10061
+ if (!hasSession) {
10062
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10063
+ return;
10064
+ }
10065
+
10066
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10002
10067
 
10003
10068
  if (this.audioOutputDeviceId) {
10004
10069
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10134,9 +10199,14 @@ class WebRTCPhone extends Emitter {
10134
10199
  return this.client.getSipSessionId(sipSession);
10135
10200
  }
10136
10201
 
10137
- _updateCallSession(callSession ) {
10202
+ getSipSessionIdFromCallSession(callSession ) {
10138
10203
  const sipSession = this.findSipSession(callSession);
10139
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10204
+
10205
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10206
+ }
10207
+
10208
+ _updateCallSession(callSession ) {
10209
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10140
10210
 
10141
10211
  if (sipSessionId) {
10142
10212
  this.callSessions[sipSessionId] = callSession;
@@ -10254,6 +10324,7 @@ class WebRTCPhone extends Emitter {
10254
10324
  recording: fromSession ? fromSession.isRecording() : false,
10255
10325
  recordingPaused: false, // @TODO
10256
10326
  sipSession,
10327
+ conference: !!fromSession && fromSession.isConference(),
10257
10328
  ...extra,
10258
10329
  });
10259
10330
 
@@ -13671,16 +13742,16 @@ class Phone extends Emitter {
13671
13742
  }
13672
13743
  }
13673
13744
 
13674
- hold(callSession , isConference = false) {
13675
- return this.phone && this.phone.hold(callSession, true, isConference);
13745
+ hold(callSession ) {
13746
+ return this.phone && this.phone.hold(callSession, true);
13676
13747
  }
13677
13748
 
13678
- unhold(callSession , isConference = false) {
13679
- return this.phone && this.phone.unhold(callSession, true, isConference);
13749
+ unhold(callSession ) {
13750
+ return this.phone && this.phone.unhold(callSession, true);
13680
13751
  }
13681
13752
 
13682
- resume(callSession , isConference = false) {
13683
- return this.phone && this.phone.resume(callSession, isConference);
13753
+ resume(callSession ) {
13754
+ return this.phone && this.phone.resume(callSession);
13684
13755
  }
13685
13756
 
13686
13757
  reject(callSession ) {