@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
@@ -2859,13 +2859,9 @@ class IssueReporter {
2859
2859
 
2860
2860
  setTimeout(() => {
2861
2861
  if (isArray) {
2862
- payload = payload.map(message => {
2863
- message._retry = retry + 1;
2864
- return message;
2865
- });
2866
- } else {
2867
- // $FlowFixMe
2868
- payload._retry = retry + 1;
2862
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2863
+ } else if (payload && typeof payload === 'object') {
2864
+ payload = this._writeRetryCount(payload, retry + 1);
2869
2865
  }
2870
2866
 
2871
2867
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2873,6 +2869,15 @@ class IssueReporter {
2873
2869
  });
2874
2870
  }
2875
2871
 
2872
+ _writeRetryCount(message , count ) {
2873
+ if (message && typeof message === 'object') {
2874
+ // $FlowFixMe
2875
+ message._retry = count;
2876
+ }
2877
+
2878
+ return message;
2879
+ }
2880
+
2876
2881
  _isLevelAbove(level1 , level2 ) {
2877
2882
  const index1 = LOG_LEVELS.indexOf(level1);
2878
2883
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -3214,9 +3219,12 @@ var authMethods = (client , baseUrl ) => ({
3214
3219
  expiration: expiration || DETAULT_EXPIRATION,
3215
3220
  refresh_token: refreshToken,
3216
3221
  client_id: client.clientId,
3217
- tenant_id: tenantId,
3218
3222
  };
3219
3223
 
3224
+ if (tenantId) {
3225
+ body.tenant_id = tenantId;
3226
+ }
3227
+
3220
3228
  const headers = {
3221
3229
  'Content-Type': 'application/json',
3222
3230
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4988,6 +4996,7 @@ class ApiClient {
4988
4996
 
4989
4997
 
4990
4998
 
4999
+
4991
5000
 
4992
5001
 
4993
5002
 
@@ -5040,23 +5049,31 @@ class ApiClient {
5040
5049
  return null;
5041
5050
  }
5042
5051
 
5043
- const session = await this.auth.refreshToken(
5044
- this.refreshToken,
5045
- this.refreshBackend,
5046
- this.refreshExpiration,
5047
- this.isMobile,
5048
- this.refreshTenantId,
5049
- );
5050
-
5051
- logger$1.info('token refreshed', { token: session.token });
5052
+ try {
5053
+ const session = await this.auth.refreshToken(
5054
+ this.refreshToken,
5055
+ this.refreshBackend,
5056
+ this.refreshExpiration,
5057
+ this.isMobile,
5058
+ this.refreshTenantId,
5059
+ );
5060
+
5061
+ logger$1.info('token refreshed', { token: session.token });
5062
+
5063
+ if (this.onRefreshToken) {
5064
+ this.onRefreshToken(session.token, session);
5065
+ }
5052
5066
 
5053
- if (this.onRefreshToken) {
5054
- this.onRefreshToken(session.token, session);
5055
- }
5067
+ this.setToken(session.token);
5056
5068
 
5057
- this.setToken(session.token);
5069
+ return session.token;
5070
+ } catch (error) {
5071
+ logger$1.error('token refresh, error', error);
5058
5072
 
5059
- return session.token;
5073
+ if (this.onRefreshTokenError) {
5074
+ this.onRefreshTokenError(error);
5075
+ }
5076
+ }
5060
5077
  }
5061
5078
 
5062
5079
  setToken(token ) {
@@ -5079,6 +5096,10 @@ class ApiClient {
5079
5096
  this.onRefreshToken = onRefreshToken;
5080
5097
  }
5081
5098
 
5099
+ setOnRefreshTokenError(callback ) {
5100
+ this.onRefreshTokenError = callback;
5101
+ }
5102
+
5082
5103
  setRefreshExpiration(refreshExpiration ) {
5083
5104
  this.refreshExpiration = refreshExpiration;
5084
5105
  }
@@ -5114,7 +5135,9 @@ global.wazoClients = global.wazoClients || {};
5114
5135
  global.wazoClientId = global.wazoClientId || {};
5115
5136
  global.wazoClientToken = global.wazoClientToken || {};
5116
5137
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5138
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5117
5139
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5140
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5118
5141
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5119
5142
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5120
5143
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5130,12 +5153,20 @@ const fillClient = (apiClient ) => {
5130
5153
 
5131
5154
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5132
5155
 
5156
+ apiClient.setRefreshTenantId(
5157
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5158
+ );
5159
+
5133
5160
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5134
5161
 
5135
5162
  apiClient.setOnRefreshToken(
5136
5163
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5137
5164
  );
5138
5165
 
5166
+ apiClient.setOnRefreshTokenError(
5167
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5168
+ );
5169
+
5139
5170
  apiClient.setRefreshExpiration(
5140
5171
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5141
5172
  );
@@ -5149,7 +5180,7 @@ const fillClient = (apiClient ) => {
5149
5180
  return apiClient;
5150
5181
  };
5151
5182
 
5152
- var getApiClient = (forServer ) => {
5183
+ var getApiClient = (forServer = null) => {
5153
5184
  const server = forServer || global.wazoCurrentServer || '';
5154
5185
  if (server in global.wazoClients) {
5155
5186
  return fillClient(global.wazoClients[server]);
@@ -811,13 +811,9 @@ class IssueReporter {
811
811
 
812
812
  setTimeout(() => {
813
813
  if (isArray) {
814
- payload = payload.map(message => {
815
- message._retry = retry + 1;
816
- return message;
817
- });
818
- } else {
819
- // $FlowFixMe
820
- payload._retry = retry + 1;
814
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
815
+ } else if (payload && typeof payload === 'object') {
816
+ payload = this._writeRetryCount(payload, retry + 1);
821
817
  }
822
818
 
823
819
  this._sendDebugToGrafana(payload, retry + 1);
@@ -825,6 +821,15 @@ class IssueReporter {
825
821
  });
826
822
  }
827
823
 
824
+ _writeRetryCount(message , count ) {
825
+ if (message && typeof message === 'object') {
826
+ // $FlowFixMe
827
+ message._retry = count;
828
+ }
829
+
830
+ return message;
831
+ }
832
+
828
833
  _isLevelAbove(level1 , level2 ) {
829
834
  const index1 = LOG_LEVELS.indexOf(level1);
830
835
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -897,7 +902,9 @@ global.wazoClients = global.wazoClients || {};
897
902
  global.wazoClientId = global.wazoClientId || {};
898
903
  global.wazoClientToken = global.wazoClientToken || {};
899
904
  global.wazoRefreshToken = global.wazoRefreshToken || {};
905
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
900
906
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
907
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
901
908
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
902
909
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
903
910
  global.wazoIsMobile = global.wazoIsMobile || {};
package/lib/index.js CHANGED
@@ -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' } : {}),
@@ -3987,7 +3995,9 @@ global.wazoClients = global.wazoClients || {};
3987
3995
  global.wazoClientId = global.wazoClientId || {};
3988
3996
  global.wazoClientToken = global.wazoClientToken || {};
3989
3997
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3998
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3990
3999
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4000
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3991
4001
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3992
4002
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3993
4003
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4009,10 +4019,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
4009
4019
  global.wazoRefreshToken[forServer] = newRefreshToken;
4010
4020
  };
4011
4021
 
4022
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4023
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4024
+ };
4025
+
4012
4026
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4013
4027
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4014
4028
  };
4015
4029
 
4030
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4031
+ global.wazoOnRefreshTokenError[forServer] = callback;
4032
+ };
4033
+
4016
4034
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4017
4035
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4018
4036
  };
@@ -4031,12 +4049,20 @@ const fillClient = (apiClient ) => {
4031
4049
 
4032
4050
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4033
4051
 
4052
+ apiClient.setRefreshTenantId(
4053
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4054
+ );
4055
+
4034
4056
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4035
4057
 
4036
4058
  apiClient.setOnRefreshToken(
4037
4059
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4038
4060
  );
4039
4061
 
4062
+ apiClient.setOnRefreshTokenError(
4063
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4064
+ );
4065
+
4040
4066
  apiClient.setRefreshExpiration(
4041
4067
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4042
4068
  );
@@ -4050,7 +4076,7 @@ const fillClient = (apiClient ) => {
4050
4076
  return apiClient;
4051
4077
  };
4052
4078
 
4053
- var getApiClient = (forServer ) => {
4079
+ var getApiClient = (forServer = null) => {
4054
4080
  const server = forServer || global.wazoCurrentServer || '';
4055
4081
  if (server in global.wazoClients) {
4056
4082
  return fillClient(global.wazoClients[server]);
@@ -5510,6 +5536,7 @@ class ApiClient {
5510
5536
 
5511
5537
 
5512
5538
 
5539
+
5513
5540
 
5514
5541
 
5515
5542
 
@@ -5562,23 +5589,31 @@ class ApiClient {
5562
5589
  return null;
5563
5590
  }
5564
5591
 
5565
- const session = await this.auth.refreshToken(
5566
- this.refreshToken,
5567
- this.refreshBackend,
5568
- this.refreshExpiration,
5569
- this.isMobile,
5570
- this.refreshTenantId,
5571
- );
5592
+ try {
5593
+ const session = await this.auth.refreshToken(
5594
+ this.refreshToken,
5595
+ this.refreshBackend,
5596
+ this.refreshExpiration,
5597
+ this.isMobile,
5598
+ this.refreshTenantId,
5599
+ );
5572
5600
 
5573
- logger$a.info('token refreshed', { token: session.token });
5601
+ logger$a.info('token refreshed', { token: session.token });
5574
5602
 
5575
- if (this.onRefreshToken) {
5576
- this.onRefreshToken(session.token, session);
5577
- }
5603
+ if (this.onRefreshToken) {
5604
+ this.onRefreshToken(session.token, session);
5605
+ }
5578
5606
 
5579
- this.setToken(session.token);
5607
+ this.setToken(session.token);
5580
5608
 
5581
- return session.token;
5609
+ return session.token;
5610
+ } catch (error) {
5611
+ logger$a.error('token refresh, error', error);
5612
+
5613
+ if (this.onRefreshTokenError) {
5614
+ this.onRefreshTokenError(error);
5615
+ }
5616
+ }
5582
5617
  }
5583
5618
 
5584
5619
  setToken(token ) {
@@ -5601,6 +5636,10 @@ class ApiClient {
5601
5636
  this.onRefreshToken = onRefreshToken;
5602
5637
  }
5603
5638
 
5639
+ setOnRefreshTokenError(callback ) {
5640
+ this.onRefreshTokenError = callback;
5641
+ }
5642
+
5604
5643
  setRefreshExpiration(refreshExpiration ) {
5605
5644
  this.refreshExpiration = refreshExpiration;
5606
5645
  }
@@ -6973,8 +7012,10 @@ class WebRTCClient extends Emitter {
6973
7012
  conference: isConference,
6974
7013
  };
6975
7014
 
6976
- // Avoid sdh to created a new stream
6977
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7015
+ // Avoid sdh to create a new stream
7016
+ if (session.sessionDescriptionHandler) {
7017
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7018
+ }
6978
7019
 
6979
7020
  // Send re-INVITE
6980
7021
  return session.invite(options);
@@ -8763,7 +8804,7 @@ class WebSocketClient extends Emitter {
8763
8804
  this.close();
8764
8805
  }
8765
8806
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
8766
- logger$8.log('Wazo WS url computed to reconnect', { url });
8807
+ logger$8.info('Wazo WS url computed to reconnect', { url });
8767
8808
 
8768
8809
  return url;
8769
8810
  }
@@ -11732,6 +11773,7 @@ class Auth {
11732
11773
 
11733
11774
 
11734
11775
 
11776
+
11735
11777
 
11736
11778
 
11737
11779
 
@@ -11769,6 +11811,14 @@ class Auth {
11769
11811
  this.onRefreshTokenCallback(token, session);
11770
11812
  }
11771
11813
  });
11814
+
11815
+ setOnRefreshTokenError(error => {
11816
+ logger$5.error('on refresh token error', error);
11817
+
11818
+ if (this.onRefreshTokenCallbackError) {
11819
+ this.onRefreshTokenCallbackError(error);
11820
+ }
11821
+ });
11772
11822
  }
11773
11823
 
11774
11824
  setFetchOptions(options ) {
@@ -11857,6 +11907,10 @@ class Auth {
11857
11907
  this.onRefreshTokenCallback = callback;
11858
11908
  }
11859
11909
 
11910
+ setOnRefreshTokenError(callback ) {
11911
+ this.onRefreshTokenCallbackError = callback;
11912
+ }
11913
+
11860
11914
  checkAuthorizations(session , authorizationName ) {
11861
11915
  if (!authorizationName) {
11862
11916
  return;
@@ -11889,6 +11943,12 @@ class Auth {
11889
11943
  setRefreshToken(refreshToken);
11890
11944
  }
11891
11945
 
11946
+ setRefreshTenantId(refreshTenantId ) {
11947
+ setRefreshTenantId(refreshTenantId);
11948
+
11949
+ getApiClient().setRefreshTenantId(refreshTenantId);
11950
+ }
11951
+
11892
11952
  forceRefreshToken() {
11893
11953
  getApiClient().forceRefreshToken();
11894
11954
  }
@@ -14058,6 +14118,153 @@ const createLocalVideoStream = async (options ) => createLocalStream('vid
14058
14118
 
14059
14119
  const createLocalAudioStream = async (options ) => createLocalStream('audio', options);
14060
14120
 
14121
+ //
14122
+ /* eslint-disable no-unused-vars */
14123
+ /* global window, document */
14124
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14125
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14126
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14127
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14128
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14129
+
14130
+ class Softphone {
14131
+ url = 'https://softphone.wazo.io';
14132
+ width = 500;
14133
+ height = 600;
14134
+ displayed = false;
14135
+ iframe = null;
14136
+
14137
+ onLinkEnabled(link ) {}
14138
+
14139
+ onCallMade(call ) {}
14140
+ onCallIncoming(call ) {}
14141
+ onCallEnded(call , card , direction , fromExtension ) {}
14142
+ onAuthenticated(session ) {}
14143
+
14144
+ init(url , width , height ) {
14145
+ if (url) {
14146
+ this.url = url;
14147
+ }
14148
+ if (width) {
14149
+ this.width = width;
14150
+ }
14151
+ if (height) {
14152
+ this.height = height;
14153
+ }
14154
+
14155
+ window.addEventListener('message', this._onMessage.bind(this), false);
14156
+
14157
+ this._createIframe();
14158
+ }
14159
+
14160
+ parseLinks() {
14161
+ const links = this._getLinks();
14162
+
14163
+ links.forEach(link => {
14164
+ link.setAttribute('data-wazo-parsed', true);
14165
+ link.addEventListener('click', this._onLinkClick.bind(this));
14166
+ this.onLinkEnabled(link);
14167
+ });
14168
+ }
14169
+
14170
+ makeCall(number ) {
14171
+ this.displaySoftphone();
14172
+
14173
+ if (this.iframe) {
14174
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14175
+ }
14176
+ }
14177
+
14178
+ toggleSoftphoneDisplay() {
14179
+ if (this.displayed) {
14180
+ this.hideSoftphone();
14181
+ } else {
14182
+ this.displaySoftphone();
14183
+ }
14184
+
14185
+ this.displayed = !this.displayed;
14186
+ }
14187
+
14188
+ displaySoftphone() {
14189
+ if (!this.iframe) {
14190
+ this._createIframe();
14191
+ }
14192
+
14193
+ if (this.iframe) {
14194
+ this.iframe.style.display = 'block';
14195
+ }
14196
+ }
14197
+
14198
+ hideSoftphone() {
14199
+ if (this.iframe) {
14200
+ this.iframe.style.display = 'none';
14201
+ }
14202
+ }
14203
+
14204
+ _createIframe() {
14205
+ this.iframe = document.createElement('iframe');
14206
+ // $FlowFixMe
14207
+ this.iframe.width = this.width;
14208
+ // $FlowFixMe
14209
+ this.iframe.height = this.height;
14210
+ // $FlowFixMe
14211
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
14212
+ this.iframe.style.position = 'absolute';
14213
+ this.iframe.style.left = '0';
14214
+ this.iframe.style.bottom = '0';
14215
+ this.iframe.style.border = '1px solid #aaa';
14216
+ this.iframe.src = this.url;
14217
+ this.iframe.style.display = 'none';
14218
+ this.iframe.id = 'wazo-softphone';
14219
+
14220
+ // $FlowFixMe
14221
+ document.body.appendChild(this.iframe);
14222
+ }
14223
+
14224
+ _getLinks() {
14225
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
14226
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
14227
+ }
14228
+
14229
+ _onLinkClick(e ) {
14230
+ e.preventDefault();
14231
+ const number = e.target.href.split(':')[1];
14232
+
14233
+ this.makeCall(number);
14234
+ }
14235
+
14236
+ _onAuthenticated() {
14237
+ this.parseLinks();
14238
+ }
14239
+
14240
+ _onMessage(event ) {
14241
+ if (!event.data) {
14242
+ return;
14243
+ }
14244
+
14245
+ switch (event.data.type) {
14246
+ case SDK_ON_CALL_MADE:
14247
+ this.onCallMade(event.data.callSession);
14248
+ break;
14249
+ case SDK_CALL_ENDED: {
14250
+ const { callSession, content, direction, userExtension } = event.data;
14251
+ this.onCallEnded(callSession, content, direction, userExtension);
14252
+ break;
14253
+ }
14254
+ case SDK_CALL_INCOMING:
14255
+ this.onCallIncoming(event.data.callSession);
14256
+ break;
14257
+ case SDK_AUTHENTICATED:
14258
+ // $FlowFixMe
14259
+ this._onAuthenticated(event.data.session);
14260
+ this.onAuthenticated(event.data.session);
14261
+ break;
14262
+ }
14263
+ }
14264
+ }
14265
+
14266
+ var Softphone$1 = new Softphone();
14267
+
14061
14268
  /* global window */
14062
14269
 
14063
14270
  const Wazo = {
@@ -14078,6 +14285,7 @@ const Wazo = {
14078
14285
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
14079
14286
  Features: Features$1,
14080
14287
  Checker,
14288
+ Softphone: Softphone$1,
14081
14289
 
14082
14290
  // Domain
14083
14291
  domain: {
@@ -373,13 +373,9 @@ class IssueReporter {
373
373
 
374
374
  setTimeout(() => {
375
375
  if (isArray) {
376
- payload = payload.map(message => {
377
- message._retry = retry + 1;
378
- return message;
379
- });
380
- } else {
381
- // $FlowFixMe
382
- payload._retry = retry + 1;
376
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
377
+ } else if (payload && typeof payload === 'object') {
378
+ payload = this._writeRetryCount(payload, retry + 1);
383
379
  }
384
380
 
385
381
  this._sendDebugToGrafana(payload, retry + 1);
@@ -387,6 +383,15 @@ class IssueReporter {
387
383
  });
388
384
  }
389
385
 
386
+ _writeRetryCount(message , count ) {
387
+ if (message && typeof message === 'object') {
388
+ // $FlowFixMe
389
+ message._retry = count;
390
+ }
391
+
392
+ return message;
393
+ }
394
+
390
395
  _isLevelAbove(level1 , level2 ) {
391
396
  const index1 = LOG_LEVELS.indexOf(level1);
392
397
  const index2 = LOG_LEVELS.indexOf(level2);