@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
@@ -706,13 +706,9 @@ class IssueReporter {
706
706
 
707
707
  setTimeout(() => {
708
708
  if (isArray) {
709
- payload = payload.map(message => {
710
- message._retry = retry + 1;
711
- return message;
712
- });
713
- } else {
714
- // $FlowFixMe
715
- payload._retry = retry + 1;
709
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
710
+ } else if (payload && typeof payload === 'object') {
711
+ payload = this._writeRetryCount(payload, retry + 1);
716
712
  }
717
713
 
718
714
  this._sendDebugToGrafana(payload, retry + 1);
@@ -720,6 +716,15 @@ class IssueReporter {
720
716
  });
721
717
  }
722
718
 
719
+ _writeRetryCount(message , count ) {
720
+ if (message && typeof message === 'object') {
721
+ // $FlowFixMe
722
+ message._retry = count;
723
+ }
724
+
725
+ return message;
726
+ }
727
+
723
728
  _isLevelAbove(level1 , level2 ) {
724
729
  const index1 = LOG_LEVELS.indexOf(level1);
725
730
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2291,9 +2296,12 @@ var authMethods = (client , baseUrl ) => ({
2291
2296
  expiration: expiration || DETAULT_EXPIRATION,
2292
2297
  refresh_token: refreshToken,
2293
2298
  client_id: client.clientId,
2294
- tenant_id: tenantId,
2295
2299
  };
2296
2300
 
2301
+ if (tenantId) {
2302
+ body.tenant_id = tenantId;
2303
+ }
2304
+
2297
2305
  const headers = {
2298
2306
  'Content-Type': 'application/json',
2299
2307
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5415,6 +5423,7 @@ class ApiClient {
5415
5423
 
5416
5424
 
5417
5425
 
5426
+
5418
5427
 
5419
5428
 
5420
5429
 
@@ -5467,23 +5476,31 @@ class ApiClient {
5467
5476
  return null;
5468
5477
  }
5469
5478
 
5470
- const session = await this.auth.refreshToken(
5471
- this.refreshToken,
5472
- this.refreshBackend,
5473
- this.refreshExpiration,
5474
- this.isMobile,
5475
- this.refreshTenantId,
5476
- );
5479
+ try {
5480
+ const session = await this.auth.refreshToken(
5481
+ this.refreshToken,
5482
+ this.refreshBackend,
5483
+ this.refreshExpiration,
5484
+ this.isMobile,
5485
+ this.refreshTenantId,
5486
+ );
5477
5487
 
5478
- logger$a.info('token refreshed', { token: session.token });
5488
+ logger$a.info('token refreshed', { token: session.token });
5479
5489
 
5480
- if (this.onRefreshToken) {
5481
- this.onRefreshToken(session.token, session);
5482
- }
5490
+ if (this.onRefreshToken) {
5491
+ this.onRefreshToken(session.token, session);
5492
+ }
5483
5493
 
5484
- this.setToken(session.token);
5494
+ this.setToken(session.token);
5495
+
5496
+ return session.token;
5497
+ } catch (error) {
5498
+ logger$a.error('token refresh, error', error);
5485
5499
 
5486
- return session.token;
5500
+ if (this.onRefreshTokenError) {
5501
+ this.onRefreshTokenError(error);
5502
+ }
5503
+ }
5487
5504
  }
5488
5505
 
5489
5506
  setToken(token ) {
@@ -5506,6 +5523,10 @@ class ApiClient {
5506
5523
  this.onRefreshToken = onRefreshToken;
5507
5524
  }
5508
5525
 
5526
+ setOnRefreshTokenError(callback ) {
5527
+ this.onRefreshTokenError = callback;
5528
+ }
5529
+
5509
5530
  setRefreshExpiration(refreshExpiration ) {
5510
5531
  this.refreshExpiration = refreshExpiration;
5511
5532
  }
@@ -5541,7 +5562,9 @@ global.wazoClients = global.wazoClients || {};
5541
5562
  global.wazoClientId = global.wazoClientId || {};
5542
5563
  global.wazoClientToken = global.wazoClientToken || {};
5543
5564
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5565
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5544
5566
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5567
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5545
5568
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5546
5569
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5547
5570
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5563,10 +5586,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5563
5586
  global.wazoRefreshToken[forServer] = newRefreshToken;
5564
5587
  };
5565
5588
 
5589
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5590
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5591
+ };
5592
+
5566
5593
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5567
5594
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5568
5595
  };
5569
5596
 
5597
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5598
+ global.wazoOnRefreshTokenError[forServer] = callback;
5599
+ };
5600
+
5570
5601
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5571
5602
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5572
5603
  };
@@ -5585,12 +5616,20 @@ const fillClient = (apiClient ) => {
5585
5616
 
5586
5617
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5587
5618
 
5619
+ apiClient.setRefreshTenantId(
5620
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5621
+ );
5622
+
5588
5623
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5589
5624
 
5590
5625
  apiClient.setOnRefreshToken(
5591
5626
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5592
5627
  );
5593
5628
 
5629
+ apiClient.setOnRefreshTokenError(
5630
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5631
+ );
5632
+
5594
5633
  apiClient.setRefreshExpiration(
5595
5634
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5596
5635
  );
@@ -5604,7 +5643,7 @@ const fillClient = (apiClient ) => {
5604
5643
  return apiClient;
5605
5644
  };
5606
5645
 
5607
- var getApiClient = (forServer ) => {
5646
+ var getApiClient = (forServer = null) => {
5608
5647
  const server = forServer || global.wazoCurrentServer || '';
5609
5648
  if (server in global.wazoClients) {
5610
5649
  return fillClient(global.wazoClients[server]);
@@ -5631,6 +5670,7 @@ class Auth {
5631
5670
 
5632
5671
 
5633
5672
 
5673
+
5634
5674
 
5635
5675
 
5636
5676
 
@@ -5668,6 +5708,14 @@ class Auth {
5668
5708
  this.onRefreshTokenCallback(token, session);
5669
5709
  }
5670
5710
  });
5711
+
5712
+ setOnRefreshTokenError(error => {
5713
+ logger$9.error('on refresh token error', error);
5714
+
5715
+ if (this.onRefreshTokenCallbackError) {
5716
+ this.onRefreshTokenCallbackError(error);
5717
+ }
5718
+ });
5671
5719
  }
5672
5720
 
5673
5721
  setFetchOptions(options ) {
@@ -5756,6 +5804,10 @@ class Auth {
5756
5804
  this.onRefreshTokenCallback = callback;
5757
5805
  }
5758
5806
 
5807
+ setOnRefreshTokenError(callback ) {
5808
+ this.onRefreshTokenCallbackError = callback;
5809
+ }
5810
+
5759
5811
  checkAuthorizations(session , authorizationName ) {
5760
5812
  if (!authorizationName) {
5761
5813
  return;
@@ -5788,6 +5840,12 @@ class Auth {
5788
5840
  setRefreshToken(refreshToken);
5789
5841
  }
5790
5842
 
5843
+ setRefreshTenantId(refreshTenantId ) {
5844
+ setRefreshTenantId(refreshTenantId);
5845
+
5846
+ getApiClient().setRefreshTenantId(refreshTenantId);
5847
+ }
5848
+
5791
5849
  forceRefreshToken() {
5792
5850
  getApiClient().forceRefreshToken();
5793
5851
  }
@@ -7422,8 +7480,10 @@ class WebRTCClient extends Emitter {
7422
7480
  conference: isConference,
7423
7481
  };
7424
7482
 
7425
- // Avoid sdh to created a new stream
7426
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7483
+ // Avoid sdh to create a new stream
7484
+ if (session.sessionDescriptionHandler) {
7485
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7486
+ }
7427
7487
 
7428
7488
  // Send re-INVITE
7429
7489
  return session.invite(options);
@@ -11434,7 +11494,7 @@ class WebSocketClient extends Emitter {
11434
11494
  this.close();
11435
11495
  }
11436
11496
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
11437
- logger$5.log('Wazo WS url computed to reconnect', { url });
11497
+ logger$5.info('Wazo WS url computed to reconnect', { url });
11438
11498
 
11439
11499
  return url;
11440
11500
  }
@@ -12778,6 +12838,153 @@ class Checker {
12778
12838
  }
12779
12839
  }
12780
12840
 
12841
+ //
12842
+ /* eslint-disable no-unused-vars */
12843
+ /* global window, document */
12844
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
12845
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
12846
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
12847
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
12848
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
12849
+
12850
+ class Softphone {
12851
+ url = 'https://softphone.wazo.io';
12852
+ width = 500;
12853
+ height = 600;
12854
+ displayed = false;
12855
+ iframe = null;
12856
+
12857
+ onLinkEnabled(link ) {}
12858
+
12859
+ onCallMade(call ) {}
12860
+ onCallIncoming(call ) {}
12861
+ onCallEnded(call , card , direction , fromExtension ) {}
12862
+ onAuthenticated(session ) {}
12863
+
12864
+ init(url , width , height ) {
12865
+ if (url) {
12866
+ this.url = url;
12867
+ }
12868
+ if (width) {
12869
+ this.width = width;
12870
+ }
12871
+ if (height) {
12872
+ this.height = height;
12873
+ }
12874
+
12875
+ window.addEventListener('message', this._onMessage.bind(this), false);
12876
+
12877
+ this._createIframe();
12878
+ }
12879
+
12880
+ parseLinks() {
12881
+ const links = this._getLinks();
12882
+
12883
+ links.forEach(link => {
12884
+ link.setAttribute('data-wazo-parsed', true);
12885
+ link.addEventListener('click', this._onLinkClick.bind(this));
12886
+ this.onLinkEnabled(link);
12887
+ });
12888
+ }
12889
+
12890
+ makeCall(number ) {
12891
+ this.displaySoftphone();
12892
+
12893
+ if (this.iframe) {
12894
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
12895
+ }
12896
+ }
12897
+
12898
+ toggleSoftphoneDisplay() {
12899
+ if (this.displayed) {
12900
+ this.hideSoftphone();
12901
+ } else {
12902
+ this.displaySoftphone();
12903
+ }
12904
+
12905
+ this.displayed = !this.displayed;
12906
+ }
12907
+
12908
+ displaySoftphone() {
12909
+ if (!this.iframe) {
12910
+ this._createIframe();
12911
+ }
12912
+
12913
+ if (this.iframe) {
12914
+ this.iframe.style.display = 'block';
12915
+ }
12916
+ }
12917
+
12918
+ hideSoftphone() {
12919
+ if (this.iframe) {
12920
+ this.iframe.style.display = 'none';
12921
+ }
12922
+ }
12923
+
12924
+ _createIframe() {
12925
+ this.iframe = document.createElement('iframe');
12926
+ // $FlowFixMe
12927
+ this.iframe.width = this.width;
12928
+ // $FlowFixMe
12929
+ this.iframe.height = this.height;
12930
+ // $FlowFixMe
12931
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
12932
+ this.iframe.style.position = 'absolute';
12933
+ this.iframe.style.left = '0';
12934
+ this.iframe.style.bottom = '0';
12935
+ this.iframe.style.border = '1px solid #aaa';
12936
+ this.iframe.src = this.url;
12937
+ this.iframe.style.display = 'none';
12938
+ this.iframe.id = 'wazo-softphone';
12939
+
12940
+ // $FlowFixMe
12941
+ document.body.appendChild(this.iframe);
12942
+ }
12943
+
12944
+ _getLinks() {
12945
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
12946
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
12947
+ }
12948
+
12949
+ _onLinkClick(e ) {
12950
+ e.preventDefault();
12951
+ const number = e.target.href.split(':')[1];
12952
+
12953
+ this.makeCall(number);
12954
+ }
12955
+
12956
+ _onAuthenticated() {
12957
+ this.parseLinks();
12958
+ }
12959
+
12960
+ _onMessage(event ) {
12961
+ if (!event.data) {
12962
+ return;
12963
+ }
12964
+
12965
+ switch (event.data.type) {
12966
+ case SDK_ON_CALL_MADE:
12967
+ this.onCallMade(event.data.callSession);
12968
+ break;
12969
+ case SDK_CALL_ENDED: {
12970
+ const { callSession, content, direction, userExtension } = event.data;
12971
+ this.onCallEnded(callSession, content, direction, userExtension);
12972
+ break;
12973
+ }
12974
+ case SDK_CALL_INCOMING:
12975
+ this.onCallIncoming(event.data.callSession);
12976
+ break;
12977
+ case SDK_AUTHENTICATED:
12978
+ // $FlowFixMe
12979
+ this._onAuthenticated(event.data.session);
12980
+ this.onAuthenticated(event.data.session);
12981
+ break;
12982
+ }
12983
+ }
12984
+ }
12985
+
12986
+ var Softphone$1 = new Softphone();
12987
+
12781
12988
  /* global window */
12782
12989
 
12783
12990
  const Wazo = {
@@ -12798,6 +13005,7 @@ const Wazo = {
12798
13005
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
12799
13006
  Features: Features$1,
12800
13007
  Checker,
13008
+ Softphone: Softphone$1,
12801
13009
 
12802
13010
  // Domain
12803
13011
  domain: {