@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
@@ -275,6 +275,7 @@ var updateFrom = (instance , from ) => {
275
275
 
276
276
 
277
277
 
278
+
278
279
 
279
280
 
280
281
  class CallSession {
@@ -337,6 +338,8 @@ class CallSession {
337
338
 
338
339
 
339
340
 
341
+
342
+
340
343
 
341
344
 
342
345
 
@@ -368,6 +371,7 @@ class CallSession {
368
371
  videoRemotelyDowngraded,
369
372
  sipSession,
370
373
  answerTime,
374
+ conference,
371
375
  } ) {
372
376
  this.callId = callId;
373
377
  this.sipCallId = sipCallId;
@@ -396,6 +400,7 @@ class CallSession {
396
400
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
397
401
  this.sipSession = sipSession;
398
402
  this.answerTime = answerTime || this.answerTime;
403
+ this.conference = conference;
399
404
 
400
405
  // Useful to compare instead of instanceof with minified code
401
406
  this.type = 'CallSession';
@@ -453,6 +458,10 @@ class CallSession {
453
458
  this.screensharing = false;
454
459
  }
455
460
 
461
+ setIsConference(conference ) {
462
+ this.conference = conference;
463
+ }
464
+
456
465
  isIncoming() {
457
466
  return !this.isCaller && !this.answered;
458
467
  }
@@ -529,6 +538,10 @@ class CallSession {
529
538
  return this.sipStatus === SessionState.Terminated;
530
539
  }
531
540
 
541
+ isConference() {
542
+ return this.conference;
543
+ }
544
+
532
545
  getElapsedTimeInSeconds() {
533
546
  if (!this.startTime) {
534
547
  return 0;
@@ -620,6 +633,7 @@ class CallSession {
620
633
  cameraEnabled: false,
621
634
  dialedExtension: call.dialedExtension,
622
635
  call,
636
+ conference: false, // @FIXME?
623
637
  });
624
638
  }
625
639
  }
@@ -1660,6 +1674,7 @@ const LINE_STATE = {
1660
1674
 
1661
1675
 
1662
1676
 
1677
+
1663
1678
 
1664
1679
 
1665
1680
 
@@ -1696,6 +1711,7 @@ const LINE_STATE = {
1696
1711
 
1697
1712
 
1698
1713
 
1714
+
1699
1715
 
1700
1716
 
1701
1717
 
@@ -1727,6 +1743,7 @@ class Profile {
1727
1743
 
1728
1744
 
1729
1745
 
1746
+
1730
1747
 
1731
1748
 
1732
1749
 
@@ -1743,6 +1760,7 @@ class Profile {
1743
1760
  lines: plain.lines.map(line => Line.parse(line)),
1744
1761
  username: plain.username,
1745
1762
  mobileNumber: plain.mobile_phone_number || '',
1763
+ ringSeconds: plain.ring_seconds,
1746
1764
  forwards: [
1747
1765
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
1748
1766
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -1779,6 +1797,7 @@ class Profile {
1779
1797
  switchboards,
1780
1798
  agent,
1781
1799
  status,
1800
+ ringSeconds,
1782
1801
  sipLines,
1783
1802
  callPickupTargetUsers,
1784
1803
  onlineCallRecordEnabled,
@@ -1800,6 +1819,7 @@ class Profile {
1800
1819
  this.status = status;
1801
1820
  this.callPickupTargetUsers = callPickupTargetUsers;
1802
1821
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
1822
+ this.ringSeconds = ringSeconds;
1803
1823
 
1804
1824
  this.sipLines = sipLines || [];
1805
1825
  }
@@ -2805,6 +2825,7 @@ var authMethods = (client , baseUrl ) => ({
2805
2825
 
2806
2826
 
2807
2827
 
2828
+
2808
2829
  ) {
2809
2830
  const body = {
2810
2831
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2824,6 +2845,10 @@ var authMethods = (client , baseUrl ) => ({
2824
2845
  headers['Wazo-Session-Type'] = 'mobile';
2825
2846
  }
2826
2847
 
2848
+ if (params.tenantId) {
2849
+ body.tenant_id = params.tenantId;
2850
+ }
2851
+
2827
2852
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2828
2853
  },
2829
2854
 
@@ -3709,11 +3734,13 @@ class Recording {
3709
3734
 
3710
3735
 
3711
3736
 
3737
+
3712
3738
 
3713
3739
 
3714
3740
 
3715
3741
 
3716
3742
 
3743
+
3717
3744
 
3718
3745
 
3719
3746
 
@@ -3734,10 +3761,12 @@ class Recording {
3734
3761
 
3735
3762
 
3736
3763
 
3764
+
3737
3765
 
3738
3766
 
3739
3767
 
3740
3768
 
3769
+
3741
3770
 
3742
3771
 
3743
3772
 
@@ -3799,10 +3828,12 @@ class CallLog {
3799
3828
  || plain.destination_extension
3800
3829
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3801
3830
  name: plain.requested_name || plain.destination_name || '',
3831
+ uuid: plain.destination_user_uuid,
3802
3832
  },
3803
3833
  source: {
3804
3834
  extension: plain.source_extension,
3805
3835
  name: plain.source_name,
3836
+ uuid: plain.source_user_uuid,
3806
3837
  },
3807
3838
  id: plain.id,
3808
3839
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -5645,6 +5676,10 @@ class AdHocAPIConference {
5645
5676
  this.conferenceId = conferenceId || '';
5646
5677
  this.muted = muted || false;
5647
5678
  this.paused = paused || false;
5679
+
5680
+ if (this.host) {
5681
+ this.host.setIsConference(true);
5682
+ }
5648
5683
  }
5649
5684
 
5650
5685
  async start() {
@@ -6399,7 +6434,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6399
6434
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6400
6435
  class CanceledCallError extends Error {}
6401
6436
 
6402
- const MAX_REGISTER_TRIES = 10;
6437
+ const MAX_REGISTER_TRIES = 5;
6403
6438
 
6404
6439
 
6405
6440
 
@@ -9354,7 +9389,11 @@ class WebRTCPhone extends Emitter {
9354
9389
  accept(callSession , cameraEnabled ) {
9355
9390
  logger$8.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9356
9391
  if (this.currentSipSession) {
9357
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9392
+ this.holdSipSession(
9393
+ this.currentSipSession,
9394
+ this.currentCallSession,
9395
+ true,
9396
+ );
9358
9397
  }
9359
9398
 
9360
9399
  if (!callSession) {
@@ -9362,6 +9401,12 @@ class WebRTCPhone extends Emitter {
9362
9401
  return Promise.resolve(null);
9363
9402
  }
9364
9403
 
9404
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9405
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9406
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9407
+ return Promise.resolve(null);
9408
+ }
9409
+
9365
9410
  if (callSession.getId() in this.acceptedSessions) {
9366
9411
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9367
9412
  return Promise.resolve(callSession.sipCallId);
@@ -9441,22 +9486,22 @@ class WebRTCPhone extends Emitter {
9441
9486
  }
9442
9487
  }
9443
9488
 
9444
- hold(callSession , withEvent = true, isConference = false) {
9489
+ hold(callSession , withEvent = true) {
9445
9490
  logger$8.info('WebRTC hold', { id: callSession.getId() });
9446
9491
 
9447
9492
  const sipSession = this.findSipSession(callSession);
9448
9493
 
9449
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9494
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9450
9495
  }
9451
9496
 
9452
9497
  // @Deprecated
9453
- unhold(callSession , withEvent = true, isConference = false) {
9498
+ unhold(callSession , withEvent = true) {
9454
9499
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9455
9500
 
9456
- return this.resume(callSession, isConference, withEvent);
9501
+ return this.resume(callSession, withEvent);
9457
9502
  }
9458
9503
 
9459
- resume(callSession , isConference = false, withEvent = true) {
9504
+ resume(callSession , withEvent = true) {
9460
9505
  logger$8.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9461
9506
 
9462
9507
  const sipSession = this.findSipSession(callSession);
@@ -9469,10 +9514,14 @@ class WebRTCPhone extends Emitter {
9469
9514
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9470
9515
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9471
9516
  logger$8.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9472
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9517
+ this.holdSipSession(
9518
+ this.currentSipSession,
9519
+ this.currentCallSession,
9520
+ withEvent,
9521
+ );
9473
9522
  }
9474
9523
 
9475
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9524
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9476
9525
  this.currentSipSession = sipSession;
9477
9526
  if (callSession) {
9478
9527
  this.currentCallSession = callSession;
@@ -9485,7 +9534,6 @@ class WebRTCPhone extends Emitter {
9485
9534
  sipSession ,
9486
9535
  callSession ,
9487
9536
  withEvent = true,
9488
- isConference = false,
9489
9537
  ) {
9490
9538
  if (!sipSession) {
9491
9539
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9506,6 +9554,8 @@ class WebRTCPhone extends Emitter {
9506
9554
  await this.client.downgradeToAudio(sipSession);
9507
9555
  }
9508
9556
 
9557
+ const isConference = !!callSession && callSession.isConference();
9558
+
9509
9559
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9510
9560
  if (withEvent) {
9511
9561
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9518,11 +9568,13 @@ class WebRTCPhone extends Emitter {
9518
9568
  sipSession ,
9519
9569
  callSession ,
9520
9570
  withEvent = true,
9521
- isConference = false,
9522
9571
  ) {
9523
9572
  if (!sipSession) {
9524
9573
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9525
9574
  }
9575
+
9576
+ const isConference = !!callSession && callSession.isConference();
9577
+
9526
9578
  const sessionId = this.getSipSessionId(sipSession);
9527
9579
  logger$8.info('WebRTC unhold sip session', { sessionId, isConference });
9528
9580
 
@@ -9664,7 +9716,11 @@ class WebRTCPhone extends Emitter {
9664
9716
  await this.client.register();
9665
9717
  }
9666
9718
  if (this.currentSipSession) {
9667
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9719
+ this.holdSipSession(
9720
+ this.currentSipSession,
9721
+ this.currentCallSession,
9722
+ true,
9723
+ ).catch(e => {
9668
9724
  logger$8.warn('Unable to hold current session when making another call', e);
9669
9725
  });
9670
9726
  }
@@ -9679,6 +9735,7 @@ class WebRTCPhone extends Emitter {
9679
9735
  return Promise.resolve(null);
9680
9736
  }
9681
9737
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9738
+ callSession.setIsConference(conference);
9682
9739
  callSession.creationTime = new Date();
9683
9740
  this._updateCallSession(callSession);
9684
9741
 
@@ -9986,9 +10043,17 @@ class WebRTCPhone extends Emitter {
9986
10043
  });
9987
10044
 
9988
10045
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
9989
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10046
+ const sessionId = this.getSipSessionId(sipSession);
10047
+ const hasSession = sessionId in this.callSessions;
9990
10048
 
9991
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10049
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10050
+
10051
+ if (!hasSession) {
10052
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10053
+ return;
10054
+ }
10055
+
10056
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
9992
10057
 
9993
10058
  if (this.audioOutputDeviceId) {
9994
10059
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10124,9 +10189,14 @@ class WebRTCPhone extends Emitter {
10124
10189
  return this.client.getSipSessionId(sipSession);
10125
10190
  }
10126
10191
 
10127
- _updateCallSession(callSession ) {
10192
+ getSipSessionIdFromCallSession(callSession ) {
10128
10193
  const sipSession = this.findSipSession(callSession);
10129
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10194
+
10195
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10196
+ }
10197
+
10198
+ _updateCallSession(callSession ) {
10199
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10130
10200
 
10131
10201
  if (sipSessionId) {
10132
10202
  this.callSessions[sipSessionId] = callSession;
@@ -10244,6 +10314,7 @@ class WebRTCPhone extends Emitter {
10244
10314
  recording: fromSession ? fromSession.isRecording() : false,
10245
10315
  recordingPaused: false, // @TODO
10246
10316
  sipSession,
10317
+ conference: !!fromSession && fromSession.isConference(),
10247
10318
  ...extra,
10248
10319
  });
10249
10320
 
@@ -13661,16 +13732,16 @@ class Phone extends Emitter {
13661
13732
  }
13662
13733
  }
13663
13734
 
13664
- hold(callSession , isConference = false) {
13665
- return this.phone && this.phone.hold(callSession, true, isConference);
13735
+ hold(callSession ) {
13736
+ return this.phone && this.phone.hold(callSession, true);
13666
13737
  }
13667
13738
 
13668
- unhold(callSession , isConference = false) {
13669
- return this.phone && this.phone.unhold(callSession, true, isConference);
13739
+ unhold(callSession ) {
13740
+ return this.phone && this.phone.unhold(callSession, true);
13670
13741
  }
13671
13742
 
13672
- resume(callSession , isConference = false) {
13673
- return this.phone && this.phone.resume(callSession, isConference);
13743
+ resume(callSession ) {
13744
+ return this.phone && this.phone.resume(callSession);
13674
13745
  }
13675
13746
 
13676
13747
  reject(callSession ) {