@wazo/sdk 0.37.20 → 0.37.24

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 (147) hide show
  1. package/dist/wazo-sdk.js +6 -6
  2. package/esm/__tests__/api-client.test.js +91 -21
  3. package/esm/__tests__/web-rtc-client.test.js +214 -165
  4. package/esm/api/agentd.js +25 -2
  5. package/esm/api/amid.js +26 -3
  6. package/esm/api/application.js +25 -2
  7. package/esm/api/auth.js +25 -2
  8. package/esm/api/call-logd.js +34 -4
  9. package/esm/api/calld.js +35 -2
  10. package/esm/api/chatd.js +32 -2
  11. package/esm/api/confd.js +56 -9
  12. package/esm/api/ctid-ng.js +38 -5
  13. package/esm/api/dird.js +29 -3
  14. package/esm/api/webhookd.js +26 -3
  15. package/esm/api-client.js +91 -21
  16. package/esm/checker/Checker.js +241 -190
  17. package/esm/checker/checks/aor.js +91 -21
  18. package/esm/checker/checks/api.js +91 -21
  19. package/esm/checker/checks/index.js +231 -180
  20. package/esm/checker/checks/wazo-websocket.js +42 -17
  21. package/esm/checker/checks/webrtc-transport.js +214 -165
  22. package/esm/checker/checks/webrtc.js +214 -165
  23. package/esm/domain/AdHocAPIConference.js +91 -21
  24. package/esm/domain/Call.js +3 -0
  25. package/esm/domain/CallLog.js +8 -1
  26. package/esm/domain/ChatMessage.js +4 -0
  27. package/esm/domain/ChatRoom.js +3 -0
  28. package/esm/domain/Contact.js +4 -1
  29. package/esm/domain/Features.js +91 -21
  30. package/esm/domain/Meeting.js +28 -5
  31. package/esm/domain/Phone/CTIPhone.js +109 -35
  32. package/esm/domain/Phone/WebRTCPhone.js +159 -102
  33. package/esm/domain/Recording.js +3 -0
  34. package/esm/domain/Voicemail.js +3 -0
  35. package/esm/domain/__tests__/Call.test.js +3 -0
  36. package/esm/domain/__tests__/CallLog.test.js +8 -1
  37. package/esm/domain/__tests__/Contact.test.js +4 -1
  38. package/esm/domain/__tests__/Meeting.test.js +144 -0
  39. package/esm/domain/__tests__/Voicemail.test.js +3 -0
  40. package/esm/index.js +509 -414
  41. package/esm/lib/WazoSessionDescriptionHandler.js +26 -41
  42. package/esm/service/CallApi.js +91 -21
  43. package/esm/service/IssueReporter.js +26 -3
  44. package/esm/service/__tests__/IssueReporter.test.js +26 -3
  45. package/esm/service/getApiClient.js +91 -21
  46. package/esm/simple/Auth.js +499 -404
  47. package/esm/simple/Configuration.js +499 -404
  48. package/esm/simple/Directory.js +91 -21
  49. package/esm/simple/Phone.js +499 -404
  50. package/esm/simple/Websocket.js +45 -19
  51. package/esm/simple/index.js +503 -408
  52. package/esm/simple/room/LocalParticipant.js +503 -408
  53. package/esm/simple/room/Participant.js +503 -408
  54. package/esm/simple/room/RemoteParticipant.js +503 -408
  55. package/esm/simple/room/Room.js +504 -409
  56. package/esm/simple/room/SipRoom.js +503 -408
  57. package/esm/simple/room/Stream.js +503 -408
  58. package/esm/simple/room/__tests__/RemoteParticipant.test.js +503 -408
  59. package/esm/simple/utils.js +503 -408
  60. package/esm/types/WebSocketMessage.js +1 -1
  61. package/esm/utils/__tests__/api-requester.test.js +25 -2
  62. package/esm/utils/api-requester.js +25 -2
  63. package/esm/web-rtc-client.js +214 -165
  64. package/esm/websocket-client.js +43 -18
  65. package/lib/__tests__/api-client.test.js +91 -21
  66. package/lib/__tests__/web-rtc-client.test.js +214 -165
  67. package/lib/api/agentd.js +25 -2
  68. package/lib/api/amid.js +26 -3
  69. package/lib/api/application.js +25 -2
  70. package/lib/api/auth.js +25 -2
  71. package/lib/api/call-logd.js +34 -4
  72. package/lib/api/calld.js +35 -2
  73. package/lib/api/chatd.js +32 -2
  74. package/lib/api/confd.js +56 -9
  75. package/lib/api/ctid-ng.js +38 -5
  76. package/lib/api/dird.js +29 -3
  77. package/lib/api/webhookd.js +26 -3
  78. package/lib/api-client.js +91 -21
  79. package/lib/checker/Checker.js +241 -190
  80. package/lib/checker/checks/aor.js +91 -21
  81. package/lib/checker/checks/api.js +91 -21
  82. package/lib/checker/checks/index.js +231 -180
  83. package/lib/checker/checks/wazo-websocket.js +42 -17
  84. package/lib/checker/checks/webrtc-transport.js +214 -165
  85. package/lib/checker/checks/webrtc.js +214 -165
  86. package/lib/domain/AdHocAPIConference.js +91 -21
  87. package/lib/domain/Call.js +3 -0
  88. package/lib/domain/CallLog.js +8 -1
  89. package/lib/domain/ChatMessage.js +4 -0
  90. package/lib/domain/ChatRoom.js +3 -0
  91. package/lib/domain/Contact.js +4 -1
  92. package/lib/domain/Features.js +91 -21
  93. package/lib/domain/Meeting.js +32 -5
  94. package/lib/domain/Phone/CTIPhone.js +109 -35
  95. package/lib/domain/Phone/WebRTCPhone.js +159 -102
  96. package/lib/domain/Recording.js +3 -0
  97. package/lib/domain/Voicemail.js +3 -0
  98. package/lib/domain/__tests__/Call.test.js +3 -0
  99. package/lib/domain/__tests__/CallLog.test.js +8 -1
  100. package/lib/domain/__tests__/Contact.test.js +4 -1
  101. package/lib/domain/__tests__/Meeting.test.js +150 -0
  102. package/lib/domain/__tests__/Voicemail.test.js +3 -0
  103. package/lib/index.js +509 -414
  104. package/lib/lib/WazoSessionDescriptionHandler.js +26 -41
  105. package/lib/service/CallApi.js +91 -21
  106. package/lib/service/IssueReporter.js +26 -3
  107. package/lib/service/__tests__/IssueReporter.test.js +26 -3
  108. package/lib/service/getApiClient.js +91 -21
  109. package/lib/simple/Auth.js +499 -404
  110. package/lib/simple/Configuration.js +499 -404
  111. package/lib/simple/Directory.js +91 -21
  112. package/lib/simple/Phone.js +499 -404
  113. package/lib/simple/Websocket.js +45 -19
  114. package/lib/simple/index.js +503 -408
  115. package/lib/simple/room/LocalParticipant.js +503 -408
  116. package/lib/simple/room/Participant.js +503 -408
  117. package/lib/simple/room/RemoteParticipant.js +503 -408
  118. package/lib/simple/room/Room.js +504 -409
  119. package/lib/simple/room/SipRoom.js +503 -408
  120. package/lib/simple/room/Stream.js +503 -408
  121. package/lib/simple/room/__tests__/RemoteParticipant.test.js +503 -408
  122. package/lib/simple/utils.js +503 -408
  123. package/lib/types/WebSocketMessage.js +2 -0
  124. package/lib/utils/__tests__/api-requester.test.js +25 -2
  125. package/lib/utils/api-requester.js +25 -2
  126. package/lib/web-rtc-client.js +214 -165
  127. package/lib/websocket-client.js +43 -17
  128. package/package.json +1 -1
  129. package/src/api/confd.js +5 -2
  130. package/src/domain/Call.js +3 -0
  131. package/src/domain/CallLog.js +4 -0
  132. package/src/domain/ChatMessage.js +4 -0
  133. package/src/domain/ChatRoom.js +3 -0
  134. package/src/domain/Contact.js +3 -0
  135. package/src/domain/Meeting.js +28 -5
  136. package/src/domain/Phone/CTIPhone.js +4 -0
  137. package/src/domain/Phone/Phone.js +2 -0
  138. package/src/domain/Phone/WebRTCPhone.js +49 -15
  139. package/src/domain/Recording.js +3 -0
  140. package/src/domain/Voicemail.js +3 -0
  141. package/src/domain/__tests__/Meeting.test.js +50 -0
  142. package/src/lib/WazoSessionDescriptionHandler.js +1 -35
  143. package/src/service/IssueReporter.js +25 -2
  144. package/src/simple/Phone.js +5 -0
  145. package/src/types/WebSocketMessage.js +5 -1
  146. package/src/web-rtc-client.js +41 -24
  147. package/src/websocket-client.js +2 -0
@@ -11,7 +11,7 @@ const isMobile = () => typeof navigator !== 'undefined' && navigator.product ===
11
11
 
12
12
  /* */
13
13
 
14
- IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
14
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
15
15
 
16
16
  // Use a function here to be able to mock it in tests
17
17
  const realFetch = () => {
@@ -97,6 +97,7 @@ class IssueReporter {
97
97
 
98
98
 
99
99
 
100
+
100
101
 
101
102
  constructor() {
102
103
  addLevelsTo(this);
@@ -108,12 +109,17 @@ class IssueReporter {
108
109
  this.bufferTimeout = null;
109
110
  this._boundProcessBuffer = this._processBuffer.bind(this);
110
111
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
112
+ this._callback = null;
111
113
  }
112
114
 
113
115
  init() {
114
116
  this._catchConsole();
115
117
  }
116
118
 
119
+ setCallback(cb ) {
120
+ this._callback = cb;
121
+ }
122
+
117
123
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
118
124
  this.remoteClientConfiguration = configuration;
119
125
  }
@@ -149,6 +155,7 @@ class IssueReporter {
149
155
 
150
156
  // Handle category label
151
157
  let category = null;
158
+ let skipSendToRemote = false;
152
159
  let extra = {};
153
160
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
154
161
  category = args[0].split('=')[1];
@@ -164,6 +171,7 @@ class IssueReporter {
164
171
  errorMessage: lastArg.message,
165
172
  errorStack: lastArg.stack,
166
173
  errorType: lastArg.constructor.name,
174
+ skipSendToRemote: lastArg.skipSendToRemote,
167
175
  };
168
176
  } else {
169
177
  extra = lastArg;
@@ -172,6 +180,11 @@ class IssueReporter {
172
180
  args.splice(1, 1);
173
181
  }
174
182
 
183
+ if (extra.skipSendToRemote) {
184
+ skipSendToRemote = true;
185
+ delete extra.skipSendToRemote;
186
+ }
187
+
175
188
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
176
189
  const message = args.join(', ');
177
190
  let consoleMessage = message;
@@ -192,7 +205,13 @@ class IssueReporter {
192
205
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
193
206
  oldMethod.apply(oldMethod, [date, consoleMessage]);
194
207
 
195
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
208
+ if (this._callback) {
209
+ this._callback(level, consoleMessage);
210
+ }
211
+
212
+ if (!skipSendToRemote) {
213
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
214
+ }
196
215
  }
197
216
 
198
217
  logRequest(url , options , response , start ) {
@@ -337,7 +356,11 @@ class IssueReporter {
337
356
  },
338
357
  // $FlowFixMe
339
358
  body,
340
- }).catch(() => {
359
+ }).catch((e ) => {
360
+ // $FlowFixMe
361
+ e.skipSendToRemote = true;
362
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
363
+
341
364
  setTimeout(() => {
342
365
  if (isArray) {
343
366
  payload = payload.map(message => {
@@ -386,10 +409,6 @@ const getSrflxOrRelay = (candidates ) =>
386
409
  candidates
387
410
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
388
411
 
389
- const areCandidateValid = (candidates ) =>
390
- getSrflxOrRelay(candidates)
391
- .length > 0;
392
-
393
412
  const fixSdp = (sdp , candidates , forcePort = true) => {
394
413
  const parsedSdp = sdpParser.parse(sdp);
395
414
  const mainCandidate = getSrflxOrRelay(candidates)[0];
@@ -421,8 +440,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
421
440
  /* global RTCSessionDescriptionInit, navigator */
422
441
 
423
442
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
424
- const MAX_WAIT_FOR_ICE_TRIES = 20;
425
- const WAIT_FOR_ICE_TIMEOUT = 500;
426
443
 
427
444
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
428
445
  const wazoMediaStreamFactory = (constraints ) => {
@@ -612,38 +629,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
612
629
  this._peerConnection = undefined;
613
630
  }
614
631
 
615
- async _waitForValidGatheredIce() {
616
- let tries = 0;
617
-
618
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
619
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
620
- tries,
621
- max: MAX_WAIT_FOR_ICE_TRIES,
622
- });
623
-
624
- tries++;
625
-
626
- // eslint-disable-next-line no-await-in-loop
627
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
628
- }
629
-
630
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
631
- const errorMsg = 'No valid candidates found, can\'t answer the call';
632
- const error = new Error(errorMsg);
633
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
634
-
635
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
636
- this.eventEmitter.emit('error', error);
637
-
638
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
639
- }
640
-
641
- // eslint-disable-next-line
642
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
643
-
644
- return this.getLocalSessionDescription();
645
- }
646
-
647
632
  // Overridden to send `inactive` in conference
648
633
  updateDirection(options , isConference = false,
649
634
  audioOnly = false) {
@@ -76,6 +76,9 @@ class Call {
76
76
 
77
77
 
78
78
  static parseMany(plain ) {
79
+ if (!plain) {
80
+ return [];
81
+ }
79
82
  return plain.map((plainCall ) => Call.parse(plainCall));
80
83
  }
81
84
 
@@ -1034,6 +1037,9 @@ class Contact {
1034
1037
  }
1035
1038
 
1036
1039
  static parseMany(response ) {
1040
+ if (!response || !response.results) {
1041
+ return [];
1042
+ }
1037
1043
  return response.results.map(r => Contact.parse(r, response.column_types));
1038
1044
  }
1039
1045
 
@@ -1706,6 +1712,9 @@ class Recording {
1706
1712
 
1707
1713
 
1708
1714
  static parseMany(recordings = []) {
1715
+ if (!recordings) {
1716
+ return [];
1717
+ }
1709
1718
  return recordings.map(item => Recording.parse(item));
1710
1719
  }
1711
1720
 
@@ -1807,6 +1816,10 @@ class CallLog {
1807
1816
  }
1808
1817
 
1809
1818
  static parseMany(plain ) {
1819
+ if (!plain || !plain.items) {
1820
+ return [];
1821
+ }
1822
+
1810
1823
  return plain.items.map(item => CallLog.parse(item));
1811
1824
  }
1812
1825
 
@@ -2139,6 +2152,7 @@ class IssueReporter {
2139
2152
 
2140
2153
 
2141
2154
 
2155
+
2142
2156
 
2143
2157
  constructor() {
2144
2158
  addLevelsTo(this);
@@ -2150,12 +2164,17 @@ class IssueReporter {
2150
2164
  this.bufferTimeout = null;
2151
2165
  this._boundProcessBuffer = this._processBuffer.bind(this);
2152
2166
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
2167
+ this._callback = null;
2153
2168
  }
2154
2169
 
2155
2170
  init() {
2156
2171
  this._catchConsole();
2157
2172
  }
2158
2173
 
2174
+ setCallback(cb ) {
2175
+ this._callback = cb;
2176
+ }
2177
+
2159
2178
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
2160
2179
  this.remoteClientConfiguration = configuration;
2161
2180
  }
@@ -2191,6 +2210,7 @@ class IssueReporter {
2191
2210
 
2192
2211
  // Handle category label
2193
2212
  let category = null;
2213
+ let skipSendToRemote = false;
2194
2214
  let extra = {};
2195
2215
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
2196
2216
  category = args[0].split('=')[1];
@@ -2206,6 +2226,7 @@ class IssueReporter {
2206
2226
  errorMessage: lastArg.message,
2207
2227
  errorStack: lastArg.stack,
2208
2228
  errorType: lastArg.constructor.name,
2229
+ skipSendToRemote: lastArg.skipSendToRemote,
2209
2230
  };
2210
2231
  } else {
2211
2232
  extra = lastArg;
@@ -2214,6 +2235,11 @@ class IssueReporter {
2214
2235
  args.splice(1, 1);
2215
2236
  }
2216
2237
 
2238
+ if (extra.skipSendToRemote) {
2239
+ skipSendToRemote = true;
2240
+ delete extra.skipSendToRemote;
2241
+ }
2242
+
2217
2243
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
2218
2244
  const message = args.join(', ');
2219
2245
  let consoleMessage = message;
@@ -2234,7 +2260,13 @@ class IssueReporter {
2234
2260
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
2235
2261
  oldMethod.apply(oldMethod, [date, consoleMessage]);
2236
2262
 
2237
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
2263
+ if (this._callback) {
2264
+ this._callback(level, consoleMessage);
2265
+ }
2266
+
2267
+ if (!skipSendToRemote) {
2268
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
2269
+ }
2238
2270
  }
2239
2271
 
2240
2272
  logRequest(url , options , response , start ) {
@@ -2379,7 +2411,11 @@ class IssueReporter {
2379
2411
  },
2380
2412
  // $FlowFixMe
2381
2413
  body,
2382
- }).catch(() => {
2414
+ }).catch((e ) => {
2415
+ // $FlowFixMe
2416
+ e.skipSendToRemote = true;
2417
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
2418
+
2383
2419
  setTimeout(() => {
2384
2420
  if (isArray) {
2385
2421
  payload = payload.map(message => {
@@ -2426,7 +2462,7 @@ var IssueReporter$1 = new IssueReporter();
2426
2462
 
2427
2463
  const methods = ['head', 'get', 'post', 'put', 'delete'];
2428
2464
 
2429
- const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
2465
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
2430
2466
 
2431
2467
  // Use a function here to be able to mock it in tests
2432
2468
  const realFetch = () => {
@@ -2565,7 +2601,7 @@ class ApiRequester {
2565
2601
  };
2566
2602
 
2567
2603
  if (this.refreshTokenPromise) {
2568
- logger$1.info('A token is already refreshing, waiting ...', { url });
2604
+ logger.info('A token is already refreshing, waiting ...', { url });
2569
2605
  await this.refreshTokenPromise;
2570
2606
  }
2571
2607
 
@@ -2585,7 +2621,7 @@ class ApiRequester {
2585
2621
  return promise.then(async (err ) => {
2586
2622
  // Check if the token is still valid
2587
2623
  if (firstCall && this._checkTokenExpired(response, err)) {
2588
- logger$1.warn('token expired', { error: err.reason });
2624
+ logger.warn('token expired', { error: err.reason });
2589
2625
  // Replay the call after refreshing the token
2590
2626
  return this._replayWithNewToken(err, path, method, body, headers, parse);
2591
2627
  }
@@ -2595,7 +2631,7 @@ class ApiRequester {
2595
2631
  : exceptionClass.fromResponse(err, response.status);
2596
2632
 
2597
2633
  if (this.shouldLogErrors) {
2598
- logger$1.error('API error', error);
2634
+ logger.error('API error', error);
2599
2635
  }
2600
2636
 
2601
2637
  throw error;
@@ -2605,7 +2641,7 @@ class ApiRequester {
2605
2641
  return newParse(response, isJson);
2606
2642
  }).catch(error => {
2607
2643
  if (this.shouldLogErrors) {
2608
- logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
2644
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
2609
2645
  }
2610
2646
 
2611
2647
  throw error;
@@ -2633,13 +2669,13 @@ class ApiRequester {
2633
2669
  ) {
2634
2670
  const isTokenNotFound = this._isTokenNotFound(err);
2635
2671
  let newPath = path;
2636
- logger$1.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
2672
+ logger.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
2637
2673
 
2638
2674
  this.refreshTokenPromise = this.refreshTokenPromise || this.refreshTokenCallback();
2639
2675
 
2640
2676
  return this.refreshTokenPromise.then(() => {
2641
2677
  this.refreshTokenPromise = null;
2642
- logger$1.info('token refreshed', { isTokenNotFound });
2678
+ logger.info('token refreshed', { isTokenNotFound });
2643
2679
  if (isTokenNotFound) {
2644
2680
  const pathParts = path.split('/');
2645
2681
  pathParts.pop();
@@ -3109,8 +3145,9 @@ class ExternalApp {
3109
3145
 
3110
3146
 
3111
3147
 
3112
-
3148
+
3113
3149
 
3150
+
3114
3151
 
3115
3152
 
3116
3153
  class Meeting {
@@ -3121,9 +3158,10 @@ class Meeting {
3121
3158
 
3122
3159
 
3123
3160
 
3124
-
3161
+
3125
3162
 
3126
3163
 
3164
+
3127
3165
 
3128
3166
  static parse(plain ) {
3129
3167
  return new Meeting({
@@ -3133,24 +3171,43 @@ class Meeting {
3133
3171
  ownerUuids: plain.owner_uuids,
3134
3172
  port: plain.port,
3135
3173
  uuid: plain.uuid,
3136
- number: plain.number,
3174
+ extension: plain.exten,
3137
3175
  persistent: plain.persistent,
3176
+ creationTime: moment(plain.creation_time).toDate(),
3138
3177
  });
3139
3178
  }
3140
3179
 
3180
+ static parseMany(items ) {
3181
+ if (!items) {
3182
+ return [];
3183
+ }
3184
+ return items.map(plain => Meeting.parse(plain));
3185
+ }
3186
+
3141
3187
  static newFrom(meeting ) {
3142
3188
  return newFrom(meeting, Meeting);
3143
3189
  }
3144
3190
 
3145
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
3191
+ constructor({
3192
+ uuid,
3193
+ name,
3194
+ guestSipAuthorization,
3195
+ ownerUuids,
3196
+ port,
3197
+ uri,
3198
+ extension,
3199
+ persistent,
3200
+ creationTime,
3201
+ } = {}) {
3146
3202
  this.guestSipAuthorization = guestSipAuthorization;
3147
3203
  this.uri = uri;
3148
3204
  this.name = name;
3149
3205
  this.ownerUuids = ownerUuids;
3150
3206
  this.port = port;
3151
3207
  this.uuid = uuid;
3152
- this.number = number;
3208
+ this.extension = extension;
3153
3209
  this.persistent = persistent;
3210
+ this.creationTime = creationTime;
3154
3211
 
3155
3212
  // Useful to compare instead of instanceof with minified code
3156
3213
  this.type = 'Meeting';
@@ -3228,8 +3285,11 @@ var confdMethods = (client , baseUrl ) => ({
3228
3285
  }
3229
3286
  },
3230
3287
 
3231
- createMyMeeting: (name ) =>
3232
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
3288
+ getMyMeetings: () =>
3289
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
3290
+
3291
+ createMyMeeting: (name , persistent ) =>
3292
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
3233
3293
 
3234
3294
  deleteMyMeeting: (meetingUuid ) =>
3235
3295
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -3282,6 +3342,10 @@ class ChatMessage {
3282
3342
 
3283
3343
 
3284
3344
  static parseMany(plain ) {
3345
+ if (!plain || !plain.items) {
3346
+ return [];
3347
+ }
3348
+
3285
3349
  return plain.items.map(item => ChatMessage.parse(item));
3286
3350
  }
3287
3351
 
@@ -3391,6 +3455,9 @@ class Voicemail {
3391
3455
  }
3392
3456
 
3393
3457
  static parseMany(plain ) {
3458
+ if (!plain) {
3459
+ return [];
3460
+ }
3394
3461
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3395
3462
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3396
3463
 
@@ -3445,7 +3512,7 @@ const TRANSFER_FLOW_BLIND = 'blind';
3445
3512
 
3446
3513
  // const MINIMUM_WAZO_ENGINE_VERSION_FOR_CTI_HOLD = '20.11';
3447
3514
 
3448
- IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3515
+ const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3449
3516
 
3450
3517
  /* */
3451
3518
 
@@ -3781,6 +3848,9 @@ class ChatRoom {
3781
3848
 
3782
3849
 
3783
3850
  static parseMany(plain ) {
3851
+ if (!plain || !plain.items) {
3852
+ return [];
3853
+ }
3784
3854
  return plain.items.map(item => ChatRoom.parse(item));
3785
3855
  }
3786
3856
 
@@ -4429,7 +4499,7 @@ const AGENTD_VERSION = '1.0';
4429
4499
  const WEBHOOKD_VERSION = '1.0';
4430
4500
  const AMID_VERSION = '1.0';
4431
4501
 
4432
- const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4502
+ const logger$2 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4433
4503
 
4434
4504
  class ApiClient {
4435
4505
 
@@ -4481,12 +4551,12 @@ class ApiClient {
4481
4551
  }
4482
4552
 
4483
4553
  async forceRefreshToken() {
4484
- logger.info('forcing refresh token, calling callback');
4554
+ logger$2.info('forcing refresh token, calling callback');
4485
4555
  return this.refreshTokenCallback();
4486
4556
  }
4487
4557
 
4488
4558
  async refreshTokenCallback() {
4489
- logger.info('refresh token callback called', {
4559
+ logger$2.info('refresh token callback called', {
4490
4560
  refreshToken: this.refreshToken,
4491
4561
  refreshBackend: this.refreshBackend,
4492
4562
  refreshExpiration: this.refreshExpiration,
@@ -4504,7 +4574,7 @@ class ApiClient {
4504
4574
  this.isMobile,
4505
4575
  );
4506
4576
 
4507
- logger.info('token refreshed', { token: session.token });
4577
+ logger$2.info('token refreshed', { token: session.token });
4508
4578
 
4509
4579
  if (this.onRefreshToken) {
4510
4580
  this.onRefreshToken(session.token, session);
@@ -7,7 +7,7 @@ const isMobile = () => typeof navigator !== 'undefined' && navigator.product ===
7
7
 
8
8
  /* */
9
9
 
10
- IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
10
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
11
11
 
12
12
  // Use a function here to be able to mock it in tests
13
13
  const realFetch = () => {
@@ -93,6 +93,7 @@ class IssueReporter {
93
93
 
94
94
 
95
95
 
96
+
96
97
 
97
98
  constructor() {
98
99
  addLevelsTo(this);
@@ -104,12 +105,17 @@ class IssueReporter {
104
105
  this.bufferTimeout = null;
105
106
  this._boundProcessBuffer = this._processBuffer.bind(this);
106
107
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
108
+ this._callback = null;
107
109
  }
108
110
 
109
111
  init() {
110
112
  this._catchConsole();
111
113
  }
112
114
 
115
+ setCallback(cb ) {
116
+ this._callback = cb;
117
+ }
118
+
113
119
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
114
120
  this.remoteClientConfiguration = configuration;
115
121
  }
@@ -145,6 +151,7 @@ class IssueReporter {
145
151
 
146
152
  // Handle category label
147
153
  let category = null;
154
+ let skipSendToRemote = false;
148
155
  let extra = {};
149
156
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
150
157
  category = args[0].split('=')[1];
@@ -160,6 +167,7 @@ class IssueReporter {
160
167
  errorMessage: lastArg.message,
161
168
  errorStack: lastArg.stack,
162
169
  errorType: lastArg.constructor.name,
170
+ skipSendToRemote: lastArg.skipSendToRemote,
163
171
  };
164
172
  } else {
165
173
  extra = lastArg;
@@ -168,6 +176,11 @@ class IssueReporter {
168
176
  args.splice(1, 1);
169
177
  }
170
178
 
179
+ if (extra.skipSendToRemote) {
180
+ skipSendToRemote = true;
181
+ delete extra.skipSendToRemote;
182
+ }
183
+
171
184
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
172
185
  const message = args.join(', ');
173
186
  let consoleMessage = message;
@@ -188,7 +201,13 @@ class IssueReporter {
188
201
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
189
202
  oldMethod.apply(oldMethod, [date, consoleMessage]);
190
203
 
191
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
204
+ if (this._callback) {
205
+ this._callback(level, consoleMessage);
206
+ }
207
+
208
+ if (!skipSendToRemote) {
209
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
210
+ }
192
211
  }
193
212
 
194
213
  logRequest(url , options , response , start ) {
@@ -333,7 +352,11 @@ class IssueReporter {
333
352
  },
334
353
  // $FlowFixMe
335
354
  body,
336
- }).catch(() => {
355
+ }).catch((e ) => {
356
+ // $FlowFixMe
357
+ e.skipSendToRemote = true;
358
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
359
+
337
360
  setTimeout(() => {
338
361
  if (isArray) {
339
362
  payload = payload.map(message => {
@@ -7,7 +7,7 @@ const isMobile = () => typeof navigator !== 'undefined' && navigator.product ===
7
7
 
8
8
  /* */
9
9
 
10
- IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
10
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
11
11
 
12
12
  // Use a function here to be able to mock it in tests
13
13
  const realFetch = () => {
@@ -93,6 +93,7 @@ class IssueReporter {
93
93
 
94
94
 
95
95
 
96
+
96
97
 
97
98
  constructor() {
98
99
  addLevelsTo(this);
@@ -104,12 +105,17 @@ class IssueReporter {
104
105
  this.bufferTimeout = null;
105
106
  this._boundProcessBuffer = this._processBuffer.bind(this);
106
107
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
108
+ this._callback = null;
107
109
  }
108
110
 
109
111
  init() {
110
112
  this._catchConsole();
111
113
  }
112
114
 
115
+ setCallback(cb ) {
116
+ this._callback = cb;
117
+ }
118
+
113
119
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
114
120
  this.remoteClientConfiguration = configuration;
115
121
  }
@@ -145,6 +151,7 @@ class IssueReporter {
145
151
 
146
152
  // Handle category label
147
153
  let category = null;
154
+ let skipSendToRemote = false;
148
155
  let extra = {};
149
156
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
150
157
  category = args[0].split('=')[1];
@@ -160,6 +167,7 @@ class IssueReporter {
160
167
  errorMessage: lastArg.message,
161
168
  errorStack: lastArg.stack,
162
169
  errorType: lastArg.constructor.name,
170
+ skipSendToRemote: lastArg.skipSendToRemote,
163
171
  };
164
172
  } else {
165
173
  extra = lastArg;
@@ -168,6 +176,11 @@ class IssueReporter {
168
176
  args.splice(1, 1);
169
177
  }
170
178
 
179
+ if (extra.skipSendToRemote) {
180
+ skipSendToRemote = true;
181
+ delete extra.skipSendToRemote;
182
+ }
183
+
171
184
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
172
185
  const message = args.join(', ');
173
186
  let consoleMessage = message;
@@ -188,7 +201,13 @@ class IssueReporter {
188
201
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
189
202
  oldMethod.apply(oldMethod, [date, consoleMessage]);
190
203
 
191
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
204
+ if (this._callback) {
205
+ this._callback(level, consoleMessage);
206
+ }
207
+
208
+ if (!skipSendToRemote) {
209
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
210
+ }
192
211
  }
193
212
 
194
213
  logRequest(url , options , response , start ) {
@@ -333,7 +352,11 @@ class IssueReporter {
333
352
  },
334
353
  // $FlowFixMe
335
354
  body,
336
- }).catch(() => {
355
+ }).catch((e ) => {
356
+ // $FlowFixMe
357
+ e.skipSendToRemote = true;
358
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
359
+
337
360
  setTimeout(() => {
338
361
  if (isArray) {
339
362
  payload = payload.map(message => {