@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
 
@@ -5625,10 +5694,6 @@ const getSrflxOrRelay = (candidates ) =>
5625
5694
  candidates
5626
5695
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5627
5696
 
5628
- const areCandidateValid = (candidates ) =>
5629
- getSrflxOrRelay(candidates)
5630
- .length > 0;
5631
-
5632
5697
  const getVideoDirection = (sdp ) => {
5633
5698
  const parsedSdp = sdpParser.parse(sdp);
5634
5699
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5681,8 +5746,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5681
5746
  /* global RTCSessionDescriptionInit, navigator */
5682
5747
 
5683
5748
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5684
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5685
- const WAIT_FOR_ICE_TIMEOUT = 500;
5686
5749
 
5687
5750
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5688
5751
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5872,38 +5935,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
5872
5935
  this._peerConnection = undefined;
5873
5936
  }
5874
5937
 
5875
- async _waitForValidGatheredIce() {
5876
- let tries = 0;
5877
-
5878
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5879
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5880
- tries,
5881
- max: MAX_WAIT_FOR_ICE_TRIES,
5882
- });
5883
-
5884
- tries++;
5885
-
5886
- // eslint-disable-next-line no-await-in-loop
5887
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5888
- }
5889
-
5890
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5891
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5892
- const error = new Error(errorMsg);
5893
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5894
-
5895
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5896
- this.eventEmitter.emit('error', error);
5897
-
5898
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5899
- }
5900
-
5901
- // eslint-disable-next-line
5902
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5903
-
5904
- return this.getLocalSessionDescription();
5905
- }
5906
-
5907
5938
  // Overridden to send `inactive` in conference
5908
5939
  updateDirection(options , isConference = false,
5909
5940
  audioOnly = false) {
@@ -6696,7 +6727,9 @@ class WebRTCClient extends Emitter {
6696
6727
  const inviteOptions = {
6697
6728
  requestDelegate: {
6698
6729
  onAccept: (response ) => {
6699
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
6730
+ if (session.sessionDescriptionHandler.peerConnection) {
6731
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
6732
+ }
6700
6733
  this._onAccepted(session, response.session, true);
6701
6734
  },
6702
6735
  onReject: (response ) => {
@@ -7568,6 +7601,16 @@ class WebRTCClient extends Emitter {
7568
7601
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
7569
7602
  }
7570
7603
 
7604
+ // Useful in a react-native environment when remoteMediaStream is not updated
7605
+ getRemoteVideoStreamFromPc(sessionId ) {
7606
+ const pc = this.getPeerConnection(sessionId);
7607
+ if (!pc) {
7608
+ return null;
7609
+ }
7610
+
7611
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
7612
+ }
7613
+
7571
7614
  hasVideo(sessionId ) {
7572
7615
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
7573
7616
  }
@@ -8078,6 +8121,7 @@ class WebRTCClient extends Emitter {
8078
8121
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8079
8122
 
8080
8123
  pc.oniceconnectionstatechange = () => {
8124
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
8081
8125
  if (pc.iceConnectionState === 'disconnected') {
8082
8126
  this.eventEmitter.emit(ON_DISCONNECTED$1);
8083
8127
  }
@@ -8306,25 +8350,25 @@ class WebRTCClient extends Emitter {
8306
8350
 
8307
8351
  stats.forEach(report => {
8308
8352
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8309
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8353
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8310
8354
  }
8311
8355
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8312
- audioBytesSent += report.bytesSent;
8356
+ audioBytesSent += Number(report.bytesSent);
8313
8357
  }
8314
8358
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8315
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8359
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8316
8360
  }
8317
8361
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8318
- packetsLost += report.packetsLost;
8319
- networkStats.packetsReceived = report.packetsReceived;
8320
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8362
+ packetsLost += Number(report.packetsLost);
8363
+ networkStats.packetsReceived = Number(report.packetsReceived);
8364
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8321
8365
  }
8322
8366
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8323
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8367
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8324
8368
  }
8325
8369
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8326
8370
  if ('framesPerSecond' in report) {
8327
- networkStats.framesPerSecond = report.framesPerSecond;
8371
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8328
8372
  }
8329
8373
  if ('framerateMean' in report) {
8330
8374
  // framerateMean is only available in FF
@@ -8332,32 +8376,36 @@ class WebRTCClient extends Emitter {
8332
8376
  }
8333
8377
  }
8334
8378
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8335
- packetsLost += report.packetsLost;
8336
- networkStats.roundTripTime = report.roundTripTime;
8337
- networkStats.jitter = report.jitter;
8379
+ packetsLost += Number(report.packetsLost);
8380
+ networkStats.roundTripTime = Number(report.roundTripTime);
8381
+ networkStats.jitter = Number(report.jitter);
8338
8382
  }
8339
8383
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8340
- packetsLost += report.packetsLost;
8384
+ packetsLost += Number(report.packetsLost);
8341
8385
  }
8342
8386
  if (report.type === 'transport') {
8343
- transportSent += report.bytesSent;
8344
- transportReceived += report.bytesReceived;
8387
+ transportSent += Number(report.bytesSent);
8388
+ transportReceived += Number(report.bytesReceived);
8345
8389
  }
8346
8390
  });
8347
8391
 
8348
8392
  networkStats.packetsLost = packetsLost;
8349
- networkStats.audioBytesSent = audioBytesSent;
8393
+ networkStats.totalAudioBytesSent = audioBytesSent;
8394
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8395
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8350
8396
  networkStats.audioBytesReceived = audioBytesReceived;
8351
- networkStats.videoBytesSent = videoBytesSent;
8352
- networkStats.videoBytesReceived = videoBytesReceived;
8397
+ networkStats.totalVideoBytesSent = videoBytesSent;
8398
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8399
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
8400
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
8401
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
8353
8402
  networkStats.transportSent = transportSent;
8354
- networkStats.transportReceived = transportReceived;
8403
+ networkStats.totalTransportReceived = transportReceived;
8404
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
8355
8405
 
8356
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
8357
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
8358
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
8359
-
8360
- networkStats.bandwidth = bandwidth;
8406
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
8407
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
8408
+ + networkStats.transportSent;
8361
8409
 
8362
8410
  this.eventEmitter.emit(ON_NETWORK_STATS$1, session, networkStats, this.sessionNetworkStats[sessionId]);
8363
8411
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -8739,7 +8787,10 @@ class WebRTCPhone extends Emitter {
8739
8787
 
8740
8788
  onCancel(message);
8741
8789
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
8742
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
8790
+ const callSession = this._createCallSession(sipSession);
8791
+ delete this.callSessions[callSession.getId()];
8792
+
8793
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
8743
8794
  };
8744
8795
  } else if (sipSession instanceof Invitation) {
8745
8796
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -8768,9 +8819,11 @@ class WebRTCPhone extends Emitter {
8768
8819
  case SessionState.Terminated: {
8769
8820
  logger$8.info('WebRTC phone - call terminated', { sipId: sipSession.id });
8770
8821
 
8822
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
8823
+ const callSession = this._createCallSession(sipSession);
8771
8824
  const wasCurrentSession = this._onCallTerminated(sipSession);
8772
8825
 
8773
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
8826
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
8774
8827
  }
8775
8828
  }
8776
8829
  });
@@ -8918,18 +8971,20 @@ class WebRTCPhone extends Emitter {
8918
8971
  screenTrack,
8919
8972
  });
8920
8973
 
8921
- screenTrack.onended = () => {
8922
- logger$8.info('WebRTC phone - on screenshare ended', {
8923
- hadVideo,
8924
- id: this.getSipSessionId(sipSession),
8925
- screenTrack,
8926
- });
8974
+ if (screenTrack) {
8975
+ screenTrack.onended = () => {
8976
+ logger$8.info('WebRTC phone - on screenshare ended', {
8977
+ hadVideo,
8978
+ id: this.getSipSessionId(sipSession),
8979
+ screenTrack,
8980
+ });
8927
8981
 
8928
- this.eventEmitter.emit(
8929
- ON_SHARE_SCREEN_ENDING,
8930
- this._createCallSession(sipSession, callSession),
8931
- );
8932
- };
8982
+ this.eventEmitter.emit(
8983
+ ON_SHARE_SCREEN_ENDING,
8984
+ this._createCallSession(sipSession, callSession),
8985
+ );
8986
+ };
8987
+ }
8933
8988
 
8934
8989
  this.currentScreenShare = {
8935
8990
  stream: screenStream,
@@ -9718,6 +9773,10 @@ class WebRTCPhone extends Emitter {
9718
9773
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
9719
9774
  }
9720
9775
 
9776
+ getRemoteVideoStreamFromPc(callSession ) {
9777
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
9778
+ }
9779
+
9721
9780
  hasRemoteVideo(callSession ) {
9722
9781
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
9723
9782
  }
@@ -10401,6 +10460,11 @@ class Phone extends Emitter {
10401
10460
  return this.getRemoteVideoStream(callSession);
10402
10461
  }
10403
10462
 
10463
+ // Useful in a react-native environment when remoteMediaStream is not updated
10464
+ getRemoteVideoStreamFromPc(callSession ) {
10465
+ return this.phone ? this.phone.getRemoteVideoStreamFromPc(callSession) : false;
10466
+ }
10467
+
10404
10468
  hasVideo(callSession ) {
10405
10469
  return this.phone ? this.phone.hasVideo(callSession) : false;
10406
10470
  }
@@ -10560,6 +10624,7 @@ const AGENT_PAUSED = 'agent_paused';
10560
10624
  const AGENT_UNPAUSED = 'agent_unpaused';
10561
10625
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
10562
10626
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
10627
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
10563
10628
 
10564
10629
  const BLACKLIST_EVENTS = [
10565
10630
  CHAT_MESSAGE_SENT,
@@ -10910,6 +10975,7 @@ WebSocketClient.eventLists = [
10910
10975
  AGENT_UNPAUSED,
10911
10976
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10912
10977
  CONFERENCE_ADHOC_DELETED,
10978
+ MEETING_USER_PROGRESS,
10913
10979
  ];
10914
10980
 
10915
10981
  var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
@@ -10980,6 +11046,7 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
10980
11046
  AGENT_UNPAUSED: AGENT_UNPAUSED,
10981
11047
  CONFERENCE_ADHOC_PARTICIPANT_LEFT: CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10982
11048
  CONFERENCE_ADHOC_DELETED: CONFERENCE_ADHOC_DELETED,
11049
+ MEETING_USER_PROGRESS: MEETING_USER_PROGRESS,
10983
11050
  HEARTBEAT_ENGINE_VERSION: HEARTBEAT_ENGINE_VERSION,
10984
11051
  'default': WebSocketClient
10985
11052
  });