@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
@@ -863,6 +863,9 @@ class Contact {
863
863
  }
864
864
 
865
865
  static parseMany(response ) {
866
+ if (!response || !response.results) {
867
+ return [];
868
+ }
866
869
  return response.results.map(r => Contact.parse(r, response.column_types));
867
870
  }
868
871
 
@@ -1634,6 +1637,7 @@ class IssueReporter {
1634
1637
 
1635
1638
 
1636
1639
 
1640
+
1637
1641
 
1638
1642
  constructor() {
1639
1643
  addLevelsTo(this);
@@ -1645,12 +1649,17 @@ class IssueReporter {
1645
1649
  this.bufferTimeout = null;
1646
1650
  this._boundProcessBuffer = this._processBuffer.bind(this);
1647
1651
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
1652
+ this._callback = null;
1648
1653
  }
1649
1654
 
1650
1655
  init() {
1651
1656
  this._catchConsole();
1652
1657
  }
1653
1658
 
1659
+ setCallback(cb ) {
1660
+ this._callback = cb;
1661
+ }
1662
+
1654
1663
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
1655
1664
  this.remoteClientConfiguration = configuration;
1656
1665
  }
@@ -1686,6 +1695,7 @@ class IssueReporter {
1686
1695
 
1687
1696
  // Handle category label
1688
1697
  let category = null;
1698
+ let skipSendToRemote = false;
1689
1699
  let extra = {};
1690
1700
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
1691
1701
  category = args[0].split('=')[1];
@@ -1701,6 +1711,7 @@ class IssueReporter {
1701
1711
  errorMessage: lastArg.message,
1702
1712
  errorStack: lastArg.stack,
1703
1713
  errorType: lastArg.constructor.name,
1714
+ skipSendToRemote: lastArg.skipSendToRemote,
1704
1715
  };
1705
1716
  } else {
1706
1717
  extra = lastArg;
@@ -1709,6 +1720,11 @@ class IssueReporter {
1709
1720
  args.splice(1, 1);
1710
1721
  }
1711
1722
 
1723
+ if (extra.skipSendToRemote) {
1724
+ skipSendToRemote = true;
1725
+ delete extra.skipSendToRemote;
1726
+ }
1727
+
1712
1728
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
1713
1729
  const message = args.join(', ');
1714
1730
  let consoleMessage = message;
@@ -1729,7 +1745,13 @@ class IssueReporter {
1729
1745
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
1730
1746
  oldMethod.apply(oldMethod, [date, consoleMessage]);
1731
1747
 
1732
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
1748
+ if (this._callback) {
1749
+ this._callback(level, consoleMessage);
1750
+ }
1751
+
1752
+ if (!skipSendToRemote) {
1753
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
1754
+ }
1733
1755
  }
1734
1756
 
1735
1757
  logRequest(url , options , response , start ) {
@@ -1874,7 +1896,11 @@ class IssueReporter {
1874
1896
  },
1875
1897
  // $FlowFixMe
1876
1898
  body,
1877
- }).catch(() => {
1899
+ }).catch((e ) => {
1900
+ // $FlowFixMe
1901
+ e.skipSendToRemote = true;
1902
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
1903
+
1878
1904
  setTimeout(() => {
1879
1905
  if (isArray) {
1880
1906
  payload = payload.map(message => {
@@ -2633,11 +2659,27 @@ class Meeting {
2633
2659
  });
2634
2660
  }
2635
2661
 
2662
+ static parseMany(items ) {
2663
+ if (!items) {
2664
+ return [];
2665
+ }
2666
+ return items.map(plain => Meeting.parse(plain));
2667
+ }
2668
+
2636
2669
  static newFrom(meeting ) {
2637
2670
  return newFrom(meeting, Meeting);
2638
2671
  }
2639
2672
 
2640
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2673
+ constructor({
2674
+ uuid,
2675
+ name,
2676
+ guestSipAuthorization,
2677
+ ownerUuids,
2678
+ port,
2679
+ uri,
2680
+ number,
2681
+ persistent,
2682
+ } = {}) {
2641
2683
  this.guestSipAuthorization = guestSipAuthorization;
2642
2684
  this.uri = uri;
2643
2685
  this.name = name;
@@ -2723,8 +2765,11 @@ var confdMethods = (client , baseUrl ) => ({
2723
2765
  }
2724
2766
  },
2725
2767
 
2726
- createMyMeeting: (name ) =>
2727
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2768
+ getMyMeetings: () =>
2769
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2770
+
2771
+ createMyMeeting: (name , persistent ) =>
2772
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2728
2773
 
2729
2774
  deleteMyMeeting: (meetingUuid ) =>
2730
2775
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2820,6 +2865,10 @@ class ChatMessage {
2820
2865
 
2821
2866
 
2822
2867
  static parseMany(plain ) {
2868
+ if (!plain || !plain.items) {
2869
+ return [];
2870
+ }
2871
+
2823
2872
  return plain.items.map(item => ChatMessage.parse(item));
2824
2873
  }
2825
2874
 
@@ -2929,6 +2978,9 @@ class Voicemail {
2929
2978
  }
2930
2979
 
2931
2980
  static parseMany(plain ) {
2981
+ if (!plain) {
2982
+ return [];
2983
+ }
2932
2984
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2933
2985
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2934
2986
 
@@ -3038,6 +3090,9 @@ class Call {
3038
3090
 
3039
3091
 
3040
3092
  static parseMany(plain ) {
3093
+ if (!plain) {
3094
+ return [];
3095
+ }
3041
3096
  return plain.map((plainCall ) => Call.parse(plainCall));
3042
3097
  }
3043
3098
 
@@ -3581,6 +3636,9 @@ class Recording {
3581
3636
 
3582
3637
 
3583
3638
  static parseMany(recordings = []) {
3639
+ if (!recordings) {
3640
+ return [];
3641
+ }
3584
3642
  return recordings.map(item => Recording.parse(item));
3585
3643
  }
3586
3644
 
@@ -3682,6 +3740,10 @@ class CallLog {
3682
3740
  }
3683
3741
 
3684
3742
  static parseMany(plain ) {
3743
+ if (!plain || !plain.items) {
3744
+ return [];
3745
+ }
3746
+
3685
3747
  return plain.items.map(item => CallLog.parse(item));
3686
3748
  }
3687
3749
 
@@ -4251,6 +4313,10 @@ class CTIPhone extends Emitter {
4251
4313
  return false;
4252
4314
  }
4253
4315
 
4316
+ hasAVideoTrack() {
4317
+ return false;
4318
+ }
4319
+
4254
4320
  getLocalStreamForCall() {
4255
4321
  return null;
4256
4322
  }
@@ -4644,6 +4710,9 @@ class ChatRoom {
4644
4710
 
4645
4711
 
4646
4712
  static parseMany(plain ) {
4713
+ if (!plain || !plain.items) {
4714
+ return [];
4715
+ }
4647
4716
  return plain.items.map(item => ChatRoom.parse(item));
4648
4717
  }
4649
4718
 
@@ -5889,10 +5958,6 @@ const getSrflxOrRelay = (candidates ) =>
5889
5958
  candidates
5890
5959
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5891
5960
 
5892
- const areCandidateValid = (candidates ) =>
5893
- getSrflxOrRelay(candidates)
5894
- .length > 0;
5895
-
5896
5961
  const getVideoDirection = (sdp ) => {
5897
5962
  const parsedSdp = sdpParser.parse(sdp);
5898
5963
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5945,8 +6010,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5945
6010
  /* global RTCSessionDescriptionInit, navigator */
5946
6011
 
5947
6012
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5948
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5949
- const WAIT_FOR_ICE_TIMEOUT = 500;
5950
6013
 
5951
6014
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5952
6015
  const wazoMediaStreamFactory = (constraints ) => {
@@ -6136,38 +6199,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
6136
6199
  this._peerConnection = undefined;
6137
6200
  }
6138
6201
 
6139
- async _waitForValidGatheredIce() {
6140
- let tries = 0;
6141
-
6142
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
6143
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
6144
- tries,
6145
- max: MAX_WAIT_FOR_ICE_TRIES,
6146
- });
6147
-
6148
- tries++;
6149
-
6150
- // eslint-disable-next-line no-await-in-loop
6151
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
6152
- }
6153
-
6154
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
6155
- const errorMsg = 'No valid candidates found, can\'t answer the call';
6156
- const error = new Error(errorMsg);
6157
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
6158
-
6159
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
6160
- this.eventEmitter.emit('error', error);
6161
-
6162
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6163
- }
6164
-
6165
- // eslint-disable-next-line
6166
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6167
-
6168
- return this.getLocalSessionDescription();
6169
- }
6170
-
6171
6202
  // Overridden to send `inactive` in conference
6172
6203
  updateDirection(options , isConference = false,
6173
6204
  audioOnly = false) {
@@ -6960,7 +6991,9 @@ class WebRTCClient extends Emitter {
6960
6991
  const inviteOptions = {
6961
6992
  requestDelegate: {
6962
6993
  onAccept: (response ) => {
6963
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
6994
+ if (session.sessionDescriptionHandler.peerConnection) {
6995
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
6996
+ }
6964
6997
  this._onAccepted(session, response.session, true);
6965
6998
  },
6966
6999
  onReject: (response ) => {
@@ -7832,6 +7865,16 @@ class WebRTCClient extends Emitter {
7832
7865
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
7833
7866
  }
7834
7867
 
7868
+ // Useful in a react-native environment when remoteMediaStream is not updated
7869
+ getRemoteVideoStreamFromPc(sessionId ) {
7870
+ const pc = this.getPeerConnection(sessionId);
7871
+ if (!pc) {
7872
+ return null;
7873
+ }
7874
+
7875
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
7876
+ }
7877
+
7835
7878
  hasVideo(sessionId ) {
7836
7879
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
7837
7880
  }
@@ -8342,6 +8385,7 @@ class WebRTCClient extends Emitter {
8342
8385
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8343
8386
 
8344
8387
  pc.oniceconnectionstatechange = () => {
8388
+ logger$8.info('on ice connection state changed', { state: pc.iceConnectionState });
8345
8389
  if (pc.iceConnectionState === 'disconnected') {
8346
8390
  this.eventEmitter.emit(ON_DISCONNECTED$1);
8347
8391
  }
@@ -8570,25 +8614,25 @@ class WebRTCClient extends Emitter {
8570
8614
 
8571
8615
  stats.forEach(report => {
8572
8616
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8573
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8617
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8574
8618
  }
8575
8619
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8576
- audioBytesSent += report.bytesSent;
8620
+ audioBytesSent += Number(report.bytesSent);
8577
8621
  }
8578
8622
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8579
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8623
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8580
8624
  }
8581
8625
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8582
- packetsLost += report.packetsLost;
8583
- networkStats.packetsReceived = report.packetsReceived;
8584
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8626
+ packetsLost += Number(report.packetsLost);
8627
+ networkStats.packetsReceived = Number(report.packetsReceived);
8628
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8585
8629
  }
8586
8630
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8587
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8631
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8588
8632
  }
8589
8633
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8590
8634
  if ('framesPerSecond' in report) {
8591
- networkStats.framesPerSecond = report.framesPerSecond;
8635
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8592
8636
  }
8593
8637
  if ('framerateMean' in report) {
8594
8638
  // framerateMean is only available in FF
@@ -8596,32 +8640,36 @@ class WebRTCClient extends Emitter {
8596
8640
  }
8597
8641
  }
8598
8642
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8599
- packetsLost += report.packetsLost;
8600
- networkStats.roundTripTime = report.roundTripTime;
8601
- networkStats.jitter = report.jitter;
8643
+ packetsLost += Number(report.packetsLost);
8644
+ networkStats.roundTripTime = Number(report.roundTripTime);
8645
+ networkStats.jitter = Number(report.jitter);
8602
8646
  }
8603
8647
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8604
- packetsLost += report.packetsLost;
8648
+ packetsLost += Number(report.packetsLost);
8605
8649
  }
8606
8650
  if (report.type === 'transport') {
8607
- transportSent += report.bytesSent;
8608
- transportReceived += report.bytesReceived;
8651
+ transportSent += Number(report.bytesSent);
8652
+ transportReceived += Number(report.bytesReceived);
8609
8653
  }
8610
8654
  });
8611
8655
 
8612
8656
  networkStats.packetsLost = packetsLost;
8613
- networkStats.audioBytesSent = audioBytesSent;
8657
+ networkStats.totalAudioBytesSent = audioBytesSent;
8658
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8659
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8614
8660
  networkStats.audioBytesReceived = audioBytesReceived;
8615
- networkStats.videoBytesSent = videoBytesSent;
8616
- networkStats.videoBytesReceived = videoBytesReceived;
8661
+ networkStats.totalVideoBytesSent = videoBytesSent;
8662
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8663
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
8664
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
8665
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
8617
8666
  networkStats.transportSent = transportSent;
8618
- networkStats.transportReceived = transportReceived;
8667
+ networkStats.totalTransportReceived = transportReceived;
8668
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
8619
8669
 
8620
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
8621
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
8622
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
8623
-
8624
- networkStats.bandwidth = bandwidth;
8670
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
8671
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
8672
+ + networkStats.transportSent;
8625
8673
 
8626
8674
  this.eventEmitter.emit(ON_NETWORK_STATS$1, session, networkStats, this.sessionNetworkStats[sessionId]);
8627
8675
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -9003,7 +9051,10 @@ class WebRTCPhone extends Emitter {
9003
9051
 
9004
9052
  onCancel(message);
9005
9053
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
9006
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
9054
+ const callSession = this._createCallSession(sipSession);
9055
+ delete this.callSessions[callSession.getId()];
9056
+
9057
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
9007
9058
  };
9008
9059
  } else if (sipSession instanceof Invitation) {
9009
9060
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -9032,9 +9083,11 @@ class WebRTCPhone extends Emitter {
9032
9083
  case SessionState.Terminated: {
9033
9084
  logger$7.info('WebRTC phone - call terminated', { sipId: sipSession.id });
9034
9085
 
9086
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
9087
+ const callSession = this._createCallSession(sipSession);
9035
9088
  const wasCurrentSession = this._onCallTerminated(sipSession);
9036
9089
 
9037
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
9090
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
9038
9091
  }
9039
9092
  }
9040
9093
  });
@@ -9182,18 +9235,20 @@ class WebRTCPhone extends Emitter {
9182
9235
  screenTrack,
9183
9236
  });
9184
9237
 
9185
- screenTrack.onended = () => {
9186
- logger$7.info('WebRTC phone - on screenshare ended', {
9187
- hadVideo,
9188
- id: this.getSipSessionId(sipSession),
9189
- screenTrack,
9190
- });
9238
+ if (screenTrack) {
9239
+ screenTrack.onended = () => {
9240
+ logger$7.info('WebRTC phone - on screenshare ended', {
9241
+ hadVideo,
9242
+ id: this.getSipSessionId(sipSession),
9243
+ screenTrack,
9244
+ });
9191
9245
 
9192
- this.eventEmitter.emit(
9193
- ON_SHARE_SCREEN_ENDING,
9194
- this._createCallSession(sipSession, callSession),
9195
- );
9196
- };
9246
+ this.eventEmitter.emit(
9247
+ ON_SHARE_SCREEN_ENDING,
9248
+ this._createCallSession(sipSession, callSession),
9249
+ );
9250
+ };
9251
+ }
9197
9252
 
9198
9253
  this.currentScreenShare = {
9199
9254
  stream: screenStream,
@@ -9982,6 +10037,10 @@ class WebRTCPhone extends Emitter {
9982
10037
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
9983
10038
  }
9984
10039
 
10040
+ getRemoteVideoStreamFromPc(callSession ) {
10041
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
10042
+ }
10043
+
9985
10044
  hasRemoteVideo(callSession ) {
9986
10045
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
9987
10046
  }
@@ -10665,6 +10724,11 @@ class Phone extends Emitter {
10665
10724
  return this.getRemoteVideoStream(callSession);
10666
10725
  }
10667
10726
 
10727
+ // Useful in a react-native environment when remoteMediaStream is not updated
10728
+ getRemoteVideoStreamFromPc(callSession ) {
10729
+ return this.phone ? this.phone.getRemoteVideoStreamFromPc(callSession) : false;
10730
+ }
10731
+
10668
10732
  hasVideo(callSession ) {
10669
10733
  return this.phone ? this.phone.hasVideo(callSession) : false;
10670
10734
  }
@@ -10824,6 +10888,7 @@ const AGENT_PAUSED = 'agent_paused';
10824
10888
  const AGENT_UNPAUSED = 'agent_unpaused';
10825
10889
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
10826
10890
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
10891
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
10827
10892
 
10828
10893
  const BLACKLIST_EVENTS = [
10829
10894
  CHAT_MESSAGE_SENT,
@@ -11174,6 +11239,7 @@ WebSocketClient.eventLists = [
11174
11239
  AGENT_UNPAUSED,
11175
11240
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
11176
11241
  CONFERENCE_ADHOC_DELETED,
11242
+ MEETING_USER_PROGRESS,
11177
11243
  ];
11178
11244
 
11179
11245
  var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
@@ -11244,6 +11310,7 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
11244
11310
  AGENT_UNPAUSED: AGENT_UNPAUSED,
11245
11311
  CONFERENCE_ADHOC_PARTICIPANT_LEFT: CONFERENCE_ADHOC_PARTICIPANT_LEFT,
11246
11312
  CONFERENCE_ADHOC_DELETED: CONFERENCE_ADHOC_DELETED,
11313
+ MEETING_USER_PROGRESS: MEETING_USER_PROGRESS,
11247
11314
  HEARTBEAT_ENGINE_VERSION: HEARTBEAT_ENGINE_VERSION,
11248
11315
  'default': WebSocketClient
11249
11316
  });
@@ -126,6 +126,7 @@ class IssueReporter {
126
126
 
127
127
 
128
128
 
129
+
129
130
 
130
131
  constructor() {
131
132
  addLevelsTo(this);
@@ -137,12 +138,17 @@ class IssueReporter {
137
138
  this.bufferTimeout = null;
138
139
  this._boundProcessBuffer = this._processBuffer.bind(this);
139
140
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
141
+ this._callback = null;
140
142
  }
141
143
 
142
144
  init() {
143
145
  this._catchConsole();
144
146
  }
145
147
 
148
+ setCallback(cb ) {
149
+ this._callback = cb;
150
+ }
151
+
146
152
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
147
153
  this.remoteClientConfiguration = configuration;
148
154
  }
@@ -178,6 +184,7 @@ class IssueReporter {
178
184
 
179
185
  // Handle category label
180
186
  let category = null;
187
+ let skipSendToRemote = false;
181
188
  let extra = {};
182
189
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
183
190
  category = args[0].split('=')[1];
@@ -193,6 +200,7 @@ class IssueReporter {
193
200
  errorMessage: lastArg.message,
194
201
  errorStack: lastArg.stack,
195
202
  errorType: lastArg.constructor.name,
203
+ skipSendToRemote: lastArg.skipSendToRemote,
196
204
  };
197
205
  } else {
198
206
  extra = lastArg;
@@ -201,6 +209,11 @@ class IssueReporter {
201
209
  args.splice(1, 1);
202
210
  }
203
211
 
212
+ if (extra.skipSendToRemote) {
213
+ skipSendToRemote = true;
214
+ delete extra.skipSendToRemote;
215
+ }
216
+
204
217
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
205
218
  const message = args.join(', ');
206
219
  let consoleMessage = message;
@@ -221,7 +234,13 @@ class IssueReporter {
221
234
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
222
235
  oldMethod.apply(oldMethod, [date, consoleMessage]);
223
236
 
224
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
237
+ if (this._callback) {
238
+ this._callback(level, consoleMessage);
239
+ }
240
+
241
+ if (!skipSendToRemote) {
242
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
243
+ }
225
244
  }
226
245
 
227
246
  logRequest(url , options , response , start ) {
@@ -366,7 +385,11 @@ class IssueReporter {
366
385
  },
367
386
  // $FlowFixMe
368
387
  body,
369
- }).catch(() => {
388
+ }).catch((e ) => {
389
+ // $FlowFixMe
390
+ e.skipSendToRemote = true;
391
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
392
+
370
393
  setTimeout(() => {
371
394
  if (isArray) {
372
395
  payload = payload.map(message => {
@@ -126,6 +126,7 @@ class IssueReporter {
126
126
 
127
127
 
128
128
 
129
+
129
130
 
130
131
  constructor() {
131
132
  addLevelsTo(this);
@@ -137,12 +138,17 @@ class IssueReporter {
137
138
  this.bufferTimeout = null;
138
139
  this._boundProcessBuffer = this._processBuffer.bind(this);
139
140
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
141
+ this._callback = null;
140
142
  }
141
143
 
142
144
  init() {
143
145
  this._catchConsole();
144
146
  }
145
147
 
148
+ setCallback(cb ) {
149
+ this._callback = cb;
150
+ }
151
+
146
152
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
147
153
  this.remoteClientConfiguration = configuration;
148
154
  }
@@ -178,6 +184,7 @@ class IssueReporter {
178
184
 
179
185
  // Handle category label
180
186
  let category = null;
187
+ let skipSendToRemote = false;
181
188
  let extra = {};
182
189
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
183
190
  category = args[0].split('=')[1];
@@ -193,6 +200,7 @@ class IssueReporter {
193
200
  errorMessage: lastArg.message,
194
201
  errorStack: lastArg.stack,
195
202
  errorType: lastArg.constructor.name,
203
+ skipSendToRemote: lastArg.skipSendToRemote,
196
204
  };
197
205
  } else {
198
206
  extra = lastArg;
@@ -201,6 +209,11 @@ class IssueReporter {
201
209
  args.splice(1, 1);
202
210
  }
203
211
 
212
+ if (extra.skipSendToRemote) {
213
+ skipSendToRemote = true;
214
+ delete extra.skipSendToRemote;
215
+ }
216
+
204
217
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
205
218
  const message = args.join(', ');
206
219
  let consoleMessage = message;
@@ -221,7 +234,13 @@ class IssueReporter {
221
234
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
222
235
  oldMethod.apply(oldMethod, [date, consoleMessage]);
223
236
 
224
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
237
+ if (this._callback) {
238
+ this._callback(level, consoleMessage);
239
+ }
240
+
241
+ if (!skipSendToRemote) {
242
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
243
+ }
225
244
  }
226
245
 
227
246
  logRequest(url , options , response , start ) {
@@ -366,7 +385,11 @@ class IssueReporter {
366
385
  },
367
386
  // $FlowFixMe
368
387
  body,
369
- }).catch(() => {
388
+ }).catch((e ) => {
389
+ // $FlowFixMe
390
+ e.skipSendToRemote = true;
391
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
392
+
370
393
  setTimeout(() => {
371
394
  if (isArray) {
372
395
  payload = payload.map(message => {