@wazo/sdk 0.38.7 → 0.38.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 (121) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +163 -2
  3. package/esm/__tests__/web-rtc-client.test.js +248 -27
  4. package/esm/api/auth.js +12 -0
  5. package/esm/api/calld.js +8 -0
  6. package/esm/api/confd.js +134 -2
  7. package/esm/api/ctid-ng.js +1 -0
  8. package/esm/api-client.js +163 -2
  9. package/esm/checker/Checker.js +204 -24
  10. package/esm/checker/checks/aor.js +163 -2
  11. package/esm/checker/checks/api.js +163 -2
  12. package/esm/checker/checks/index.js +204 -24
  13. package/esm/checker/checks/wazo-websocket.js +2 -0
  14. package/esm/checker/checks/webrtc-transport.js +202 -24
  15. package/esm/checker/checks/webrtc.js +202 -24
  16. package/esm/domain/AdHocAPIConference.js +170 -4
  17. package/esm/domain/Features.js +170 -4
  18. package/esm/domain/Meeting.js +18 -0
  19. package/esm/domain/MeetingAuthorization.js +70 -0
  20. package/esm/domain/Phone/CTIPhone.js +170 -4
  21. package/esm/domain/Phone/WebRTCPhone.js +2 -3
  22. package/esm/domain/__tests__/Meeting.test.js +87 -1
  23. package/esm/domain/__tests__/MeetingAuthorization.test.js +109 -0
  24. package/esm/index.js +300 -36
  25. package/esm/service/CallApi.js +170 -4
  26. package/esm/service/getApiClient.js +176 -5
  27. package/esm/simple/Auth.js +301 -37
  28. package/esm/simple/Configuration.js +300 -36
  29. package/esm/simple/Directory.js +170 -4
  30. package/esm/simple/Phone.js +300 -36
  31. package/esm/simple/Softphone.js +5 -0
  32. package/esm/simple/Websocket.js +3 -0
  33. package/esm/simple/index.js +300 -36
  34. package/esm/simple/room/LocalParticipant.js +300 -36
  35. package/esm/simple/room/Participant.js +300 -36
  36. package/esm/simple/room/RemoteParticipant.js +300 -36
  37. package/esm/simple/room/Room.js +300 -36
  38. package/esm/simple/room/SipRoom.js +300 -36
  39. package/esm/simple/room/Stream.js +300 -36
  40. package/esm/simple/room/__tests__/Participant.test.js +14812 -0
  41. package/esm/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  42. package/esm/simple/utils.js +300 -36
  43. package/esm/utils/__tests__/object.test.js +57 -0
  44. package/esm/utils/__tests__/string.test.js +30 -0
  45. package/esm/utils/object.js +24 -0
  46. package/esm/utils/string.js +10 -0
  47. package/esm/web-rtc-client.js +202 -24
  48. package/esm/websocket-client.js +3 -1
  49. package/lib/__tests__/api-client.test.js +163 -2
  50. package/lib/__tests__/web-rtc-client.test.js +248 -27
  51. package/lib/api/auth.js +12 -0
  52. package/lib/api/calld.js +8 -0
  53. package/lib/api/confd.js +134 -2
  54. package/lib/api/ctid-ng.js +1 -0
  55. package/lib/api-client.js +163 -2
  56. package/lib/checker/Checker.js +204 -24
  57. package/lib/checker/checks/aor.js +163 -2
  58. package/lib/checker/checks/api.js +163 -2
  59. package/lib/checker/checks/index.js +204 -24
  60. package/lib/checker/checks/wazo-websocket.js +2 -0
  61. package/lib/checker/checks/webrtc-transport.js +202 -24
  62. package/lib/checker/checks/webrtc.js +202 -24
  63. package/lib/domain/AdHocAPIConference.js +170 -4
  64. package/lib/domain/Features.js +170 -4
  65. package/lib/domain/Meeting.js +18 -0
  66. package/lib/domain/MeetingAuthorization.js +79 -0
  67. package/lib/domain/Phone/CTIPhone.js +170 -4
  68. package/lib/domain/Phone/WebRTCPhone.js +2 -3
  69. package/lib/domain/__tests__/Meeting.test.js +87 -1
  70. package/lib/domain/__tests__/MeetingAuthorization.test.js +111 -0
  71. package/lib/index.js +300 -36
  72. package/lib/service/CallApi.js +170 -4
  73. package/lib/service/getApiClient.js +176 -4
  74. package/lib/simple/Auth.js +301 -36
  75. package/lib/simple/Configuration.js +300 -36
  76. package/lib/simple/Directory.js +170 -4
  77. package/lib/simple/Phone.js +300 -36
  78. package/lib/simple/Softphone.js +5 -0
  79. package/lib/simple/Websocket.js +3 -0
  80. package/lib/simple/index.js +300 -36
  81. package/lib/simple/room/LocalParticipant.js +300 -36
  82. package/lib/simple/room/Participant.js +300 -36
  83. package/lib/simple/room/RemoteParticipant.js +300 -36
  84. package/lib/simple/room/Room.js +300 -36
  85. package/lib/simple/room/SipRoom.js +300 -36
  86. package/lib/simple/room/Stream.js +300 -36
  87. package/lib/simple/room/__tests__/Participant.test.js +14822 -0
  88. package/lib/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  89. package/lib/simple/utils.js +300 -36
  90. package/lib/utils/__tests__/object.test.js +59 -0
  91. package/lib/utils/__tests__/string.test.js +32 -0
  92. package/lib/utils/object.js +28 -0
  93. package/lib/utils/string.js +14 -0
  94. package/lib/web-rtc-client.js +202 -24
  95. package/lib/websocket-client.js +3 -0
  96. package/package.json +1 -1
  97. package/src/__tests__/web-rtc-client.test.js +46 -3
  98. package/src/api/auth.js +12 -0
  99. package/src/api/calld.js +8 -0
  100. package/src/api/confd.js +43 -2
  101. package/src/api-client.js +8 -0
  102. package/src/domain/Meeting.js +20 -0
  103. package/src/domain/MeetingAuthorization.js +67 -0
  104. package/src/domain/Phone/WebRTCPhone.js +1 -3
  105. package/src/domain/__tests__/Meeting.test.js +70 -1
  106. package/src/domain/__tests__/MeetingAuthorization.test.js +58 -0
  107. package/src/service/getApiClient.js +13 -2
  108. package/src/simple/Auth.js +35 -4
  109. package/src/simple/Softphone.js +5 -0
  110. package/src/simple/index.js +2 -1
  111. package/src/simple/room/Participant.js +40 -0
  112. package/src/simple/room/Room.js +2 -2
  113. package/src/simple/room/SipRoom.js +1 -1
  114. package/src/simple/room/__tests__/Participant.test.js +81 -0
  115. package/src/types/WebSocketMessage.js +7 -1
  116. package/src/utils/__tests__/object.test.js +35 -0
  117. package/src/utils/__tests__/string.test.js +23 -0
  118. package/src/utils/object.js +15 -0
  119. package/src/utils/string.js +8 -0
  120. package/src/web-rtc-client.js +39 -22
  121. package/src/websocket-client.js +2 -0
@@ -2215,6 +2215,7 @@ var authMethods = (client , baseUrl ) => ({
2215
2215
 
2216
2216
 
2217
2217
 
2218
+
2218
2219
  ) {
2219
2220
  const body = {
2220
2221
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2235,9 +2236,14 @@ var authMethods = (client , baseUrl ) => ({
2235
2236
  }
2236
2237
 
2237
2238
  if (params.tenantId) {
2239
+ console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
2238
2240
  body.tenant_id = params.tenantId;
2239
2241
  }
2240
2242
 
2243
+ if (params.domainName) {
2244
+ body.domain_name = params.domainName;
2245
+ }
2246
+
2241
2247
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2242
2248
  },
2243
2249
 
@@ -2250,6 +2256,7 @@ var authMethods = (client , baseUrl ) => ({
2250
2256
  expiration ,
2251
2257
  isMobile = false,
2252
2258
  tenantId ,
2259
+ domainName ,
2253
2260
  ) => {
2254
2261
  const body = {
2255
2262
  backend: backend || DEFAULT_BACKEND_USER,
@@ -2259,9 +2266,14 @@ var authMethods = (client , baseUrl ) => ({
2259
2266
  };
2260
2267
 
2261
2268
  if (tenantId) {
2269
+ console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
2262
2270
  body.tenant_id = tenantId;
2263
2271
  }
2264
2272
 
2273
+ if (domainName) {
2274
+ body.domain_name = domainName;
2275
+ }
2276
+
2265
2277
  const headers = {
2266
2278
  'Content-Type': 'application/json',
2267
2279
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -2631,6 +2643,70 @@ class ExternalApp {
2631
2643
 
2632
2644
  //
2633
2645
 
2646
+ class MeetingAuthorization {
2647
+
2648
+
2649
+
2650
+
2651
+
2652
+
2653
+ constructor({
2654
+ meetingUuid,
2655
+ uuid,
2656
+ userUuid,
2657
+ userName,
2658
+ } = {}) {
2659
+ this.meetingUuid = meetingUuid;
2660
+ this.uuid = uuid;
2661
+ this.userUuid = userUuid;
2662
+ this.userName = userName;
2663
+ }
2664
+
2665
+ setStatus(status ) {
2666
+ this.status = status;
2667
+ }
2668
+
2669
+ getStatus() {
2670
+ return this.status;
2671
+ }
2672
+
2673
+ static parse(plain ) {
2674
+ const {
2675
+ meeting_uuid: meetingUuid,
2676
+ uuid,
2677
+ guest_uuid: userUuid,
2678
+ guest_name: userName,
2679
+ } = plain;
2680
+
2681
+ return new MeetingAuthorization({
2682
+ meetingUuid,
2683
+ uuid,
2684
+ userUuid,
2685
+ userName,
2686
+ });
2687
+ }
2688
+
2689
+ static parseMany(items ) {
2690
+ if (!items) {
2691
+ return [];
2692
+ }
2693
+ return items.map(MeetingAuthorization.parse);
2694
+ }
2695
+ }
2696
+
2697
+ //
2698
+
2699
+
2700
+
2701
+
2702
+
2703
+
2704
+
2705
+
2706
+
2707
+
2708
+
2709
+
2634
2710
 
2635
2711
 
2636
2712
 
@@ -2641,6 +2717,7 @@ class ExternalApp {
2641
2717
 
2642
2718
 
2643
2719
 
2720
+
2644
2721
 
2645
2722
 
2646
2723
  class Meeting {
@@ -2655,6 +2732,8 @@ class Meeting {
2655
2732
 
2656
2733
 
2657
2734
 
2735
+
2736
+
2658
2737
 
2659
2738
  static parse(plain ) {
2660
2739
  return new Meeting({
@@ -2667,6 +2746,7 @@ class Meeting {
2667
2746
  extension: plain.exten,
2668
2747
  persistent: plain.persistent,
2669
2748
  creationTime: moment__default['default'](plain.creation_time).toDate(),
2749
+ requireAuthorization: plain.require_authorization,
2670
2750
  });
2671
2751
  }
2672
2752
 
@@ -2691,6 +2771,7 @@ class Meeting {
2691
2771
  extension,
2692
2772
  persistent,
2693
2773
  creationTime,
2774
+ requireAuthorization,
2694
2775
  } = {}) {
2695
2776
  this.guestSipAuthorization = guestSipAuthorization;
2696
2777
  this.uri = uri;
@@ -2701,6 +2782,7 @@ class Meeting {
2701
2782
  this.extension = extension;
2702
2783
  this.persistent = persistent;
2703
2784
  this.creationTime = creationTime;
2785
+ this.requireAuthorization = requireAuthorization;
2704
2786
 
2705
2787
  // Useful to compare instead of instanceof with minified code
2706
2788
  this.type = 'Meeting';
@@ -2711,8 +2793,32 @@ class Meeting {
2711
2793
  const [username, secret] = atob(this.guestSipAuthorization).split(':');
2712
2794
  return { username, secret };
2713
2795
  }
2796
+
2714
2797
  }
2715
2798
 
2799
+ //
2800
+
2801
+ const camelToUnderscore = (key ) => {
2802
+ if (typeof key !== 'string') {
2803
+ throw new Error('Input is not a string');
2804
+ }
2805
+ return key.charAt(0).toLowerCase() + key.substring(1).replace(/([A-Z])/g, '_$1').toLowerCase();
2806
+ };
2807
+
2808
+ //
2809
+
2810
+ const convertKeysFromCamelToUnderscore = (args ) => {
2811
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
2812
+ throw new Error('Input is not an object');
2813
+ }
2814
+
2815
+ return Object.keys(args).reduce((acc, key) => {
2816
+ acc[camelToUnderscore(key)] = typeof args[key] === 'object' && !Array.isArray(args[key])
2817
+ ? convertKeysFromCamelToUnderscore(args[key]) : args[key];
2818
+ return acc;
2819
+ }, {});
2820
+ };
2821
+
2716
2822
  /* */
2717
2823
 
2718
2824
  var confdMethods = (client , baseUrl ) => ({
@@ -2781,8 +2887,18 @@ var confdMethods = (client , baseUrl ) => ({
2781
2887
  getMyMeetings: () =>
2782
2888
  client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2783
2889
 
2784
- createMyMeeting: (name , persistent ) =>
2785
- client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2890
+ createMyMeeting: (args ) =>
2891
+ client
2892
+ .post(`${baseUrl}/users/me/meetings`, convertKeysFromCamelToUnderscore(args))
2893
+ .then(Meeting.parse),
2894
+
2895
+ updateMyMeeting: (meetingUuid , data ) =>
2896
+ client.put(
2897
+ `${baseUrl}/users/me/meetings/${meetingUuid}`,
2898
+ convertKeysFromCamelToUnderscore(data),
2899
+ null,
2900
+ ApiRequester.successResponseParser,
2901
+ ),
2786
2902
 
2787
2903
  deleteMyMeeting: (meetingUuid ) =>
2788
2904
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2790,8 +2906,36 @@ var confdMethods = (client , baseUrl ) => ({
2790
2906
  getMeeting: (meetingUuid ) =>
2791
2907
  client.get(`${baseUrl}/meetings/${meetingUuid}`, null).then(Meeting.parse),
2792
2908
 
2909
+ meetingAuthorizations: (meetingUuid ) =>
2910
+ client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/authorizations`, null).then(MeetingAuthorization.parseMany),
2911
+
2912
+ meetingAuthorizationReject: (meetingUuid , authorizationUuid ) =>
2913
+ client.put(
2914
+ `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/reject`,
2915
+ {},
2916
+ null,
2917
+ ApiRequester.successResponseParser,
2918
+ ),
2919
+
2920
+ meetingAuthorizationAccept: (meetingUuid , authorizationUuid ) =>
2921
+ client.put(
2922
+ `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/accept`,
2923
+ {},
2924
+ null,
2925
+ ApiRequester.successResponseParser,
2926
+ ),
2927
+
2793
2928
  guestGetMeeting: (meetingUuid ) =>
2794
2929
  client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}`, null).then(Meeting.parse),
2930
+
2931
+ guestAuthorizationRequest: (userUuid , meetingUuid , username ) =>
2932
+ client
2933
+ .post(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations`, { guest_name: username })
2934
+ .then(MeetingAuthorization.parse),
2935
+
2936
+ guestAuthorizationCheck: (userUuid , meetingUuid , authorizationUuid ) =>
2937
+ client.get(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations/${authorizationUuid}`, null),
2938
+
2795
2939
  });
2796
2940
 
2797
2941
  //
@@ -4213,6 +4357,14 @@ var calldMethods = (client , baseUrl ) => ({
4213
4357
  getMeetingParticipantsAsUser: async (meetingUuid ) =>
4214
4358
  client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/participants`),
4215
4359
 
4360
+ banMeetingParticipant: (meetingUuid , participantUuid ) =>
4361
+ client.delete(
4362
+ `${baseUrl}/users/me/meetings/${meetingUuid}/participants/${participantUuid}`,
4363
+ null,
4364
+ null,
4365
+ ApiRequester.successResponseParser,
4366
+ ),
4367
+
4216
4368
  listTrunks: () => client.get(`${baseUrl}/trunks`),
4217
4369
 
4218
4370
  mute: (callId ) =>
@@ -4590,6 +4742,7 @@ class ApiClient {
4590
4742
 
4591
4743
 
4592
4744
 
4745
+
4593
4746
 
4594
4747
 
4595
4748
 
@@ -4631,6 +4784,7 @@ class ApiClient {
4631
4784
  refreshToken: this.refreshToken,
4632
4785
  refreshBackend: this.refreshBackend,
4633
4786
  refreshTenantId: this.refreshTenantId,
4787
+ refreshDomainName: this.refreshDomainName,
4634
4788
  refreshExpiration: this.refreshExpiration,
4635
4789
  isMobile: this.isMobile,
4636
4790
  });
@@ -4646,6 +4800,7 @@ class ApiClient {
4646
4800
  this.refreshExpiration,
4647
4801
  this.isMobile,
4648
4802
  this.refreshTenantId,
4803
+ this.refreshDomainName,
4649
4804
  );
4650
4805
 
4651
4806
  logger.info('token refreshed', { token: session.token });
@@ -4699,9 +4854,14 @@ class ApiClient {
4699
4854
  }
4700
4855
 
4701
4856
  setRefreshTenantId(tenantId ) {
4857
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
4702
4858
  this.refreshTenantId = tenantId;
4703
4859
  }
4704
4860
 
4861
+ setRefreshDomainName(domainName ) {
4862
+ this.refreshDomainName = domainName;
4863
+ }
4864
+
4705
4865
  setIsMobile(isMobile ) {
4706
4866
  this.isMobile = isMobile;
4707
4867
  }
@@ -4726,6 +4886,7 @@ global.wazoClientId = global.wazoClientId || {};
4726
4886
  global.wazoClientToken = global.wazoClientToken || {};
4727
4887
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4728
4888
  global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4889
+ global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
4729
4890
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4730
4891
  global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4731
4892
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
@@ -4735,6 +4896,7 @@ global.wazoFetchOptions = global.wazoFetchOptions || {};
4735
4896
 
4736
4897
  const fillClient = (apiClient ) => {
4737
4898
  const { server, token, clientId } = apiClient.client;
4899
+ const tenantId = global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId;
4738
4900
 
4739
4901
  // try with null server when dealing with non-related server info
4740
4902
  apiClient.setToken(global.wazoClientToken[server] || global.wazoClientToken[null] || token);
@@ -4743,8 +4905,12 @@ const fillClient = (apiClient ) => {
4743
4905
 
4744
4906
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4745
4907
 
4746
- apiClient.setRefreshTenantId(
4747
- global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4908
+ if (tenantId) {
4909
+ apiClient.setRefreshTenantId(tenantId);
4910
+ }
4911
+
4912
+ apiClient.setRefreshDomainName(
4913
+ global.wazoRefreshDomainName[server] || global.wazoRefreshDomainName[null] || apiClient.refreshDomainName,
4748
4914
  );
4749
4915
 
4750
4916
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);