@wazo/sdk 0.37.2 → 0.37.6

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 (99) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +84 -22
  3. package/esm/__tests__/web-rtc-client.test.js +156 -55
  4. package/esm/api/call-logd.js +10 -22
  5. package/esm/api/calld.js +3 -0
  6. package/esm/api/confd.js +71 -0
  7. package/esm/api-client.js +84 -22
  8. package/esm/checker/Checker.js +160 -55
  9. package/esm/checker/checks/aor.js +84 -22
  10. package/esm/checker/checks/api.js +84 -22
  11. package/esm/checker/checks/index.js +160 -55
  12. package/esm/checker/checks/wazo-websocket.js +4 -0
  13. package/esm/checker/checks/webrtc-transport.js +156 -55
  14. package/esm/checker/checks/webrtc.js +156 -55
  15. package/esm/domain/AdHocAPIConference.js +84 -22
  16. package/esm/domain/CallLog.js +10 -22
  17. package/esm/domain/Features.js +84 -22
  18. package/esm/domain/Meeting.js +71 -0
  19. package/esm/domain/Phone/CTIPhone.js +84 -22
  20. package/esm/domain/Phone/WebRTCPhone.js +22 -8
  21. package/esm/domain/__tests__/CallLog.test.js +10 -22
  22. package/esm/index.js +726 -371
  23. package/esm/lib/WazoSessionDescriptionHandler.js +17 -9
  24. package/esm/service/CallApi.js +84 -22
  25. package/esm/service/getApiClient.js +84 -22
  26. package/esm/simple/Auth.js +717 -363
  27. package/esm/simple/Configuration.js +717 -363
  28. package/esm/simple/Directory.js +84 -22
  29. package/esm/simple/Phone.js +709 -355
  30. package/esm/simple/Websocket.js +6 -0
  31. package/esm/simple/index.js +719 -365
  32. package/esm/simple/room/LocalParticipant.js +689 -335
  33. package/esm/simple/room/Participant.js +689 -335
  34. package/esm/simple/room/RemoteParticipant.js +689 -335
  35. package/esm/simple/room/Room.js +689 -335
  36. package/esm/simple/room/SipRoom.js +13001 -0
  37. package/esm/simple/room/Stream.js +719 -365
  38. package/esm/simple/room/__tests__/RemoteParticipant.test.js +4130 -3774
  39. package/esm/simple/utils.js +719 -365
  40. package/esm/web-rtc-client.js +156 -55
  41. package/esm/websocket-client.js +5 -1
  42. package/lib/__tests__/api-client.test.js +84 -22
  43. package/lib/__tests__/web-rtc-client.test.js +156 -55
  44. package/lib/api/call-logd.js +10 -22
  45. package/lib/api/calld.js +3 -0
  46. package/lib/api/confd.js +71 -0
  47. package/lib/api-client.js +84 -22
  48. package/lib/checker/Checker.js +160 -55
  49. package/lib/checker/checks/aor.js +84 -22
  50. package/lib/checker/checks/api.js +84 -22
  51. package/lib/checker/checks/index.js +160 -55
  52. package/lib/checker/checks/wazo-websocket.js +4 -0
  53. package/lib/checker/checks/webrtc-transport.js +156 -55
  54. package/lib/checker/checks/webrtc.js +156 -55
  55. package/lib/domain/AdHocAPIConference.js +84 -22
  56. package/lib/domain/CallLog.js +10 -22
  57. package/lib/domain/Features.js +84 -22
  58. package/lib/domain/Meeting.js +73 -0
  59. package/lib/domain/Phone/CTIPhone.js +84 -22
  60. package/lib/domain/Phone/WebRTCPhone.js +22 -8
  61. package/lib/domain/__tests__/CallLog.test.js +10 -22
  62. package/lib/index.js +726 -371
  63. package/lib/lib/WazoSessionDescriptionHandler.js +17 -9
  64. package/lib/service/CallApi.js +84 -22
  65. package/lib/service/getApiClient.js +84 -22
  66. package/lib/simple/Auth.js +717 -363
  67. package/lib/simple/Configuration.js +717 -363
  68. package/lib/simple/Directory.js +84 -22
  69. package/lib/simple/Phone.js +709 -355
  70. package/lib/simple/Websocket.js +6 -0
  71. package/lib/simple/index.js +719 -365
  72. package/lib/simple/room/LocalParticipant.js +689 -335
  73. package/lib/simple/room/Participant.js +689 -335
  74. package/lib/simple/room/RemoteParticipant.js +689 -335
  75. package/lib/simple/room/Room.js +689 -335
  76. package/lib/simple/room/SipRoom.js +13011 -0
  77. package/lib/simple/room/Stream.js +719 -365
  78. package/lib/simple/room/__tests__/RemoteParticipant.test.js +4131 -3775
  79. package/lib/simple/utils.js +719 -365
  80. package/lib/web-rtc-client.js +156 -55
  81. package/lib/websocket-client.js +6 -0
  82. package/package.json +1 -1
  83. package/src/api/calld.js +3 -0
  84. package/src/api/confd.js +13 -0
  85. package/src/domain/CallLog.js +10 -22
  86. package/src/domain/Meeting.js +59 -0
  87. package/src/domain/Phone/WebRTCPhone.js +22 -8
  88. package/src/index.js +2 -0
  89. package/src/lib/WazoSessionDescriptionHandler.js +17 -9
  90. package/src/simple/Phone.js +13 -4
  91. package/src/simple/index.js +4 -0
  92. package/src/simple/room/Participant.js +7 -0
  93. package/src/simple/room/Room.js +158 -79
  94. package/src/simple/room/SipRoom.js +147 -0
  95. package/src/simple/room/Stream.js +1 -3
  96. package/src/simple/room/__tests__/RemoteParticipant.test.js +3 -2
  97. package/src/types/WebSocketMessage.js +21 -0
  98. package/src/web-rtc-client.js +55 -24
  99. package/src/websocket-client.js +4 -0
@@ -443,7 +443,9 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
443
443
  .then(() => {
444
444
  if (isConference && (options.constraints && !options.constraints.video) && !('hold' in options) && !audioOnly) {
445
445
  // Add a video an empty bundle to be able to replaceTrack when joining a conference without video
446
- this.peerConnection.addTransceiver('video', { streams: [this._localMediaStream], direction: 'sendrecv' });
446
+ if (this.peerConnection.addTransceiver) {
447
+ this.peerConnection.addTransceiver('video', { streams: [this._localMediaStream], direction: 'sendrecv' });
448
+ }
447
449
  }
448
450
  })
449
451
  .then(() => this.createLocalOfferOrAnswer(options))
@@ -470,12 +472,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
470
472
  };
471
473
  })
472
474
  .then((sessionDescription) => this.applyModifiers(sessionDescription, modifiers))
473
- .then((sessionDescription) => {
474
- // Set new constraints to avoid the constraints check issue in `sdh.getLocalMediaStream` later.
475
- this.localMediaStreamConstraints = options.constraints;
476
-
477
- return sessionDescription;
478
- })
479
475
  .then((sessionDescription) => ({ body: sessionDescription.sdp, contentType: 'application/sdp' }))
480
476
  .catch((error) => {
481
477
  wazoLogger.error('error when creating media', error);
@@ -670,6 +666,9 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
670
666
 
671
667
  // set the transceiver direction to the answer direction
672
668
  this._peerConnection.getTransceivers().forEach((transceiver) => {
669
+ if (transceiver.stopped) {
670
+ return;
671
+ }
673
672
  if (transceiver.direction /* guarding, but should always be true */) {
674
673
  const { receiver } = transceiver;
675
674
  if (isConference && audioOnly && receiver.track && receiver.track.kind === 'video') {
@@ -714,10 +713,15 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
714
713
  if (kind !== 'audio' && kind !== 'video') {
715
714
  throw new Error(`Unknown new track kind ${kind}.`);
716
715
  }
717
- const sender = pc.getSenders().find((otherSender) => otherSender.track && otherSender.track.kind === kind);
716
+ const sender = pc.getSenders && pc.getSenders().find((otherSender) =>
717
+ otherSender.track && otherSender.track.kind === kind);
718
718
 
719
719
  // Do not reuse sender video tracks in SFU
720
720
  if (sender && (!sfu || newTrack.kind === 'audio')) {
721
+ if (sender.track) {
722
+ // eslint-disable-next-line no-param-reassign
723
+ newTrack.enabled = sender.track.enabled;
724
+ }
721
725
  trackUpdates.push(
722
726
  new Promise((resolve) => {
723
727
  this.logger.debug(`SessionDescriptionHandler.setLocalMediaStream - replacing sender ${kind} track`);
@@ -751,7 +755,11 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
751
755
  // Review: could make streamless tracks a configurable option?
752
756
  // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addTrack#Usage_notes
753
757
  try {
754
- pc.addTrack(newTrack, localStream);
758
+ if (pc.addTrack) {
759
+ pc.addTrack(newTrack, localStream);
760
+ } else {
761
+ pc.addStream(localStream);
762
+ }
755
763
  } catch (error) {
756
764
  this.logger.error(`SessionDescriptionHandler.setLocalMediaStream - failed to add sender ${kind} track`);
757
765
  throw error;
@@ -1810,7 +1810,11 @@ class CallLog {
1810
1810
  answered: plain.answered,
1811
1811
  callDirection: plain.call_direction,
1812
1812
  destination: {
1813
- extension: plain.requested_extension || plain.destination_extension,
1813
+ // @TEMP: Temporarily assuming empty numbers are meetings
1814
+ // which is admittedly a very dangerous assumption. Did i mention it was temporary?
1815
+ extension: plain.requested_extension
1816
+ || plain.destination_extension
1817
+ || `meeting-${plain.requested_name || plain.destination_name || ''}`,
1814
1818
  name: plain.requested_name || plain.destination_name || '',
1815
1819
  },
1816
1820
  source: {
@@ -1826,27 +1830,11 @@ class CallLog {
1826
1830
  }
1827
1831
 
1828
1832
  static parseNew(plain , session ) {
1829
- return new CallLog({
1830
- answer: plain.answer ? moment(plain.answer).toDate() : null,
1831
- answered: plain.answered,
1832
- callDirection: plain.call_direction,
1833
- destination: {
1834
- extension: plain.requested_extension || plain.destination_extension,
1835
- name: plain.requested_name || plain.destination_name || '',
1836
- },
1837
- source: {
1838
- extension: plain.source_extension,
1839
- name: plain.source_name,
1840
- },
1841
- id: plain.id,
1842
- duration: (plain.duration || 0) * 1000, // duration is in seconds
1843
- start: moment(plain.start).toDate(),
1844
- end: plain.end ? moment(plain.end).toDate() : null,
1845
- recordings: Recording.parseMany(plain.recordings),
1846
- // @TODO: FIXME add verification declined vs missed call
1847
- newMissedCall: session
1848
- && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered,
1849
- });
1833
+ const callLog = CallLog.parse(plain);
1834
+ // @TODO: FIXME add verification declined vs missed call
1835
+ callLog.newMissedCall = session
1836
+ && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered;
1837
+ return callLog;
1850
1838
  }
1851
1839
 
1852
1840
  static newFrom(profile ) {
@@ -3021,6 +3009,65 @@ class ExternalApp {
3021
3009
  }
3022
3010
  }
3023
3011
 
3012
+ //
3013
+
3014
+
3015
+
3016
+
3017
+
3018
+
3019
+
3020
+
3021
+
3022
+
3023
+
3024
+ class Meeting {
3025
+
3026
+
3027
+
3028
+
3029
+
3030
+
3031
+
3032
+
3033
+
3034
+
3035
+ static parse(plain ) {
3036
+ return new Meeting({
3037
+ guestSipAuthorization: plain.guest_sip_authorization,
3038
+ hostname: plain.hostname,
3039
+ name: plain.name,
3040
+ ownerUuids: plain.owner_uuids,
3041
+ port: plain.port,
3042
+ uuid: plain.uuid,
3043
+ number: plain.number,
3044
+ });
3045
+ }
3046
+
3047
+ static newFrom(meeting ) {
3048
+ return newFrom(meeting, Meeting);
3049
+ }
3050
+
3051
+ constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, hostname, number } = {}) {
3052
+ this.guestSipAuthorization = guestSipAuthorization;
3053
+ this.hostname = hostname;
3054
+ this.name = name;
3055
+ this.ownerUuids = ownerUuids;
3056
+ this.port = port;
3057
+ this.uuid = uuid;
3058
+ this.number = number;
3059
+
3060
+ // Useful to compare instead of instanceof with minified code
3061
+ this.type = 'Meeting';
3062
+ }
3063
+
3064
+ getGuestSipCredentials() {
3065
+ // eslint-disable-next-line no-undef
3066
+ const [username, secret] = atob(this.guestSipAuthorization).split(':');
3067
+ return { username, secret };
3068
+ }
3069
+ }
3070
+
3024
3071
  /* */
3025
3072
 
3026
3073
  var confdMethods = (client , baseUrl ) => ({
@@ -3085,6 +3132,18 @@ var confdMethods = (client , baseUrl ) => ({
3085
3132
  return null;
3086
3133
  }
3087
3134
  },
3135
+
3136
+ createMyMeeting: (name ) =>
3137
+ client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
3138
+
3139
+ deleteMyMeeting: (meetingUuid ) =>
3140
+ client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
3141
+
3142
+ getMeeting: (meetingUuid ) =>
3143
+ client.get(`${baseUrl}/meetings/${meetingUuid}`, null).then(Meeting.parse),
3144
+
3145
+ guestGetMeeting: (meetingUuid ) =>
3146
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}`, null).then(Meeting.parse),
3088
3147
  });
3089
3148
 
3090
3149
  //
@@ -3919,6 +3978,9 @@ var calldMethods = (client , baseUrl ) => ({
3919
3978
  getConferenceParticipantsAsUser: async (conferenceId ) =>
3920
3979
  client.get(`${baseUrl}/users/me/conferences/${conferenceId}/participants`),
3921
3980
 
3981
+ getMeetingParticipantsAsUser: async (meetingUuid ) =>
3982
+ client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/participants`),
3983
+
3922
3984
  listTrunks: () => client.get(`${baseUrl}/trunks`),
3923
3985
 
3924
3986
  mute: (callId ) =>
@@ -2493,6 +2493,65 @@ class ExternalApp {
2493
2493
  }
2494
2494
  }
2495
2495
 
2496
+ //
2497
+
2498
+
2499
+
2500
+
2501
+
2502
+
2503
+
2504
+
2505
+
2506
+
2507
+
2508
+ class Meeting {
2509
+
2510
+
2511
+
2512
+
2513
+
2514
+
2515
+
2516
+
2517
+
2518
+
2519
+ static parse(plain ) {
2520
+ return new Meeting({
2521
+ guestSipAuthorization: plain.guest_sip_authorization,
2522
+ hostname: plain.hostname,
2523
+ name: plain.name,
2524
+ ownerUuids: plain.owner_uuids,
2525
+ port: plain.port,
2526
+ uuid: plain.uuid,
2527
+ number: plain.number,
2528
+ });
2529
+ }
2530
+
2531
+ static newFrom(meeting ) {
2532
+ return newFrom(meeting, Meeting);
2533
+ }
2534
+
2535
+ constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, hostname, number } = {}) {
2536
+ this.guestSipAuthorization = guestSipAuthorization;
2537
+ this.hostname = hostname;
2538
+ this.name = name;
2539
+ this.ownerUuids = ownerUuids;
2540
+ this.port = port;
2541
+ this.uuid = uuid;
2542
+ this.number = number;
2543
+
2544
+ // Useful to compare instead of instanceof with minified code
2545
+ this.type = 'Meeting';
2546
+ }
2547
+
2548
+ getGuestSipCredentials() {
2549
+ // eslint-disable-next-line no-undef
2550
+ const [username, secret] = atob(this.guestSipAuthorization).split(':');
2551
+ return { username, secret };
2552
+ }
2553
+ }
2554
+
2496
2555
  /* */
2497
2556
 
2498
2557
  var confdMethods = (client , baseUrl ) => ({
@@ -2557,6 +2616,18 @@ var confdMethods = (client , baseUrl ) => ({
2557
2616
  return null;
2558
2617
  }
2559
2618
  },
2619
+
2620
+ createMyMeeting: (name ) =>
2621
+ client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2622
+
2623
+ deleteMyMeeting: (meetingUuid ) =>
2624
+ client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
2625
+
2626
+ getMeeting: (meetingUuid ) =>
2627
+ client.get(`${baseUrl}/meetings/${meetingUuid}`, null).then(Meeting.parse),
2628
+
2629
+ guestGetMeeting: (meetingUuid ) =>
2630
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}`, null).then(Meeting.parse),
2560
2631
  });
2561
2632
 
2562
2633
  //
@@ -3141,7 +3212,11 @@ class CallLog {
3141
3212
  answered: plain.answered,
3142
3213
  callDirection: plain.call_direction,
3143
3214
  destination: {
3144
- extension: plain.requested_extension || plain.destination_extension,
3215
+ // @TEMP: Temporarily assuming empty numbers are meetings
3216
+ // which is admittedly a very dangerous assumption. Did i mention it was temporary?
3217
+ extension: plain.requested_extension
3218
+ || plain.destination_extension
3219
+ || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3145
3220
  name: plain.requested_name || plain.destination_name || '',
3146
3221
  },
3147
3222
  source: {
@@ -3157,27 +3232,11 @@ class CallLog {
3157
3232
  }
3158
3233
 
3159
3234
  static parseNew(plain , session ) {
3160
- return new CallLog({
3161
- answer: plain.answer ? moment(plain.answer).toDate() : null,
3162
- answered: plain.answered,
3163
- callDirection: plain.call_direction,
3164
- destination: {
3165
- extension: plain.requested_extension || plain.destination_extension,
3166
- name: plain.requested_name || plain.destination_name || '',
3167
- },
3168
- source: {
3169
- extension: plain.source_extension,
3170
- name: plain.source_name,
3171
- },
3172
- id: plain.id,
3173
- duration: (plain.duration || 0) * 1000, // duration is in seconds
3174
- start: moment(plain.start).toDate(),
3175
- end: plain.end ? moment(plain.end).toDate() : null,
3176
- recordings: Recording.parseMany(plain.recordings),
3177
- // @TODO: FIXME add verification declined vs missed call
3178
- newMissedCall: session
3179
- && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered,
3180
- });
3235
+ const callLog = CallLog.parse(plain);
3236
+ // @TODO: FIXME add verification declined vs missed call
3237
+ callLog.newMissedCall = session
3238
+ && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered;
3239
+ return callLog;
3181
3240
  }
3182
3241
 
3183
3242
  static newFrom(profile ) {
@@ -3919,6 +3978,9 @@ var calldMethods = (client , baseUrl ) => ({
3919
3978
  getConferenceParticipantsAsUser: async (conferenceId ) =>
3920
3979
  client.get(`${baseUrl}/users/me/conferences/${conferenceId}/participants`),
3921
3980
 
3981
+ getMeetingParticipantsAsUser: async (meetingUuid ) =>
3982
+ client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/participants`),
3983
+
3922
3984
  listTrunks: () => client.get(`${baseUrl}/trunks`),
3923
3985
 
3924
3986
  mute: (callId ) =>