@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
package/lib/api-client.js CHANGED
@@ -402,13 +402,9 @@ class IssueReporter {
402
402
 
403
403
  setTimeout(() => {
404
404
  if (isArray) {
405
- payload = payload.map(message => {
406
- message._retry = retry + 1;
407
- return message;
408
- });
409
- } else {
410
- // $FlowFixMe
411
- payload._retry = retry + 1;
405
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
406
+ } else if (payload && typeof payload === 'object') {
407
+ payload = this._writeRetryCount(payload, retry + 1);
412
408
  }
413
409
 
414
410
  this._sendDebugToGrafana(payload, retry + 1);
@@ -416,6 +412,15 @@ class IssueReporter {
416
412
  });
417
413
  }
418
414
 
415
+ _writeRetryCount(message , count ) {
416
+ if (message && typeof message === 'object') {
417
+ // $FlowFixMe
418
+ message._retry = count;
419
+ }
420
+
421
+ return message;
422
+ }
423
+
419
424
  _isLevelAbove(level1 , level2 ) {
420
425
  const index1 = LOG_LEVELS.indexOf(level1);
421
426
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2251,9 +2256,12 @@ var authMethods = (client , baseUrl ) => ({
2251
2256
  expiration: expiration || DETAULT_EXPIRATION,
2252
2257
  refresh_token: refreshToken,
2253
2258
  client_id: client.clientId,
2254
- tenant_id: tenantId,
2255
2259
  };
2256
2260
 
2261
+ if (tenantId) {
2262
+ body.tenant_id = tenantId;
2263
+ }
2264
+
2257
2265
  const headers = {
2258
2266
  'Content-Type': 'application/json',
2259
2267
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3541,7 +3549,9 @@ global.wazoClients = global.wazoClients || {};
3541
3549
  global.wazoClientId = global.wazoClientId || {};
3542
3550
  global.wazoClientToken = global.wazoClientToken || {};
3543
3551
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3552
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3544
3553
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3554
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3545
3555
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3546
3556
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3547
3557
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4587,6 +4597,7 @@ class ApiClient {
4587
4597
 
4588
4598
 
4589
4599
 
4600
+
4590
4601
 
4591
4602
 
4592
4603
 
@@ -4639,23 +4650,31 @@ class ApiClient {
4639
4650
  return null;
4640
4651
  }
4641
4652
 
4642
- const session = await this.auth.refreshToken(
4643
- this.refreshToken,
4644
- this.refreshBackend,
4645
- this.refreshExpiration,
4646
- this.isMobile,
4647
- this.refreshTenantId,
4648
- );
4649
-
4650
- logger.info('token refreshed', { token: session.token });
4653
+ try {
4654
+ const session = await this.auth.refreshToken(
4655
+ this.refreshToken,
4656
+ this.refreshBackend,
4657
+ this.refreshExpiration,
4658
+ this.isMobile,
4659
+ this.refreshTenantId,
4660
+ );
4661
+
4662
+ logger.info('token refreshed', { token: session.token });
4663
+
4664
+ if (this.onRefreshToken) {
4665
+ this.onRefreshToken(session.token, session);
4666
+ }
4651
4667
 
4652
- if (this.onRefreshToken) {
4653
- this.onRefreshToken(session.token, session);
4654
- }
4668
+ this.setToken(session.token);
4655
4669
 
4656
- this.setToken(session.token);
4670
+ return session.token;
4671
+ } catch (error) {
4672
+ logger.error('token refresh, error', error);
4657
4673
 
4658
- return session.token;
4674
+ if (this.onRefreshTokenError) {
4675
+ this.onRefreshTokenError(error);
4676
+ }
4677
+ }
4659
4678
  }
4660
4679
 
4661
4680
  setToken(token ) {
@@ -4678,6 +4697,10 @@ class ApiClient {
4678
4697
  this.onRefreshToken = onRefreshToken;
4679
4698
  }
4680
4699
 
4700
+ setOnRefreshTokenError(callback ) {
4701
+ this.onRefreshTokenError = callback;
4702
+ }
4703
+
4681
4704
  setRefreshExpiration(refreshExpiration ) {
4682
4705
  this.refreshExpiration = refreshExpiration;
4683
4706
  }
@@ -424,13 +424,9 @@ class IssueReporter {
424
424
 
425
425
  setTimeout(() => {
426
426
  if (isArray) {
427
- payload = payload.map(message => {
428
- message._retry = retry + 1;
429
- return message;
430
- });
431
- } else {
432
- // $FlowFixMe
433
- payload._retry = retry + 1;
427
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
428
+ } else if (payload && typeof payload === 'object') {
429
+ payload = this._writeRetryCount(payload, retry + 1);
434
430
  }
435
431
 
436
432
  this._sendDebugToGrafana(payload, retry + 1);
@@ -438,6 +434,15 @@ class IssueReporter {
438
434
  });
439
435
  }
440
436
 
437
+ _writeRetryCount(message , count ) {
438
+ if (message && typeof message === 'object') {
439
+ // $FlowFixMe
440
+ message._retry = count;
441
+ }
442
+
443
+ return message;
444
+ }
445
+
441
446
  _isLevelAbove(level1 , level2 ) {
442
447
  const index1 = LOG_LEVELS.indexOf(level1);
443
448
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2273,9 +2278,12 @@ var authMethods = (client , baseUrl ) => ({
2273
2278
  expiration: expiration || DETAULT_EXPIRATION,
2274
2279
  refresh_token: refreshToken,
2275
2280
  client_id: client.clientId,
2276
- tenant_id: tenantId,
2277
2281
  };
2278
2282
 
2283
+ if (tenantId) {
2284
+ body.tenant_id = tenantId;
2285
+ }
2286
+
2279
2287
  const headers = {
2280
2288
  'Content-Type': 'application/json',
2281
2289
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3589,7 +3597,9 @@ global.wazoClients = global.wazoClients || {};
3589
3597
  global.wazoClientId = global.wazoClientId || {};
3590
3598
  global.wazoClientToken = global.wazoClientToken || {};
3591
3599
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3600
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3592
3601
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3602
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3593
3603
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3594
3604
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3595
3605
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4635,6 +4645,7 @@ class ApiClient {
4635
4645
 
4636
4646
 
4637
4647
 
4648
+
4638
4649
 
4639
4650
 
4640
4651
 
@@ -4687,23 +4698,31 @@ class ApiClient {
4687
4698
  return null;
4688
4699
  }
4689
4700
 
4690
- const session = await this.auth.refreshToken(
4691
- this.refreshToken,
4692
- this.refreshBackend,
4693
- this.refreshExpiration,
4694
- this.isMobile,
4695
- this.refreshTenantId,
4696
- );
4701
+ try {
4702
+ const session = await this.auth.refreshToken(
4703
+ this.refreshToken,
4704
+ this.refreshBackend,
4705
+ this.refreshExpiration,
4706
+ this.isMobile,
4707
+ this.refreshTenantId,
4708
+ );
4709
+
4710
+ logger$3.info('token refreshed', { token: session.token });
4711
+
4712
+ if (this.onRefreshToken) {
4713
+ this.onRefreshToken(session.token, session);
4714
+ }
4697
4715
 
4698
- logger$3.info('token refreshed', { token: session.token });
4716
+ this.setToken(session.token);
4699
4717
 
4700
- if (this.onRefreshToken) {
4701
- this.onRefreshToken(session.token, session);
4702
- }
4703
-
4704
- this.setToken(session.token);
4718
+ return session.token;
4719
+ } catch (error) {
4720
+ logger$3.error('token refresh, error', error);
4705
4721
 
4706
- return session.token;
4722
+ if (this.onRefreshTokenError) {
4723
+ this.onRefreshTokenError(error);
4724
+ }
4725
+ }
4707
4726
  }
4708
4727
 
4709
4728
  setToken(token ) {
@@ -4726,6 +4745,10 @@ class ApiClient {
4726
4745
  this.onRefreshToken = onRefreshToken;
4727
4746
  }
4728
4747
 
4748
+ setOnRefreshTokenError(callback ) {
4749
+ this.onRefreshTokenError = callback;
4750
+ }
4751
+
4729
4752
  setRefreshExpiration(refreshExpiration ) {
4730
4753
  this.refreshExpiration = refreshExpiration;
4731
4754
  }
@@ -5299,7 +5322,7 @@ class WebSocketClient extends Emitter {
5299
5322
  this.close();
5300
5323
  }
5301
5324
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
5302
- logger$2.log('Wazo WS url computed to reconnect', { url });
5325
+ logger$2.info('Wazo WS url computed to reconnect', { url });
5303
5326
 
5304
5327
  return url;
5305
5328
  }
@@ -6679,8 +6702,10 @@ class WebRTCClient extends Emitter {
6679
6702
  conference: isConference,
6680
6703
  };
6681
6704
 
6682
- // Avoid sdh to created a new stream
6683
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6705
+ // Avoid sdh to create a new stream
6706
+ if (session.sessionDescriptionHandler) {
6707
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6708
+ }
6684
6709
 
6685
6710
  // Send re-INVITE
6686
6711
  return session.invite(options);
@@ -402,13 +402,9 @@ class IssueReporter {
402
402
 
403
403
  setTimeout(() => {
404
404
  if (isArray) {
405
- payload = payload.map(message => {
406
- message._retry = retry + 1;
407
- return message;
408
- });
409
- } else {
410
- // $FlowFixMe
411
- payload._retry = retry + 1;
405
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
406
+ } else if (payload && typeof payload === 'object') {
407
+ payload = this._writeRetryCount(payload, retry + 1);
412
408
  }
413
409
 
414
410
  this._sendDebugToGrafana(payload, retry + 1);
@@ -416,6 +412,15 @@ class IssueReporter {
416
412
  });
417
413
  }
418
414
 
415
+ _writeRetryCount(message , count ) {
416
+ if (message && typeof message === 'object') {
417
+ // $FlowFixMe
418
+ message._retry = count;
419
+ }
420
+
421
+ return message;
422
+ }
423
+
419
424
  _isLevelAbove(level1 , level2 ) {
420
425
  const index1 = LOG_LEVELS.indexOf(level1);
421
426
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2251,9 +2256,12 @@ var authMethods = (client , baseUrl ) => ({
2251
2256
  expiration: expiration || DETAULT_EXPIRATION,
2252
2257
  refresh_token: refreshToken,
2253
2258
  client_id: client.clientId,
2254
- tenant_id: tenantId,
2255
2259
  };
2256
2260
 
2261
+ if (tenantId) {
2262
+ body.tenant_id = tenantId;
2263
+ }
2264
+
2257
2265
  const headers = {
2258
2266
  'Content-Type': 'application/json',
2259
2267
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3541,7 +3549,9 @@ global.wazoClients = global.wazoClients || {};
3541
3549
  global.wazoClientId = global.wazoClientId || {};
3542
3550
  global.wazoClientToken = global.wazoClientToken || {};
3543
3551
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3552
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3544
3553
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3554
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3545
3555
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3546
3556
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3547
3557
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4587,6 +4597,7 @@ class ApiClient {
4587
4597
 
4588
4598
 
4589
4599
 
4600
+
4590
4601
 
4591
4602
 
4592
4603
 
@@ -4639,23 +4650,31 @@ class ApiClient {
4639
4650
  return null;
4640
4651
  }
4641
4652
 
4642
- const session = await this.auth.refreshToken(
4643
- this.refreshToken,
4644
- this.refreshBackend,
4645
- this.refreshExpiration,
4646
- this.isMobile,
4647
- this.refreshTenantId,
4648
- );
4649
-
4650
- logger.info('token refreshed', { token: session.token });
4653
+ try {
4654
+ const session = await this.auth.refreshToken(
4655
+ this.refreshToken,
4656
+ this.refreshBackend,
4657
+ this.refreshExpiration,
4658
+ this.isMobile,
4659
+ this.refreshTenantId,
4660
+ );
4661
+
4662
+ logger.info('token refreshed', { token: session.token });
4663
+
4664
+ if (this.onRefreshToken) {
4665
+ this.onRefreshToken(session.token, session);
4666
+ }
4651
4667
 
4652
- if (this.onRefreshToken) {
4653
- this.onRefreshToken(session.token, session);
4654
- }
4668
+ this.setToken(session.token);
4655
4669
 
4656
- this.setToken(session.token);
4670
+ return session.token;
4671
+ } catch (error) {
4672
+ logger.error('token refresh, error', error);
4657
4673
 
4658
- return session.token;
4674
+ if (this.onRefreshTokenError) {
4675
+ this.onRefreshTokenError(error);
4676
+ }
4677
+ }
4659
4678
  }
4660
4679
 
4661
4680
  setToken(token ) {
@@ -4678,6 +4697,10 @@ class ApiClient {
4678
4697
  this.onRefreshToken = onRefreshToken;
4679
4698
  }
4680
4699
 
4700
+ setOnRefreshTokenError(callback ) {
4701
+ this.onRefreshTokenError = callback;
4702
+ }
4703
+
4681
4704
  setRefreshExpiration(refreshExpiration ) {
4682
4705
  this.refreshExpiration = refreshExpiration;
4683
4706
  }
@@ -402,13 +402,9 @@ class IssueReporter {
402
402
 
403
403
  setTimeout(() => {
404
404
  if (isArray) {
405
- payload = payload.map(message => {
406
- message._retry = retry + 1;
407
- return message;
408
- });
409
- } else {
410
- // $FlowFixMe
411
- payload._retry = retry + 1;
405
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
406
+ } else if (payload && typeof payload === 'object') {
407
+ payload = this._writeRetryCount(payload, retry + 1);
412
408
  }
413
409
 
414
410
  this._sendDebugToGrafana(payload, retry + 1);
@@ -416,6 +412,15 @@ class IssueReporter {
416
412
  });
417
413
  }
418
414
 
415
+ _writeRetryCount(message , count ) {
416
+ if (message && typeof message === 'object') {
417
+ // $FlowFixMe
418
+ message._retry = count;
419
+ }
420
+
421
+ return message;
422
+ }
423
+
419
424
  _isLevelAbove(level1 , level2 ) {
420
425
  const index1 = LOG_LEVELS.indexOf(level1);
421
426
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2251,9 +2256,12 @@ var authMethods = (client , baseUrl ) => ({
2251
2256
  expiration: expiration || DETAULT_EXPIRATION,
2252
2257
  refresh_token: refreshToken,
2253
2258
  client_id: client.clientId,
2254
- tenant_id: tenantId,
2255
2259
  };
2256
2260
 
2261
+ if (tenantId) {
2262
+ body.tenant_id = tenantId;
2263
+ }
2264
+
2257
2265
  const headers = {
2258
2266
  'Content-Type': 'application/json',
2259
2267
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3541,7 +3549,9 @@ global.wazoClients = global.wazoClients || {};
3541
3549
  global.wazoClientId = global.wazoClientId || {};
3542
3550
  global.wazoClientToken = global.wazoClientToken || {};
3543
3551
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3552
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3544
3553
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3554
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3545
3555
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3546
3556
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3547
3557
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4587,6 +4597,7 @@ class ApiClient {
4587
4597
 
4588
4598
 
4589
4599
 
4600
+
4590
4601
 
4591
4602
 
4592
4603
 
@@ -4639,23 +4650,31 @@ class ApiClient {
4639
4650
  return null;
4640
4651
  }
4641
4652
 
4642
- const session = await this.auth.refreshToken(
4643
- this.refreshToken,
4644
- this.refreshBackend,
4645
- this.refreshExpiration,
4646
- this.isMobile,
4647
- this.refreshTenantId,
4648
- );
4649
-
4650
- logger.info('token refreshed', { token: session.token });
4653
+ try {
4654
+ const session = await this.auth.refreshToken(
4655
+ this.refreshToken,
4656
+ this.refreshBackend,
4657
+ this.refreshExpiration,
4658
+ this.isMobile,
4659
+ this.refreshTenantId,
4660
+ );
4661
+
4662
+ logger.info('token refreshed', { token: session.token });
4663
+
4664
+ if (this.onRefreshToken) {
4665
+ this.onRefreshToken(session.token, session);
4666
+ }
4651
4667
 
4652
- if (this.onRefreshToken) {
4653
- this.onRefreshToken(session.token, session);
4654
- }
4668
+ this.setToken(session.token);
4655
4669
 
4656
- this.setToken(session.token);
4670
+ return session.token;
4671
+ } catch (error) {
4672
+ logger.error('token refresh, error', error);
4657
4673
 
4658
- return session.token;
4674
+ if (this.onRefreshTokenError) {
4675
+ this.onRefreshTokenError(error);
4676
+ }
4677
+ }
4659
4678
  }
4660
4679
 
4661
4680
  setToken(token ) {
@@ -4678,6 +4697,10 @@ class ApiClient {
4678
4697
  this.onRefreshToken = onRefreshToken;
4679
4698
  }
4680
4699
 
4700
+ setOnRefreshTokenError(callback ) {
4701
+ this.onRefreshTokenError = callback;
4702
+ }
4703
+
4681
4704
  setRefreshExpiration(refreshExpiration ) {
4682
4705
  this.refreshExpiration = refreshExpiration;
4683
4706
  }
@@ -424,13 +424,9 @@ class IssueReporter {
424
424
 
425
425
  setTimeout(() => {
426
426
  if (isArray) {
427
- payload = payload.map(message => {
428
- message._retry = retry + 1;
429
- return message;
430
- });
431
- } else {
432
- // $FlowFixMe
433
- payload._retry = retry + 1;
427
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
428
+ } else if (payload && typeof payload === 'object') {
429
+ payload = this._writeRetryCount(payload, retry + 1);
434
430
  }
435
431
 
436
432
  this._sendDebugToGrafana(payload, retry + 1);
@@ -438,6 +434,15 @@ class IssueReporter {
438
434
  });
439
435
  }
440
436
 
437
+ _writeRetryCount(message , count ) {
438
+ if (message && typeof message === 'object') {
439
+ // $FlowFixMe
440
+ message._retry = count;
441
+ }
442
+
443
+ return message;
444
+ }
445
+
441
446
  _isLevelAbove(level1 , level2 ) {
442
447
  const index1 = LOG_LEVELS.indexOf(level1);
443
448
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2273,9 +2278,12 @@ var authMethods = (client , baseUrl ) => ({
2273
2278
  expiration: expiration || DETAULT_EXPIRATION,
2274
2279
  refresh_token: refreshToken,
2275
2280
  client_id: client.clientId,
2276
- tenant_id: tenantId,
2277
2281
  };
2278
2282
 
2283
+ if (tenantId) {
2284
+ body.tenant_id = tenantId;
2285
+ }
2286
+
2279
2287
  const headers = {
2280
2288
  'Content-Type': 'application/json',
2281
2289
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3589,7 +3597,9 @@ global.wazoClients = global.wazoClients || {};
3589
3597
  global.wazoClientId = global.wazoClientId || {};
3590
3598
  global.wazoClientToken = global.wazoClientToken || {};
3591
3599
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3600
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3592
3601
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3602
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3593
3603
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3594
3604
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3595
3605
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4635,6 +4645,7 @@ class ApiClient {
4635
4645
 
4636
4646
 
4637
4647
 
4648
+
4638
4649
 
4639
4650
 
4640
4651
 
@@ -4687,23 +4698,31 @@ class ApiClient {
4687
4698
  return null;
4688
4699
  }
4689
4700
 
4690
- const session = await this.auth.refreshToken(
4691
- this.refreshToken,
4692
- this.refreshBackend,
4693
- this.refreshExpiration,
4694
- this.isMobile,
4695
- this.refreshTenantId,
4696
- );
4701
+ try {
4702
+ const session = await this.auth.refreshToken(
4703
+ this.refreshToken,
4704
+ this.refreshBackend,
4705
+ this.refreshExpiration,
4706
+ this.isMobile,
4707
+ this.refreshTenantId,
4708
+ );
4709
+
4710
+ logger$2.info('token refreshed', { token: session.token });
4711
+
4712
+ if (this.onRefreshToken) {
4713
+ this.onRefreshToken(session.token, session);
4714
+ }
4697
4715
 
4698
- logger$2.info('token refreshed', { token: session.token });
4716
+ this.setToken(session.token);
4699
4717
 
4700
- if (this.onRefreshToken) {
4701
- this.onRefreshToken(session.token, session);
4702
- }
4703
-
4704
- this.setToken(session.token);
4718
+ return session.token;
4719
+ } catch (error) {
4720
+ logger$2.error('token refresh, error', error);
4705
4721
 
4706
- return session.token;
4722
+ if (this.onRefreshTokenError) {
4723
+ this.onRefreshTokenError(error);
4724
+ }
4725
+ }
4707
4726
  }
4708
4727
 
4709
4728
  setToken(token ) {
@@ -4726,6 +4745,10 @@ class ApiClient {
4726
4745
  this.onRefreshToken = onRefreshToken;
4727
4746
  }
4728
4747
 
4748
+ setOnRefreshTokenError(callback ) {
4749
+ this.onRefreshTokenError = callback;
4750
+ }
4751
+
4729
4752
  setRefreshExpiration(refreshExpiration ) {
4730
4753
  this.refreshExpiration = refreshExpiration;
4731
4754
  }
@@ -5299,7 +5322,7 @@ class WebSocketClient extends Emitter {
5299
5322
  this.close();
5300
5323
  }
5301
5324
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
5302
- logger$1.log('Wazo WS url computed to reconnect', { url });
5325
+ logger$1.info('Wazo WS url computed to reconnect', { url });
5303
5326
 
5304
5327
  return url;
5305
5328
  }
@@ -6679,8 +6702,10 @@ class WebRTCClient extends Emitter {
6679
6702
  conference: isConference,
6680
6703
  };
6681
6704
 
6682
- // Avoid sdh to created a new stream
6683
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6705
+ // Avoid sdh to create a new stream
6706
+ if (session.sessionDescriptionHandler) {
6707
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6708
+ }
6684
6709
 
6685
6710
  // Send re-INVITE
6686
6711
  return session.invite(options);
@@ -395,13 +395,9 @@ class IssueReporter {
395
395
 
396
396
  setTimeout(() => {
397
397
  if (isArray) {
398
- payload = payload.map(message => {
399
- message._retry = retry + 1;
400
- return message;
401
- });
402
- } else {
403
- // $FlowFixMe
404
- payload._retry = retry + 1;
398
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
399
+ } else if (payload && typeof payload === 'object') {
400
+ payload = this._writeRetryCount(payload, retry + 1);
405
401
  }
406
402
 
407
403
  this._sendDebugToGrafana(payload, retry + 1);
@@ -409,6 +405,15 @@ class IssueReporter {
409
405
  });
410
406
  }
411
407
 
408
+ _writeRetryCount(message , count ) {
409
+ if (message && typeof message === 'object') {
410
+ // $FlowFixMe
411
+ message._retry = count;
412
+ }
413
+
414
+ return message;
415
+ }
416
+
412
417
  _isLevelAbove(level1 , level2 ) {
413
418
  const index1 = LOG_LEVELS.indexOf(level1);
414
419
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -869,7 +874,7 @@ class WebSocketClient extends Emitter {
869
874
  this.close();
870
875
  }
871
876
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
872
- logger.log('Wazo WS url computed to reconnect', { url });
877
+ logger.info('Wazo WS url computed to reconnect', { url });
873
878
 
874
879
  return url;
875
880
  }