@wazo/sdk 0.37.41 → 0.38.0

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 (112) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +45 -22
  3. package/esm/__tests__/web-rtc-client.test.js +49 -24
  4. package/esm/api/agentd.js +12 -7
  5. package/esm/api/amid.js +12 -7
  6. package/esm/api/application.js +12 -7
  7. package/esm/api/auth.js +16 -8
  8. package/esm/api/call-logd.js +12 -7
  9. package/esm/api/calld.js +12 -7
  10. package/esm/api/chatd.js +12 -7
  11. package/esm/api/confd.js +12 -7
  12. package/esm/api/ctid-ng.js +14 -7
  13. package/esm/api/dird.js +12 -7
  14. package/esm/api/webhookd.js +12 -7
  15. package/esm/api-client.js +45 -22
  16. package/esm/checker/Checker.js +50 -25
  17. package/esm/checker/checks/aor.js +45 -22
  18. package/esm/checker/checks/api.js +45 -22
  19. package/esm/checker/checks/index.js +50 -25
  20. package/esm/checker/checks/wazo-websocket.js +13 -8
  21. package/esm/checker/checks/webrtc-transport.js +49 -24
  22. package/esm/checker/checks/webrtc.js +49 -24
  23. package/esm/domain/AdHocAPIConference.js +54 -23
  24. package/esm/domain/Features.js +54 -23
  25. package/esm/domain/Phone/CTIPhone.js +54 -23
  26. package/esm/domain/Phone/WebRTCPhone.js +14 -7
  27. package/esm/index.js +233 -25
  28. package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
  29. package/esm/service/CallApi.js +54 -23
  30. package/esm/service/IssueReporter.js +12 -7
  31. package/esm/service/__tests__/IssueReporter.test.js +18 -7
  32. package/esm/service/getApiClient.js +63 -24
  33. package/esm/simple/Auth.js +233 -25
  34. package/esm/simple/Configuration.js +233 -25
  35. package/esm/simple/Directory.js +54 -23
  36. package/esm/simple/Phone.js +233 -25
  37. package/esm/simple/Softphone.js +148 -0
  38. package/esm/simple/Websocket.js +13 -8
  39. package/esm/simple/index.js +233 -25
  40. package/esm/simple/room/LocalParticipant.js +233 -25
  41. package/esm/simple/room/Participant.js +233 -25
  42. package/esm/simple/room/RemoteParticipant.js +233 -25
  43. package/esm/simple/room/Room.js +233 -25
  44. package/esm/simple/room/SipRoom.js +233 -25
  45. package/esm/simple/room/Stream.js +233 -25
  46. package/esm/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  47. package/esm/simple/utils.js +233 -25
  48. package/esm/utils/__tests__/api-requester.test.js +12 -7
  49. package/esm/utils/api-requester.js +12 -7
  50. package/esm/web-rtc-client.js +49 -24
  51. package/esm/websocket-client.js +13 -8
  52. package/lib/__tests__/api-client.test.js +45 -22
  53. package/lib/__tests__/web-rtc-client.test.js +49 -24
  54. package/lib/api/agentd.js +12 -7
  55. package/lib/api/amid.js +12 -7
  56. package/lib/api/application.js +12 -7
  57. package/lib/api/auth.js +16 -8
  58. package/lib/api/call-logd.js +12 -7
  59. package/lib/api/calld.js +12 -7
  60. package/lib/api/chatd.js +12 -7
  61. package/lib/api/confd.js +12 -7
  62. package/lib/api/ctid-ng.js +14 -7
  63. package/lib/api/dird.js +12 -7
  64. package/lib/api/webhookd.js +12 -7
  65. package/lib/api-client.js +45 -22
  66. package/lib/checker/Checker.js +50 -25
  67. package/lib/checker/checks/aor.js +45 -22
  68. package/lib/checker/checks/api.js +45 -22
  69. package/lib/checker/checks/index.js +50 -25
  70. package/lib/checker/checks/wazo-websocket.js +13 -8
  71. package/lib/checker/checks/webrtc-transport.js +49 -24
  72. package/lib/checker/checks/webrtc.js +49 -24
  73. package/lib/domain/AdHocAPIConference.js +54 -23
  74. package/lib/domain/Features.js +54 -23
  75. package/lib/domain/Phone/CTIPhone.js +54 -23
  76. package/lib/domain/Phone/WebRTCPhone.js +14 -7
  77. package/lib/index.js +233 -25
  78. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  79. package/lib/service/CallApi.js +54 -23
  80. package/lib/service/IssueReporter.js +12 -7
  81. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  82. package/lib/service/getApiClient.js +64 -23
  83. package/lib/simple/Auth.js +233 -25
  84. package/lib/simple/Configuration.js +233 -25
  85. package/lib/simple/Directory.js +54 -23
  86. package/lib/simple/Phone.js +233 -25
  87. package/lib/simple/Softphone.js +150 -0
  88. package/lib/simple/Websocket.js +13 -8
  89. package/lib/simple/index.js +233 -25
  90. package/lib/simple/room/LocalParticipant.js +233 -25
  91. package/lib/simple/room/Participant.js +233 -25
  92. package/lib/simple/room/RemoteParticipant.js +233 -25
  93. package/lib/simple/room/Room.js +233 -25
  94. package/lib/simple/room/SipRoom.js +233 -25
  95. package/lib/simple/room/Stream.js +233 -25
  96. package/lib/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  97. package/lib/simple/utils.js +233 -25
  98. package/lib/utils/__tests__/api-requester.test.js +12 -7
  99. package/lib/utils/api-requester.js +12 -7
  100. package/lib/web-rtc-client.js +49 -24
  101. package/lib/websocket-client.js +13 -8
  102. package/package.json +1 -1
  103. package/src/api/auth.js +4 -1
  104. package/src/api-client.js +26 -13
  105. package/src/service/IssueReporter.js +12 -7
  106. package/src/service/__tests__/IssueReporter.test.js +6 -0
  107. package/src/service/getApiClient.js +19 -1
  108. package/src/simple/Auth.js +21 -0
  109. package/src/simple/Softphone.js +148 -0
  110. package/src/simple/index.js +2 -0
  111. package/src/web-rtc-client.js +4 -2
  112. package/src/websocket-client.js +1 -1
@@ -427,13 +427,9 @@ class IssueReporter {
427
427
 
428
428
  setTimeout(() => {
429
429
  if (isArray) {
430
- payload = payload.map(message => {
431
- message._retry = retry + 1;
432
- return message;
433
- });
434
- } else {
435
- // $FlowFixMe
436
- payload._retry = retry + 1;
430
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
431
+ } else if (payload && typeof payload === 'object') {
432
+ payload = this._writeRetryCount(payload, retry + 1);
437
433
  }
438
434
 
439
435
  this._sendDebugToGrafana(payload, retry + 1);
@@ -441,6 +437,15 @@ class IssueReporter {
441
437
  });
442
438
  }
443
439
 
440
+ _writeRetryCount(message , count ) {
441
+ if (message && typeof message === 'object') {
442
+ // $FlowFixMe
443
+ message._retry = count;
444
+ }
445
+
446
+ return message;
447
+ }
448
+
444
449
  _isLevelAbove(level1 , level2 ) {
445
450
  const index1 = LOG_LEVELS.indexOf(level1);
446
451
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2277,9 +2282,12 @@ var authMethods = (client , baseUrl ) => ({
2277
2282
  expiration: expiration || DETAULT_EXPIRATION,
2278
2283
  refresh_token: refreshToken,
2279
2284
  client_id: client.clientId,
2280
- tenant_id: tenantId,
2281
2285
  };
2282
2286
 
2287
+ if (tenantId) {
2288
+ body.tenant_id = tenantId;
2289
+ }
2290
+
2283
2291
  const headers = {
2284
2292
  'Content-Type': 'application/json',
2285
2293
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5427,6 +5435,7 @@ class ApiClient {
5427
5435
 
5428
5436
 
5429
5437
 
5438
+
5430
5439
 
5431
5440
 
5432
5441
 
@@ -5479,23 +5488,31 @@ class ApiClient {
5479
5488
  return null;
5480
5489
  }
5481
5490
 
5482
- const session = await this.auth.refreshToken(
5483
- this.refreshToken,
5484
- this.refreshBackend,
5485
- this.refreshExpiration,
5486
- this.isMobile,
5487
- this.refreshTenantId,
5488
- );
5491
+ try {
5492
+ const session = await this.auth.refreshToken(
5493
+ this.refreshToken,
5494
+ this.refreshBackend,
5495
+ this.refreshExpiration,
5496
+ this.isMobile,
5497
+ this.refreshTenantId,
5498
+ );
5489
5499
 
5490
- logger$a.info('token refreshed', { token: session.token });
5500
+ logger$a.info('token refreshed', { token: session.token });
5491
5501
 
5492
- if (this.onRefreshToken) {
5493
- this.onRefreshToken(session.token, session);
5494
- }
5502
+ if (this.onRefreshToken) {
5503
+ this.onRefreshToken(session.token, session);
5504
+ }
5495
5505
 
5496
- this.setToken(session.token);
5506
+ this.setToken(session.token);
5507
+
5508
+ return session.token;
5509
+ } catch (error) {
5510
+ logger$a.error('token refresh, error', error);
5497
5511
 
5498
- return session.token;
5512
+ if (this.onRefreshTokenError) {
5513
+ this.onRefreshTokenError(error);
5514
+ }
5515
+ }
5499
5516
  }
5500
5517
 
5501
5518
  setToken(token ) {
@@ -5518,6 +5535,10 @@ class ApiClient {
5518
5535
  this.onRefreshToken = onRefreshToken;
5519
5536
  }
5520
5537
 
5538
+ setOnRefreshTokenError(callback ) {
5539
+ this.onRefreshTokenError = callback;
5540
+ }
5541
+
5521
5542
  setRefreshExpiration(refreshExpiration ) {
5522
5543
  this.refreshExpiration = refreshExpiration;
5523
5544
  }
@@ -5553,7 +5574,9 @@ global.wazoClients = global.wazoClients || {};
5553
5574
  global.wazoClientId = global.wazoClientId || {};
5554
5575
  global.wazoClientToken = global.wazoClientToken || {};
5555
5576
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5577
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5556
5578
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5579
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5557
5580
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5558
5581
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5559
5582
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5575,10 +5598,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5575
5598
  global.wazoRefreshToken[forServer] = newRefreshToken;
5576
5599
  };
5577
5600
 
5601
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5602
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5603
+ };
5604
+
5578
5605
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5579
5606
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5580
5607
  };
5581
5608
 
5609
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5610
+ global.wazoOnRefreshTokenError[forServer] = callback;
5611
+ };
5612
+
5582
5613
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5583
5614
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5584
5615
  };
@@ -5597,12 +5628,20 @@ const fillClient = (apiClient ) => {
5597
5628
 
5598
5629
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5599
5630
 
5631
+ apiClient.setRefreshTenantId(
5632
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5633
+ );
5634
+
5600
5635
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5601
5636
 
5602
5637
  apiClient.setOnRefreshToken(
5603
5638
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5604
5639
  );
5605
5640
 
5641
+ apiClient.setOnRefreshTokenError(
5642
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5643
+ );
5644
+
5606
5645
  apiClient.setRefreshExpiration(
5607
5646
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5608
5647
  );
@@ -5616,7 +5655,7 @@ const fillClient = (apiClient ) => {
5616
5655
  return apiClient;
5617
5656
  };
5618
5657
 
5619
- var getApiClient = (forServer ) => {
5658
+ var getApiClient = (forServer = null) => {
5620
5659
  const server = forServer || global.wazoCurrentServer || '';
5621
5660
  if (server in global.wazoClients) {
5622
5661
  return fillClient(global.wazoClients[server]);
@@ -5643,6 +5682,7 @@ class Auth {
5643
5682
 
5644
5683
 
5645
5684
 
5685
+
5646
5686
 
5647
5687
 
5648
5688
 
@@ -5680,6 +5720,14 @@ class Auth {
5680
5720
  this.onRefreshTokenCallback(token, session);
5681
5721
  }
5682
5722
  });
5723
+
5724
+ setOnRefreshTokenError(error => {
5725
+ logger$9.error('on refresh token error', error);
5726
+
5727
+ if (this.onRefreshTokenCallbackError) {
5728
+ this.onRefreshTokenCallbackError(error);
5729
+ }
5730
+ });
5683
5731
  }
5684
5732
 
5685
5733
  setFetchOptions(options ) {
@@ -5768,6 +5816,10 @@ class Auth {
5768
5816
  this.onRefreshTokenCallback = callback;
5769
5817
  }
5770
5818
 
5819
+ setOnRefreshTokenError(callback ) {
5820
+ this.onRefreshTokenCallbackError = callback;
5821
+ }
5822
+
5771
5823
  checkAuthorizations(session , authorizationName ) {
5772
5824
  if (!authorizationName) {
5773
5825
  return;
@@ -5800,6 +5852,12 @@ class Auth {
5800
5852
  setRefreshToken(refreshToken);
5801
5853
  }
5802
5854
 
5855
+ setRefreshTenantId(refreshTenantId ) {
5856
+ setRefreshTenantId(refreshTenantId);
5857
+
5858
+ getApiClient().setRefreshTenantId(refreshTenantId);
5859
+ }
5860
+
5803
5861
  forceRefreshToken() {
5804
5862
  getApiClient().forceRefreshToken();
5805
5863
  }
@@ -7434,8 +7492,10 @@ class WebRTCClient extends Emitter {
7434
7492
  conference: isConference,
7435
7493
  };
7436
7494
 
7437
- // Avoid sdh to created a new stream
7438
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7495
+ // Avoid sdh to create a new stream
7496
+ if (session.sessionDescriptionHandler) {
7497
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7498
+ }
7439
7499
 
7440
7500
  // Send re-INVITE
7441
7501
  return session.invite(options);
@@ -11446,7 +11506,7 @@ class WebSocketClient extends Emitter {
11446
11506
  this.close();
11447
11507
  }
11448
11508
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
11449
- logger$5.log('Wazo WS url computed to reconnect', { url });
11509
+ logger$5.info('Wazo WS url computed to reconnect', { url });
11450
11510
 
11451
11511
  return url;
11452
11512
  }
@@ -13085,6 +13145,153 @@ class Checker {
13085
13145
  }
13086
13146
  }
13087
13147
 
13148
+ //
13149
+ /* eslint-disable no-unused-vars */
13150
+ /* global window, document */
13151
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13152
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13153
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13154
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13155
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13156
+
13157
+ class Softphone {
13158
+ url = 'https://softphone.wazo.io';
13159
+ width = 500;
13160
+ height = 600;
13161
+ displayed = false;
13162
+ iframe = null;
13163
+
13164
+ onLinkEnabled(link ) {}
13165
+
13166
+ onCallMade(call ) {}
13167
+ onCallIncoming(call ) {}
13168
+ onCallEnded(call , card , direction , fromExtension ) {}
13169
+ onAuthenticated(session ) {}
13170
+
13171
+ init(url , width , height ) {
13172
+ if (url) {
13173
+ this.url = url;
13174
+ }
13175
+ if (width) {
13176
+ this.width = width;
13177
+ }
13178
+ if (height) {
13179
+ this.height = height;
13180
+ }
13181
+
13182
+ window.addEventListener('message', this._onMessage.bind(this), false);
13183
+
13184
+ this._createIframe();
13185
+ }
13186
+
13187
+ parseLinks() {
13188
+ const links = this._getLinks();
13189
+
13190
+ links.forEach(link => {
13191
+ link.setAttribute('data-wazo-parsed', true);
13192
+ link.addEventListener('click', this._onLinkClick.bind(this));
13193
+ this.onLinkEnabled(link);
13194
+ });
13195
+ }
13196
+
13197
+ makeCall(number ) {
13198
+ this.displaySoftphone();
13199
+
13200
+ if (this.iframe) {
13201
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13202
+ }
13203
+ }
13204
+
13205
+ toggleSoftphoneDisplay() {
13206
+ if (this.displayed) {
13207
+ this.hideSoftphone();
13208
+ } else {
13209
+ this.displaySoftphone();
13210
+ }
13211
+
13212
+ this.displayed = !this.displayed;
13213
+ }
13214
+
13215
+ displaySoftphone() {
13216
+ if (!this.iframe) {
13217
+ this._createIframe();
13218
+ }
13219
+
13220
+ if (this.iframe) {
13221
+ this.iframe.style.display = 'block';
13222
+ }
13223
+ }
13224
+
13225
+ hideSoftphone() {
13226
+ if (this.iframe) {
13227
+ this.iframe.style.display = 'none';
13228
+ }
13229
+ }
13230
+
13231
+ _createIframe() {
13232
+ this.iframe = document.createElement('iframe');
13233
+ // $FlowFixMe
13234
+ this.iframe.width = this.width;
13235
+ // $FlowFixMe
13236
+ this.iframe.height = this.height;
13237
+ // $FlowFixMe
13238
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
13239
+ this.iframe.style.position = 'absolute';
13240
+ this.iframe.style.left = '0';
13241
+ this.iframe.style.bottom = '0';
13242
+ this.iframe.style.border = '1px solid #aaa';
13243
+ this.iframe.src = this.url;
13244
+ this.iframe.style.display = 'none';
13245
+ this.iframe.id = 'wazo-softphone';
13246
+
13247
+ // $FlowFixMe
13248
+ document.body.appendChild(this.iframe);
13249
+ }
13250
+
13251
+ _getLinks() {
13252
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
13253
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
13254
+ }
13255
+
13256
+ _onLinkClick(e ) {
13257
+ e.preventDefault();
13258
+ const number = e.target.href.split(':')[1];
13259
+
13260
+ this.makeCall(number);
13261
+ }
13262
+
13263
+ _onAuthenticated() {
13264
+ this.parseLinks();
13265
+ }
13266
+
13267
+ _onMessage(event ) {
13268
+ if (!event.data) {
13269
+ return;
13270
+ }
13271
+
13272
+ switch (event.data.type) {
13273
+ case SDK_ON_CALL_MADE:
13274
+ this.onCallMade(event.data.callSession);
13275
+ break;
13276
+ case SDK_CALL_ENDED: {
13277
+ const { callSession, content, direction, userExtension } = event.data;
13278
+ this.onCallEnded(callSession, content, direction, userExtension);
13279
+ break;
13280
+ }
13281
+ case SDK_CALL_INCOMING:
13282
+ this.onCallIncoming(event.data.callSession);
13283
+ break;
13284
+ case SDK_AUTHENTICATED:
13285
+ // $FlowFixMe
13286
+ this._onAuthenticated(event.data.session);
13287
+ this.onAuthenticated(event.data.session);
13288
+ break;
13289
+ }
13290
+ }
13291
+ }
13292
+
13293
+ var Softphone$1 = new Softphone();
13294
+
13088
13295
  /* global window */
13089
13296
 
13090
13297
  const Wazo = {
@@ -13105,6 +13312,7 @@ const Wazo = {
13105
13312
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
13106
13313
  Features: Features$1,
13107
13314
  Checker,
13315
+ Softphone: Softphone$1,
13108
13316
 
13109
13317
  // Domain
13110
13318
  domain: {