@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
@@ -875,6 +875,9 @@ class Contact {
875
875
  }
876
876
 
877
877
  static parseMany(response ) {
878
+ if (!response || !response.results) {
879
+ return [];
880
+ }
878
881
  return response.results.map(r => Contact.parse(r, response.column_types));
879
882
  }
880
883
 
@@ -1646,6 +1649,7 @@ class IssueReporter {
1646
1649
 
1647
1650
 
1648
1651
 
1652
+
1649
1653
 
1650
1654
  constructor() {
1651
1655
  addLevelsTo(this);
@@ -1657,12 +1661,17 @@ class IssueReporter {
1657
1661
  this.bufferTimeout = null;
1658
1662
  this._boundProcessBuffer = this._processBuffer.bind(this);
1659
1663
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
1664
+ this._callback = null;
1660
1665
  }
1661
1666
 
1662
1667
  init() {
1663
1668
  this._catchConsole();
1664
1669
  }
1665
1670
 
1671
+ setCallback(cb ) {
1672
+ this._callback = cb;
1673
+ }
1674
+
1666
1675
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
1667
1676
  this.remoteClientConfiguration = configuration;
1668
1677
  }
@@ -1698,6 +1707,7 @@ class IssueReporter {
1698
1707
 
1699
1708
  // Handle category label
1700
1709
  let category = null;
1710
+ let skipSendToRemote = false;
1701
1711
  let extra = {};
1702
1712
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
1703
1713
  category = args[0].split('=')[1];
@@ -1713,6 +1723,7 @@ class IssueReporter {
1713
1723
  errorMessage: lastArg.message,
1714
1724
  errorStack: lastArg.stack,
1715
1725
  errorType: lastArg.constructor.name,
1726
+ skipSendToRemote: lastArg.skipSendToRemote,
1716
1727
  };
1717
1728
  } else {
1718
1729
  extra = lastArg;
@@ -1721,6 +1732,11 @@ class IssueReporter {
1721
1732
  args.splice(1, 1);
1722
1733
  }
1723
1734
 
1735
+ if (extra.skipSendToRemote) {
1736
+ skipSendToRemote = true;
1737
+ delete extra.skipSendToRemote;
1738
+ }
1739
+
1724
1740
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
1725
1741
  const message = args.join(', ');
1726
1742
  let consoleMessage = message;
@@ -1741,7 +1757,13 @@ class IssueReporter {
1741
1757
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
1742
1758
  oldMethod.apply(oldMethod, [date, consoleMessage]);
1743
1759
 
1744
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
1760
+ if (this._callback) {
1761
+ this._callback(level, consoleMessage);
1762
+ }
1763
+
1764
+ if (!skipSendToRemote) {
1765
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
1766
+ }
1745
1767
  }
1746
1768
 
1747
1769
  logRequest(url , options , response , start ) {
@@ -1886,7 +1908,11 @@ class IssueReporter {
1886
1908
  },
1887
1909
  // $FlowFixMe
1888
1910
  body,
1889
- }).catch(() => {
1911
+ }).catch((e ) => {
1912
+ // $FlowFixMe
1913
+ e.skipSendToRemote = true;
1914
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
1915
+
1890
1916
  setTimeout(() => {
1891
1917
  if (isArray) {
1892
1918
  payload = payload.map(message => {
@@ -2645,11 +2671,27 @@ class Meeting {
2645
2671
  });
2646
2672
  }
2647
2673
 
2674
+ static parseMany(items ) {
2675
+ if (!items) {
2676
+ return [];
2677
+ }
2678
+ return items.map(plain => Meeting.parse(plain));
2679
+ }
2680
+
2648
2681
  static newFrom(meeting ) {
2649
2682
  return newFrom(meeting, Meeting);
2650
2683
  }
2651
2684
 
2652
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2685
+ constructor({
2686
+ uuid,
2687
+ name,
2688
+ guestSipAuthorization,
2689
+ ownerUuids,
2690
+ port,
2691
+ uri,
2692
+ number,
2693
+ persistent,
2694
+ } = {}) {
2653
2695
  this.guestSipAuthorization = guestSipAuthorization;
2654
2696
  this.uri = uri;
2655
2697
  this.name = name;
@@ -2735,8 +2777,11 @@ var confdMethods = (client , baseUrl ) => ({
2735
2777
  }
2736
2778
  },
2737
2779
 
2738
- createMyMeeting: (name ) =>
2739
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2780
+ getMyMeetings: () =>
2781
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2782
+
2783
+ createMyMeeting: (name , persistent ) =>
2784
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2740
2785
 
2741
2786
  deleteMyMeeting: (meetingUuid ) =>
2742
2787
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2832,6 +2877,10 @@ class ChatMessage {
2832
2877
 
2833
2878
 
2834
2879
  static parseMany(plain ) {
2880
+ if (!plain || !plain.items) {
2881
+ return [];
2882
+ }
2883
+
2835
2884
  return plain.items.map(item => ChatMessage.parse(item));
2836
2885
  }
2837
2886
 
@@ -2941,6 +2990,9 @@ class Voicemail {
2941
2990
  }
2942
2991
 
2943
2992
  static parseMany(plain ) {
2993
+ if (!plain) {
2994
+ return [];
2995
+ }
2944
2996
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2945
2997
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2946
2998
 
@@ -3050,6 +3102,9 @@ class Call {
3050
3102
 
3051
3103
 
3052
3104
  static parseMany(plain ) {
3105
+ if (!plain) {
3106
+ return [];
3107
+ }
3053
3108
  return plain.map((plainCall ) => Call.parse(plainCall));
3054
3109
  }
3055
3110
 
@@ -3593,6 +3648,9 @@ class Recording {
3593
3648
 
3594
3649
 
3595
3650
  static parseMany(recordings = []) {
3651
+ if (!recordings) {
3652
+ return [];
3653
+ }
3596
3654
  return recordings.map(item => Recording.parse(item));
3597
3655
  }
3598
3656
 
@@ -3694,6 +3752,10 @@ class CallLog {
3694
3752
  }
3695
3753
 
3696
3754
  static parseMany(plain ) {
3755
+ if (!plain || !plain.items) {
3756
+ return [];
3757
+ }
3758
+
3697
3759
  return plain.items.map(item => CallLog.parse(item));
3698
3760
  }
3699
3761
 
@@ -4263,6 +4325,10 @@ class CTIPhone extends Emitter {
4263
4325
  return false;
4264
4326
  }
4265
4327
 
4328
+ hasAVideoTrack() {
4329
+ return false;
4330
+ }
4331
+
4266
4332
  getLocalStreamForCall() {
4267
4333
  return null;
4268
4334
  }
@@ -4656,6 +4722,9 @@ class ChatRoom {
4656
4722
 
4657
4723
 
4658
4724
  static parseMany(plain ) {
4725
+ if (!plain || !plain.items) {
4726
+ return [];
4727
+ }
4659
4728
  return plain.items.map(item => ChatRoom.parse(item));
4660
4729
  }
4661
4730
 
@@ -5637,10 +5706,6 @@ const getSrflxOrRelay = (candidates ) =>
5637
5706
  candidates
5638
5707
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5639
5708
 
5640
- const areCandidateValid = (candidates ) =>
5641
- getSrflxOrRelay(candidates)
5642
- .length > 0;
5643
-
5644
5709
  const getVideoDirection = (sdp ) => {
5645
5710
  const parsedSdp = sdpParser__default['default'].parse(sdp);
5646
5711
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5693,8 +5758,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5693
5758
  /* global RTCSessionDescriptionInit, navigator */
5694
5759
 
5695
5760
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5696
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5697
- const WAIT_FOR_ICE_TIMEOUT = 500;
5698
5761
 
5699
5762
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5700
5763
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5884,38 +5947,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5884
5947
  this._peerConnection = undefined;
5885
5948
  }
5886
5949
 
5887
- async _waitForValidGatheredIce() {
5888
- let tries = 0;
5889
-
5890
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5891
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5892
- tries,
5893
- max: MAX_WAIT_FOR_ICE_TRIES,
5894
- });
5895
-
5896
- tries++;
5897
-
5898
- // eslint-disable-next-line no-await-in-loop
5899
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5900
- }
5901
-
5902
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5903
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5904
- const error = new Error(errorMsg);
5905
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5906
-
5907
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5908
- this.eventEmitter.emit('error', error);
5909
-
5910
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5911
- }
5912
-
5913
- // eslint-disable-next-line
5914
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5915
-
5916
- return this.getLocalSessionDescription();
5917
- }
5918
-
5919
5950
  // Overridden to send `inactive` in conference
5920
5951
  updateDirection(options , isConference = false,
5921
5952
  audioOnly = false) {
@@ -6708,7 +6739,9 @@ class WebRTCClient extends Emitter {
6708
6739
  const inviteOptions = {
6709
6740
  requestDelegate: {
6710
6741
  onAccept: (response ) => {
6711
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
6742
+ if (session.sessionDescriptionHandler.peerConnection) {
6743
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
6744
+ }
6712
6745
  this._onAccepted(session, response.session, true);
6713
6746
  },
6714
6747
  onReject: (response ) => {
@@ -7580,6 +7613,16 @@ class WebRTCClient extends Emitter {
7580
7613
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
7581
7614
  }
7582
7615
 
7616
+ // Useful in a react-native environment when remoteMediaStream is not updated
7617
+ getRemoteVideoStreamFromPc(sessionId ) {
7618
+ const pc = this.getPeerConnection(sessionId);
7619
+ if (!pc) {
7620
+ return null;
7621
+ }
7622
+
7623
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
7624
+ }
7625
+
7583
7626
  hasVideo(sessionId ) {
7584
7627
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
7585
7628
  }
@@ -8090,6 +8133,7 @@ class WebRTCClient extends Emitter {
8090
8133
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8091
8134
 
8092
8135
  pc.oniceconnectionstatechange = () => {
8136
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
8093
8137
  if (pc.iceConnectionState === 'disconnected') {
8094
8138
  this.eventEmitter.emit(ON_DISCONNECTED$1);
8095
8139
  }
@@ -8318,25 +8362,25 @@ class WebRTCClient extends Emitter {
8318
8362
 
8319
8363
  stats.forEach(report => {
8320
8364
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8321
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8365
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8322
8366
  }
8323
8367
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8324
- audioBytesSent += report.bytesSent;
8368
+ audioBytesSent += Number(report.bytesSent);
8325
8369
  }
8326
8370
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8327
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8371
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8328
8372
  }
8329
8373
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8330
- packetsLost += report.packetsLost;
8331
- networkStats.packetsReceived = report.packetsReceived;
8332
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8374
+ packetsLost += Number(report.packetsLost);
8375
+ networkStats.packetsReceived = Number(report.packetsReceived);
8376
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8333
8377
  }
8334
8378
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8335
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8379
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8336
8380
  }
8337
8381
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8338
8382
  if ('framesPerSecond' in report) {
8339
- networkStats.framesPerSecond = report.framesPerSecond;
8383
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8340
8384
  }
8341
8385
  if ('framerateMean' in report) {
8342
8386
  // framerateMean is only available in FF
@@ -8344,32 +8388,36 @@ class WebRTCClient extends Emitter {
8344
8388
  }
8345
8389
  }
8346
8390
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8347
- packetsLost += report.packetsLost;
8348
- networkStats.roundTripTime = report.roundTripTime;
8349
- networkStats.jitter = report.jitter;
8391
+ packetsLost += Number(report.packetsLost);
8392
+ networkStats.roundTripTime = Number(report.roundTripTime);
8393
+ networkStats.jitter = Number(report.jitter);
8350
8394
  }
8351
8395
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8352
- packetsLost += report.packetsLost;
8396
+ packetsLost += Number(report.packetsLost);
8353
8397
  }
8354
8398
  if (report.type === 'transport') {
8355
- transportSent += report.bytesSent;
8356
- transportReceived += report.bytesReceived;
8399
+ transportSent += Number(report.bytesSent);
8400
+ transportReceived += Number(report.bytesReceived);
8357
8401
  }
8358
8402
  });
8359
8403
 
8360
8404
  networkStats.packetsLost = packetsLost;
8361
- networkStats.audioBytesSent = audioBytesSent;
8405
+ networkStats.totalAudioBytesSent = audioBytesSent;
8406
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8407
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8362
8408
  networkStats.audioBytesReceived = audioBytesReceived;
8363
- networkStats.videoBytesSent = videoBytesSent;
8364
- networkStats.videoBytesReceived = videoBytesReceived;
8409
+ networkStats.totalVideoBytesSent = videoBytesSent;
8410
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8411
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
8412
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
8413
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
8365
8414
  networkStats.transportSent = transportSent;
8366
- networkStats.transportReceived = transportReceived;
8415
+ networkStats.totalTransportReceived = transportReceived;
8416
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
8367
8417
 
8368
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
8369
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
8370
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
8371
-
8372
- networkStats.bandwidth = bandwidth;
8418
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
8419
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
8420
+ + networkStats.transportSent;
8373
8421
 
8374
8422
  this.eventEmitter.emit(ON_NETWORK_STATS$1, session, networkStats, this.sessionNetworkStats[sessionId]);
8375
8423
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -8751,7 +8799,10 @@ class WebRTCPhone extends Emitter {
8751
8799
 
8752
8800
  onCancel(message);
8753
8801
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
8754
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
8802
+ const callSession = this._createCallSession(sipSession);
8803
+ delete this.callSessions[callSession.getId()];
8804
+
8805
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
8755
8806
  };
8756
8807
  } else if (sipSession instanceof invitation.Invitation) {
8757
8808
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -8780,9 +8831,11 @@ class WebRTCPhone extends Emitter {
8780
8831
  case sessionState.SessionState.Terminated: {
8781
8832
  logger$8.info('WebRTC phone - call terminated', { sipId: sipSession.id });
8782
8833
 
8834
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
8835
+ const callSession = this._createCallSession(sipSession);
8783
8836
  const wasCurrentSession = this._onCallTerminated(sipSession);
8784
8837
 
8785
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
8838
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
8786
8839
  }
8787
8840
  }
8788
8841
  });
@@ -8930,18 +8983,20 @@ class WebRTCPhone extends Emitter {
8930
8983
  screenTrack,
8931
8984
  });
8932
8985
 
8933
- screenTrack.onended = () => {
8934
- logger$8.info('WebRTC phone - on screenshare ended', {
8935
- hadVideo,
8936
- id: this.getSipSessionId(sipSession),
8937
- screenTrack,
8938
- });
8986
+ if (screenTrack) {
8987
+ screenTrack.onended = () => {
8988
+ logger$8.info('WebRTC phone - on screenshare ended', {
8989
+ hadVideo,
8990
+ id: this.getSipSessionId(sipSession),
8991
+ screenTrack,
8992
+ });
8939
8993
 
8940
- this.eventEmitter.emit(
8941
- ON_SHARE_SCREEN_ENDING,
8942
- this._createCallSession(sipSession, callSession),
8943
- );
8944
- };
8994
+ this.eventEmitter.emit(
8995
+ ON_SHARE_SCREEN_ENDING,
8996
+ this._createCallSession(sipSession, callSession),
8997
+ );
8998
+ };
8999
+ }
8945
9000
 
8946
9001
  this.currentScreenShare = {
8947
9002
  stream: screenStream,
@@ -9730,6 +9785,10 @@ class WebRTCPhone extends Emitter {
9730
9785
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
9731
9786
  }
9732
9787
 
9788
+ getRemoteVideoStreamFromPc(callSession ) {
9789
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
9790
+ }
9791
+
9733
9792
  hasRemoteVideo(callSession ) {
9734
9793
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
9735
9794
  }
@@ -10413,6 +10472,11 @@ class Phone extends Emitter {
10413
10472
  return this.getRemoteVideoStream(callSession);
10414
10473
  }
10415
10474
 
10475
+ // Useful in a react-native environment when remoteMediaStream is not updated
10476
+ getRemoteVideoStreamFromPc(callSession ) {
10477
+ return this.phone ? this.phone.getRemoteVideoStreamFromPc(callSession) : false;
10478
+ }
10479
+
10416
10480
  hasVideo(callSession ) {
10417
10481
  return this.phone ? this.phone.hasVideo(callSession) : false;
10418
10482
  }
@@ -10572,6 +10636,7 @@ const AGENT_PAUSED = 'agent_paused';
10572
10636
  const AGENT_UNPAUSED = 'agent_unpaused';
10573
10637
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
10574
10638
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
10639
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
10575
10640
 
10576
10641
  const BLACKLIST_EVENTS = [
10577
10642
  CHAT_MESSAGE_SENT,
@@ -10922,6 +10987,7 @@ WebSocketClient.eventLists = [
10922
10987
  AGENT_UNPAUSED,
10923
10988
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10924
10989
  CONFERENCE_ADHOC_DELETED,
10990
+ MEETING_USER_PROGRESS,
10925
10991
  ];
10926
10992
 
10927
10993
  var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
@@ -10992,6 +11058,7 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
10992
11058
  AGENT_UNPAUSED: AGENT_UNPAUSED,
10993
11059
  CONFERENCE_ADHOC_PARTICIPANT_LEFT: CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10994
11060
  CONFERENCE_ADHOC_DELETED: CONFERENCE_ADHOC_DELETED,
11061
+ MEETING_USER_PROGRESS: MEETING_USER_PROGRESS,
10995
11062
  HEARTBEAT_ENGINE_VERSION: HEARTBEAT_ENGINE_VERSION,
10996
11063
  'default': WebSocketClient
10997
11064
  });