@wazo/sdk 0.37.19 → 0.37.23

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 (142) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +70 -5
  3. package/esm/__tests__/web-rtc-client.test.js +111 -67
  4. package/esm/api/agentd.js +25 -2
  5. package/esm/api/amid.js +25 -2
  6. package/esm/api/application.js +25 -2
  7. package/esm/api/auth.js +25 -2
  8. package/esm/api/call-logd.js +32 -2
  9. package/esm/api/calld.js +35 -2
  10. package/esm/api/chatd.js +32 -2
  11. package/esm/api/confd.js +47 -5
  12. package/esm/api/ctid-ng.js +35 -2
  13. package/esm/api/dird.js +28 -2
  14. package/esm/api/webhookd.js +25 -2
  15. package/esm/api-client.js +70 -5
  16. package/esm/checker/Checker.js +113 -67
  17. package/esm/checker/checks/aor.js +70 -5
  18. package/esm/checker/checks/api.js +70 -5
  19. package/esm/checker/checks/index.js +113 -67
  20. package/esm/checker/checks/wazo-websocket.js +27 -2
  21. package/esm/checker/checks/webrtc-transport.js +111 -67
  22. package/esm/checker/checks/webrtc.js +111 -67
  23. package/esm/domain/AdHocAPIConference.js +70 -5
  24. package/esm/domain/Call.js +3 -0
  25. package/esm/domain/CallLog.js +7 -0
  26. package/esm/domain/ChatMessage.js +4 -0
  27. package/esm/domain/ChatRoom.js +3 -0
  28. package/esm/domain/Contact.js +3 -0
  29. package/esm/domain/Features.js +70 -5
  30. package/esm/domain/Meeting.js +17 -1
  31. package/esm/domain/Phone/CTIPhone.js +74 -5
  32. package/esm/domain/Phone/WebRTCPhone.js +50 -16
  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 +7 -0
  37. package/esm/domain/__tests__/Contact.test.js +3 -0
  38. package/esm/domain/__tests__/Voicemail.test.js +3 -0
  39. package/esm/index.js +147 -80
  40. package/esm/lib/WazoSessionDescriptionHandler.js +25 -40
  41. package/esm/service/CallApi.js +70 -5
  42. package/esm/service/IssueReporter.js +25 -2
  43. package/esm/service/__tests__/IssueReporter.test.js +25 -2
  44. package/esm/service/getApiClient.js +70 -5
  45. package/esm/simple/Auth.js +147 -80
  46. package/esm/simple/Configuration.js +147 -80
  47. package/esm/simple/Directory.js +70 -5
  48. package/esm/simple/Phone.js +147 -80
  49. package/esm/simple/Websocket.js +28 -2
  50. package/esm/simple/index.js +147 -80
  51. package/esm/simple/room/LocalParticipant.js +147 -80
  52. package/esm/simple/room/Participant.js +147 -80
  53. package/esm/simple/room/RemoteParticipant.js +147 -80
  54. package/esm/simple/room/Room.js +147 -80
  55. package/esm/simple/room/SipRoom.js +147 -80
  56. package/esm/simple/room/Stream.js +147 -80
  57. package/esm/simple/room/__tests__/RemoteParticipant.test.js +147 -80
  58. package/esm/simple/utils.js +147 -80
  59. package/esm/utils/__tests__/api-requester.test.js +25 -2
  60. package/esm/utils/api-requester.js +25 -2
  61. package/esm/web-rtc-client.js +111 -67
  62. package/esm/websocket-client.js +28 -3
  63. package/lib/__tests__/api-client.test.js +70 -5
  64. package/lib/__tests__/web-rtc-client.test.js +111 -67
  65. package/lib/api/agentd.js +25 -2
  66. package/lib/api/amid.js +25 -2
  67. package/lib/api/application.js +25 -2
  68. package/lib/api/auth.js +25 -2
  69. package/lib/api/call-logd.js +32 -2
  70. package/lib/api/calld.js +35 -2
  71. package/lib/api/chatd.js +32 -2
  72. package/lib/api/confd.js +47 -5
  73. package/lib/api/ctid-ng.js +35 -2
  74. package/lib/api/dird.js +28 -2
  75. package/lib/api/webhookd.js +25 -2
  76. package/lib/api-client.js +70 -5
  77. package/lib/checker/Checker.js +113 -67
  78. package/lib/checker/checks/aor.js +70 -5
  79. package/lib/checker/checks/api.js +70 -5
  80. package/lib/checker/checks/index.js +113 -67
  81. package/lib/checker/checks/wazo-websocket.js +27 -2
  82. package/lib/checker/checks/webrtc-transport.js +111 -67
  83. package/lib/checker/checks/webrtc.js +111 -67
  84. package/lib/domain/AdHocAPIConference.js +70 -5
  85. package/lib/domain/Call.js +3 -0
  86. package/lib/domain/CallLog.js +7 -0
  87. package/lib/domain/ChatMessage.js +4 -0
  88. package/lib/domain/ChatRoom.js +3 -0
  89. package/lib/domain/Contact.js +3 -0
  90. package/lib/domain/Features.js +70 -5
  91. package/lib/domain/Meeting.js +17 -1
  92. package/lib/domain/Phone/CTIPhone.js +74 -5
  93. package/lib/domain/Phone/WebRTCPhone.js +50 -16
  94. package/lib/domain/Recording.js +3 -0
  95. package/lib/domain/Voicemail.js +3 -0
  96. package/lib/domain/__tests__/Call.test.js +3 -0
  97. package/lib/domain/__tests__/CallLog.test.js +7 -0
  98. package/lib/domain/__tests__/Contact.test.js +3 -0
  99. package/lib/domain/__tests__/Voicemail.test.js +3 -0
  100. package/lib/index.js +147 -80
  101. package/lib/lib/WazoSessionDescriptionHandler.js +25 -40
  102. package/lib/service/CallApi.js +70 -5
  103. package/lib/service/IssueReporter.js +25 -2
  104. package/lib/service/__tests__/IssueReporter.test.js +25 -2
  105. package/lib/service/getApiClient.js +70 -5
  106. package/lib/simple/Auth.js +147 -80
  107. package/lib/simple/Configuration.js +147 -80
  108. package/lib/simple/Directory.js +70 -5
  109. package/lib/simple/Phone.js +147 -80
  110. package/lib/simple/Websocket.js +28 -2
  111. package/lib/simple/index.js +147 -80
  112. package/lib/simple/room/LocalParticipant.js +147 -80
  113. package/lib/simple/room/Participant.js +147 -80
  114. package/lib/simple/room/RemoteParticipant.js +147 -80
  115. package/lib/simple/room/Room.js +147 -80
  116. package/lib/simple/room/SipRoom.js +147 -80
  117. package/lib/simple/room/Stream.js +147 -80
  118. package/lib/simple/room/__tests__/RemoteParticipant.test.js +147 -80
  119. package/lib/simple/utils.js +147 -80
  120. package/lib/utils/__tests__/api-requester.test.js +25 -2
  121. package/lib/utils/api-requester.js +25 -2
  122. package/lib/web-rtc-client.js +111 -67
  123. package/lib/websocket-client.js +28 -2
  124. package/package.json +2 -2
  125. package/src/api/confd.js +5 -2
  126. package/src/domain/Call.js +3 -0
  127. package/src/domain/CallLog.js +4 -0
  128. package/src/domain/ChatMessage.js +4 -0
  129. package/src/domain/ChatRoom.js +3 -0
  130. package/src/domain/Contact.js +3 -0
  131. package/src/domain/Meeting.js +17 -1
  132. package/src/domain/Phone/CTIPhone.js +4 -0
  133. package/src/domain/Phone/Phone.js +2 -0
  134. package/src/domain/Phone/WebRTCPhone.js +25 -14
  135. package/src/domain/Recording.js +3 -0
  136. package/src/domain/Voicemail.js +3 -0
  137. package/src/lib/WazoSessionDescriptionHandler.js +1 -35
  138. package/src/service/IssueReporter.js +25 -2
  139. package/src/simple/Phone.js +5 -0
  140. package/src/types/WebSocketMessage.js +5 -1
  141. package/src/web-rtc-client.js +41 -24
  142. package/src/websocket-client.js +2 -0
package/esm/index.js CHANGED
@@ -150,6 +150,7 @@ class IssueReporter {
150
150
 
151
151
 
152
152
 
153
+
153
154
 
154
155
  constructor() {
155
156
  addLevelsTo(this);
@@ -161,12 +162,17 @@ class IssueReporter {
161
162
  this.bufferTimeout = null;
162
163
  this._boundProcessBuffer = this._processBuffer.bind(this);
163
164
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
165
+ this._callback = null;
164
166
  }
165
167
 
166
168
  init() {
167
169
  this._catchConsole();
168
170
  }
169
171
 
172
+ setCallback(cb ) {
173
+ this._callback = cb;
174
+ }
175
+
170
176
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
171
177
  this.remoteClientConfiguration = configuration;
172
178
  }
@@ -202,6 +208,7 @@ class IssueReporter {
202
208
 
203
209
  // Handle category label
204
210
  let category = null;
211
+ let skipSendToRemote = false;
205
212
  let extra = {};
206
213
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
207
214
  category = args[0].split('=')[1];
@@ -217,6 +224,7 @@ class IssueReporter {
217
224
  errorMessage: lastArg.message,
218
225
  errorStack: lastArg.stack,
219
226
  errorType: lastArg.constructor.name,
227
+ skipSendToRemote: lastArg.skipSendToRemote,
220
228
  };
221
229
  } else {
222
230
  extra = lastArg;
@@ -225,6 +233,11 @@ class IssueReporter {
225
233
  args.splice(1, 1);
226
234
  }
227
235
 
236
+ if (extra.skipSendToRemote) {
237
+ skipSendToRemote = true;
238
+ delete extra.skipSendToRemote;
239
+ }
240
+
228
241
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
229
242
  const message = args.join(', ');
230
243
  let consoleMessage = message;
@@ -245,7 +258,13 @@ class IssueReporter {
245
258
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
246
259
  oldMethod.apply(oldMethod, [date, consoleMessage]);
247
260
 
248
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
261
+ if (this._callback) {
262
+ this._callback(level, consoleMessage);
263
+ }
264
+
265
+ if (!skipSendToRemote) {
266
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
267
+ }
249
268
  }
250
269
 
251
270
  logRequest(url , options , response , start ) {
@@ -390,7 +409,11 @@ class IssueReporter {
390
409
  },
391
410
  // $FlowFixMe
392
411
  body,
393
- }).catch(() => {
412
+ }).catch((e ) => {
413
+ // $FlowFixMe
414
+ e.skipSendToRemote = true;
415
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
416
+
394
417
  setTimeout(() => {
395
418
  if (isArray) {
396
419
  payload = payload.map(message => {
@@ -1528,6 +1551,9 @@ class Contact {
1528
1551
  }
1529
1552
 
1530
1553
  static parseMany(response ) {
1554
+ if (!response || !response.results) {
1555
+ return [];
1556
+ }
1531
1557
  return response.results.map(r => Contact.parse(r, response.column_types));
1532
1558
  }
1533
1559
 
@@ -2634,11 +2660,27 @@ class Meeting {
2634
2660
  });
2635
2661
  }
2636
2662
 
2663
+ static parseMany(items ) {
2664
+ if (!items) {
2665
+ return [];
2666
+ }
2667
+ return items.map(plain => Meeting.parse(plain));
2668
+ }
2669
+
2637
2670
  static newFrom(meeting ) {
2638
2671
  return newFrom(meeting, Meeting);
2639
2672
  }
2640
2673
 
2641
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2674
+ constructor({
2675
+ uuid,
2676
+ name,
2677
+ guestSipAuthorization,
2678
+ ownerUuids,
2679
+ port,
2680
+ uri,
2681
+ number,
2682
+ persistent,
2683
+ } = {}) {
2642
2684
  this.guestSipAuthorization = guestSipAuthorization;
2643
2685
  this.uri = uri;
2644
2686
  this.name = name;
@@ -2724,8 +2766,11 @@ var confdMethods = (client , baseUrl ) => ({
2724
2766
  }
2725
2767
  },
2726
2768
 
2727
- createMyMeeting: (name ) =>
2728
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2769
+ getMyMeetings: () =>
2770
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2771
+
2772
+ createMyMeeting: (name , persistent ) =>
2773
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2729
2774
 
2730
2775
  deleteMyMeeting: (meetingUuid ) =>
2731
2776
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2821,6 +2866,10 @@ class ChatMessage {
2821
2866
 
2822
2867
 
2823
2868
  static parseMany(plain ) {
2869
+ if (!plain || !plain.items) {
2870
+ return [];
2871
+ }
2872
+
2824
2873
  return plain.items.map(item => ChatMessage.parse(item));
2825
2874
  }
2826
2875
 
@@ -2930,6 +2979,9 @@ class Voicemail {
2930
2979
  }
2931
2980
 
2932
2981
  static parseMany(plain ) {
2982
+ if (!plain) {
2983
+ return [];
2984
+ }
2933
2985
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2934
2986
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2935
2987
 
@@ -3039,6 +3091,9 @@ class Call {
3039
3091
 
3040
3092
 
3041
3093
  static parseMany(plain ) {
3094
+ if (!plain) {
3095
+ return [];
3096
+ }
3042
3097
  return plain.map((plainCall ) => Call.parse(plainCall));
3043
3098
  }
3044
3099
 
@@ -3582,6 +3637,9 @@ class Recording {
3582
3637
 
3583
3638
 
3584
3639
  static parseMany(recordings = []) {
3640
+ if (!recordings) {
3641
+ return [];
3642
+ }
3585
3643
  return recordings.map(item => Recording.parse(item));
3586
3644
  }
3587
3645
 
@@ -3683,6 +3741,10 @@ class CallLog {
3683
3741
  }
3684
3742
 
3685
3743
  static parseMany(plain ) {
3744
+ if (!plain || !plain.items) {
3745
+ return [];
3746
+ }
3747
+
3686
3748
  return plain.items.map(item => CallLog.parse(item));
3687
3749
  }
3688
3750
 
@@ -4335,6 +4397,10 @@ class CTIPhone extends Emitter {
4335
4397
  return false;
4336
4398
  }
4337
4399
 
4400
+ hasAVideoTrack() {
4401
+ return false;
4402
+ }
4403
+
4338
4404
  getLocalStreamForCall() {
4339
4405
  return null;
4340
4406
  }
@@ -4728,6 +4794,9 @@ class ChatRoom {
4728
4794
 
4729
4795
 
4730
4796
  static parseMany(plain ) {
4797
+ if (!plain || !plain.items) {
4798
+ return [];
4799
+ }
4731
4800
  return plain.items.map(item => ChatRoom.parse(item));
4732
4801
  }
4733
4802
 
@@ -5451,10 +5520,6 @@ const getSrflxOrRelay = (candidates ) =>
5451
5520
  candidates
5452
5521
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5453
5522
 
5454
- const areCandidateValid = (candidates ) =>
5455
- getSrflxOrRelay(candidates)
5456
- .length > 0;
5457
-
5458
5523
  const getVideoDirection = (sdp ) => {
5459
5524
  const parsedSdp = sdpParser.parse(sdp);
5460
5525
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5507,8 +5572,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5507
5572
  /* global RTCSessionDescriptionInit, navigator */
5508
5573
 
5509
5574
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5510
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5511
- const WAIT_FOR_ICE_TIMEOUT = 500;
5512
5575
 
5513
5576
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5514
5577
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5698,38 +5761,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
5698
5761
  this._peerConnection = undefined;
5699
5762
  }
5700
5763
 
5701
- async _waitForValidGatheredIce() {
5702
- let tries = 0;
5703
-
5704
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5705
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5706
- tries,
5707
- max: MAX_WAIT_FOR_ICE_TRIES,
5708
- });
5709
-
5710
- tries++;
5711
-
5712
- // eslint-disable-next-line no-await-in-loop
5713
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5714
- }
5715
-
5716
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5717
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5718
- const error = new Error(errorMsg);
5719
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5720
-
5721
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5722
- this.eventEmitter.emit('error', error);
5723
-
5724
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5725
- }
5726
-
5727
- // eslint-disable-next-line
5728
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5729
-
5730
- return this.getLocalSessionDescription();
5731
- }
5732
-
5733
5764
  // Overridden to send `inactive` in conference
5734
5765
  updateDirection(options , isConference = false,
5735
5766
  audioOnly = false) {
@@ -6522,7 +6553,9 @@ class WebRTCClient extends Emitter {
6522
6553
  const inviteOptions = {
6523
6554
  requestDelegate: {
6524
6555
  onAccept: (response ) => {
6525
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
6556
+ if (session.sessionDescriptionHandler.peerConnection) {
6557
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
6558
+ }
6526
6559
  this._onAccepted(session, response.session, true);
6527
6560
  },
6528
6561
  onReject: (response ) => {
@@ -7394,6 +7427,16 @@ class WebRTCClient extends Emitter {
7394
7427
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
7395
7428
  }
7396
7429
 
7430
+ // Useful in a react-native environment when remoteMediaStream is not updated
7431
+ getRemoteVideoStreamFromPc(sessionId ) {
7432
+ const pc = this.getPeerConnection(sessionId);
7433
+ if (!pc) {
7434
+ return null;
7435
+ }
7436
+
7437
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
7438
+ }
7439
+
7397
7440
  hasVideo(sessionId ) {
7398
7441
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
7399
7442
  }
@@ -7904,6 +7947,7 @@ class WebRTCClient extends Emitter {
7904
7947
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
7905
7948
 
7906
7949
  pc.oniceconnectionstatechange = () => {
7950
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
7907
7951
  if (pc.iceConnectionState === 'disconnected') {
7908
7952
  this.eventEmitter.emit(ON_DISCONNECTED$1);
7909
7953
  }
@@ -8132,25 +8176,25 @@ class WebRTCClient extends Emitter {
8132
8176
 
8133
8177
  stats.forEach(report => {
8134
8178
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8135
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8179
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8136
8180
  }
8137
8181
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8138
- audioBytesSent += report.bytesSent;
8182
+ audioBytesSent += Number(report.bytesSent);
8139
8183
  }
8140
8184
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8141
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8185
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8142
8186
  }
8143
8187
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8144
- packetsLost += report.packetsLost;
8145
- networkStats.packetsReceived = report.packetsReceived;
8146
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8188
+ packetsLost += Number(report.packetsLost);
8189
+ networkStats.packetsReceived = Number(report.packetsReceived);
8190
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8147
8191
  }
8148
8192
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8149
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8193
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8150
8194
  }
8151
8195
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8152
8196
  if ('framesPerSecond' in report) {
8153
- networkStats.framesPerSecond = report.framesPerSecond;
8197
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8154
8198
  }
8155
8199
  if ('framerateMean' in report) {
8156
8200
  // framerateMean is only available in FF
@@ -8158,32 +8202,36 @@ class WebRTCClient extends Emitter {
8158
8202
  }
8159
8203
  }
8160
8204
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8161
- packetsLost += report.packetsLost;
8162
- networkStats.roundTripTime = report.roundTripTime;
8163
- networkStats.jitter = report.jitter;
8205
+ packetsLost += Number(report.packetsLost);
8206
+ networkStats.roundTripTime = Number(report.roundTripTime);
8207
+ networkStats.jitter = Number(report.jitter);
8164
8208
  }
8165
8209
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8166
- packetsLost += report.packetsLost;
8210
+ packetsLost += Number(report.packetsLost);
8167
8211
  }
8168
8212
  if (report.type === 'transport') {
8169
- transportSent += report.bytesSent;
8170
- transportReceived += report.bytesReceived;
8213
+ transportSent += Number(report.bytesSent);
8214
+ transportReceived += Number(report.bytesReceived);
8171
8215
  }
8172
8216
  });
8173
8217
 
8174
8218
  networkStats.packetsLost = packetsLost;
8175
- networkStats.audioBytesSent = audioBytesSent;
8219
+ networkStats.totalAudioBytesSent = audioBytesSent;
8220
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8221
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8176
8222
  networkStats.audioBytesReceived = audioBytesReceived;
8177
- networkStats.videoBytesSent = videoBytesSent;
8178
- networkStats.videoBytesReceived = videoBytesReceived;
8223
+ networkStats.totalVideoBytesSent = videoBytesSent;
8224
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8225
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
8226
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
8227
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
8179
8228
  networkStats.transportSent = transportSent;
8180
- networkStats.transportReceived = transportReceived;
8229
+ networkStats.totalTransportReceived = transportReceived;
8230
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
8181
8231
 
8182
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
8183
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
8184
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
8185
-
8186
- networkStats.bandwidth = bandwidth;
8232
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
8233
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
8234
+ + networkStats.transportSent;
8187
8235
 
8188
8236
  this.eventEmitter.emit(ON_NETWORK_STATS$1, session, networkStats, this.sessionNetworkStats[sessionId]);
8189
8237
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -8279,6 +8327,7 @@ const AGENT_PAUSED = 'agent_paused';
8279
8327
  const AGENT_UNPAUSED = 'agent_unpaused';
8280
8328
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
8281
8329
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
8330
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
8282
8331
 
8283
8332
  const BLACKLIST_EVENTS = [
8284
8333
  CHAT_MESSAGE_SENT,
@@ -8629,6 +8678,7 @@ WebSocketClient.eventLists = [
8629
8678
  AGENT_UNPAUSED,
8630
8679
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
8631
8680
  CONFERENCE_ADHOC_DELETED,
8681
+ MEETING_USER_PROGRESS,
8632
8682
  ];
8633
8683
 
8634
8684
  var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
@@ -8699,6 +8749,7 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
8699
8749
  AGENT_UNPAUSED: AGENT_UNPAUSED,
8700
8750
  CONFERENCE_ADHOC_PARTICIPANT_LEFT: CONFERENCE_ADHOC_PARTICIPANT_LEFT,
8701
8751
  CONFERENCE_ADHOC_DELETED: CONFERENCE_ADHOC_DELETED,
8752
+ MEETING_USER_PROGRESS: MEETING_USER_PROGRESS,
8702
8753
  HEARTBEAT_ENGINE_VERSION: HEARTBEAT_ENGINE_VERSION,
8703
8754
  'default': WebSocketClient
8704
8755
  });
@@ -9455,7 +9506,10 @@ class WebRTCPhone extends Emitter {
9455
9506
 
9456
9507
  onCancel(message);
9457
9508
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
9458
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
9509
+ const callSession = this._createCallSession(sipSession);
9510
+ delete this.callSessions[callSession.getId()];
9511
+
9512
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
9459
9513
  };
9460
9514
  } else if (sipSession instanceof Invitation) {
9461
9515
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -9484,9 +9538,11 @@ class WebRTCPhone extends Emitter {
9484
9538
  case SessionState.Terminated: {
9485
9539
  logger$7.info('WebRTC phone - call terminated', { sipId: sipSession.id });
9486
9540
 
9541
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
9542
+ const callSession = this._createCallSession(sipSession);
9487
9543
  const wasCurrentSession = this._onCallTerminated(sipSession);
9488
9544
 
9489
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
9545
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
9490
9546
  }
9491
9547
  }
9492
9548
  });
@@ -9634,18 +9690,20 @@ class WebRTCPhone extends Emitter {
9634
9690
  screenTrack,
9635
9691
  });
9636
9692
 
9637
- screenTrack.onended = () => {
9638
- logger$7.info('WebRTC phone - on screenshare ended', {
9639
- hadVideo,
9640
- id: this.getSipSessionId(sipSession),
9641
- screenTrack,
9642
- });
9693
+ if (screenTrack) {
9694
+ screenTrack.onended = () => {
9695
+ logger$7.info('WebRTC phone - on screenshare ended', {
9696
+ hadVideo,
9697
+ id: this.getSipSessionId(sipSession),
9698
+ screenTrack,
9699
+ });
9643
9700
 
9644
- this.eventEmitter.emit(
9645
- ON_SHARE_SCREEN_ENDING,
9646
- this._createCallSession(sipSession, callSession),
9647
- );
9648
- };
9701
+ this.eventEmitter.emit(
9702
+ ON_SHARE_SCREEN_ENDING,
9703
+ this._createCallSession(sipSession, callSession),
9704
+ );
9705
+ };
9706
+ }
9649
9707
 
9650
9708
  this.currentScreenShare = {
9651
9709
  stream: screenStream,
@@ -10434,6 +10492,10 @@ class WebRTCPhone extends Emitter {
10434
10492
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
10435
10493
  }
10436
10494
 
10495
+ getRemoteVideoStreamFromPc(callSession ) {
10496
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
10497
+ }
10498
+
10437
10499
  hasRemoteVideo(callSession ) {
10438
10500
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
10439
10501
  }
@@ -12152,6 +12214,11 @@ class Phone extends Emitter {
12152
12214
  return this.getRemoteVideoStream(callSession);
12153
12215
  }
12154
12216
 
12217
+ // Useful in a react-native environment when remoteMediaStream is not updated
12218
+ getRemoteVideoStreamFromPc(callSession ) {
12219
+ return this.phone ? this.phone.getRemoteVideoStreamFromPc(callSession) : false;
12220
+ }
12221
+
12155
12222
  hasVideo(callSession ) {
12156
12223
  return this.phone ? this.phone.hasVideo(callSession) : false;
12157
12224
  }
@@ -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) {