@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
@@ -873,6 +873,9 @@ class Contact {
873
873
  }
874
874
 
875
875
  static parseMany(response ) {
876
+ if (!response || !response.results) {
877
+ return [];
878
+ }
876
879
  return response.results.map(r => Contact.parse(r, response.column_types));
877
880
  }
878
881
 
@@ -1644,6 +1647,7 @@ class IssueReporter {
1644
1647
 
1645
1648
 
1646
1649
 
1650
+
1647
1651
 
1648
1652
  constructor() {
1649
1653
  addLevelsTo(this);
@@ -1655,12 +1659,17 @@ class IssueReporter {
1655
1659
  this.bufferTimeout = null;
1656
1660
  this._boundProcessBuffer = this._processBuffer.bind(this);
1657
1661
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
1662
+ this._callback = null;
1658
1663
  }
1659
1664
 
1660
1665
  init() {
1661
1666
  this._catchConsole();
1662
1667
  }
1663
1668
 
1669
+ setCallback(cb ) {
1670
+ this._callback = cb;
1671
+ }
1672
+
1664
1673
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
1665
1674
  this.remoteClientConfiguration = configuration;
1666
1675
  }
@@ -1696,6 +1705,7 @@ class IssueReporter {
1696
1705
 
1697
1706
  // Handle category label
1698
1707
  let category = null;
1708
+ let skipSendToRemote = false;
1699
1709
  let extra = {};
1700
1710
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
1701
1711
  category = args[0].split('=')[1];
@@ -1711,6 +1721,7 @@ class IssueReporter {
1711
1721
  errorMessage: lastArg.message,
1712
1722
  errorStack: lastArg.stack,
1713
1723
  errorType: lastArg.constructor.name,
1724
+ skipSendToRemote: lastArg.skipSendToRemote,
1714
1725
  };
1715
1726
  } else {
1716
1727
  extra = lastArg;
@@ -1719,6 +1730,11 @@ class IssueReporter {
1719
1730
  args.splice(1, 1);
1720
1731
  }
1721
1732
 
1733
+ if (extra.skipSendToRemote) {
1734
+ skipSendToRemote = true;
1735
+ delete extra.skipSendToRemote;
1736
+ }
1737
+
1722
1738
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
1723
1739
  const message = args.join(', ');
1724
1740
  let consoleMessage = message;
@@ -1739,7 +1755,13 @@ class IssueReporter {
1739
1755
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
1740
1756
  oldMethod.apply(oldMethod, [date, consoleMessage]);
1741
1757
 
1742
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
1758
+ if (this._callback) {
1759
+ this._callback(level, consoleMessage);
1760
+ }
1761
+
1762
+ if (!skipSendToRemote) {
1763
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
1764
+ }
1743
1765
  }
1744
1766
 
1745
1767
  logRequest(url , options , response , start ) {
@@ -1884,7 +1906,11 @@ class IssueReporter {
1884
1906
  },
1885
1907
  // $FlowFixMe
1886
1908
  body,
1887
- }).catch(() => {
1909
+ }).catch((e ) => {
1910
+ // $FlowFixMe
1911
+ e.skipSendToRemote = true;
1912
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
1913
+
1888
1914
  setTimeout(() => {
1889
1915
  if (isArray) {
1890
1916
  payload = payload.map(message => {
@@ -2643,11 +2669,27 @@ class Meeting {
2643
2669
  });
2644
2670
  }
2645
2671
 
2672
+ static parseMany(items ) {
2673
+ if (!items) {
2674
+ return [];
2675
+ }
2676
+ return items.map(plain => Meeting.parse(plain));
2677
+ }
2678
+
2646
2679
  static newFrom(meeting ) {
2647
2680
  return newFrom(meeting, Meeting);
2648
2681
  }
2649
2682
 
2650
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2683
+ constructor({
2684
+ uuid,
2685
+ name,
2686
+ guestSipAuthorization,
2687
+ ownerUuids,
2688
+ port,
2689
+ uri,
2690
+ number,
2691
+ persistent,
2692
+ } = {}) {
2651
2693
  this.guestSipAuthorization = guestSipAuthorization;
2652
2694
  this.uri = uri;
2653
2695
  this.name = name;
@@ -2733,8 +2775,11 @@ var confdMethods = (client , baseUrl ) => ({
2733
2775
  }
2734
2776
  },
2735
2777
 
2736
- createMyMeeting: (name ) =>
2737
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2778
+ getMyMeetings: () =>
2779
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2780
+
2781
+ createMyMeeting: (name , persistent ) =>
2782
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2738
2783
 
2739
2784
  deleteMyMeeting: (meetingUuid ) =>
2740
2785
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2830,6 +2875,10 @@ class ChatMessage {
2830
2875
 
2831
2876
 
2832
2877
  static parseMany(plain ) {
2878
+ if (!plain || !plain.items) {
2879
+ return [];
2880
+ }
2881
+
2833
2882
  return plain.items.map(item => ChatMessage.parse(item));
2834
2883
  }
2835
2884
 
@@ -2939,6 +2988,9 @@ class Voicemail {
2939
2988
  }
2940
2989
 
2941
2990
  static parseMany(plain ) {
2991
+ if (!plain) {
2992
+ return [];
2993
+ }
2942
2994
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2943
2995
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2944
2996
 
@@ -3048,6 +3100,9 @@ class Call {
3048
3100
 
3049
3101
 
3050
3102
  static parseMany(plain ) {
3103
+ if (!plain) {
3104
+ return [];
3105
+ }
3051
3106
  return plain.map((plainCall ) => Call.parse(plainCall));
3052
3107
  }
3053
3108
 
@@ -3591,6 +3646,9 @@ class Recording {
3591
3646
 
3592
3647
 
3593
3648
  static parseMany(recordings = []) {
3649
+ if (!recordings) {
3650
+ return [];
3651
+ }
3594
3652
  return recordings.map(item => Recording.parse(item));
3595
3653
  }
3596
3654
 
@@ -3692,6 +3750,10 @@ class CallLog {
3692
3750
  }
3693
3751
 
3694
3752
  static parseMany(plain ) {
3753
+ if (!plain || !plain.items) {
3754
+ return [];
3755
+ }
3756
+
3695
3757
  return plain.items.map(item => CallLog.parse(item));
3696
3758
  }
3697
3759
 
@@ -4261,6 +4323,10 @@ class CTIPhone extends Emitter {
4261
4323
  return false;
4262
4324
  }
4263
4325
 
4326
+ hasAVideoTrack() {
4327
+ return false;
4328
+ }
4329
+
4264
4330
  getLocalStreamForCall() {
4265
4331
  return null;
4266
4332
  }
@@ -4654,6 +4720,9 @@ class ChatRoom {
4654
4720
 
4655
4721
 
4656
4722
  static parseMany(plain ) {
4723
+ if (!plain || !plain.items) {
4724
+ return [];
4725
+ }
4657
4726
  return plain.items.map(item => ChatRoom.parse(item));
4658
4727
  }
4659
4728
 
@@ -5635,10 +5704,6 @@ const getSrflxOrRelay = (candidates ) =>
5635
5704
  candidates
5636
5705
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5637
5706
 
5638
- const areCandidateValid = (candidates ) =>
5639
- getSrflxOrRelay(candidates)
5640
- .length > 0;
5641
-
5642
5707
  const getVideoDirection = (sdp ) => {
5643
5708
  const parsedSdp = sdpParser__default['default'].parse(sdp);
5644
5709
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5691,8 +5756,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5691
5756
  /* global RTCSessionDescriptionInit, navigator */
5692
5757
 
5693
5758
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5694
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5695
- const WAIT_FOR_ICE_TIMEOUT = 500;
5696
5759
 
5697
5760
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5698
5761
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5882,38 +5945,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5882
5945
  this._peerConnection = undefined;
5883
5946
  }
5884
5947
 
5885
- async _waitForValidGatheredIce() {
5886
- let tries = 0;
5887
-
5888
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5889
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5890
- tries,
5891
- max: MAX_WAIT_FOR_ICE_TRIES,
5892
- });
5893
-
5894
- tries++;
5895
-
5896
- // eslint-disable-next-line no-await-in-loop
5897
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5898
- }
5899
-
5900
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5901
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5902
- const error = new Error(errorMsg);
5903
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5904
-
5905
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5906
- this.eventEmitter.emit('error', error);
5907
-
5908
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5909
- }
5910
-
5911
- // eslint-disable-next-line
5912
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5913
-
5914
- return this.getLocalSessionDescription();
5915
- }
5916
-
5917
5948
  // Overridden to send `inactive` in conference
5918
5949
  updateDirection(options , isConference = false,
5919
5950
  audioOnly = false) {
@@ -6706,7 +6737,9 @@ class WebRTCClient extends Emitter {
6706
6737
  const inviteOptions = {
6707
6738
  requestDelegate: {
6708
6739
  onAccept: (response ) => {
6709
- session.sessionDescriptionHandler.peerConnection.sfu = conference;
6740
+ if (session.sessionDescriptionHandler.peerConnection) {
6741
+ session.sessionDescriptionHandler.peerConnection.sfu = conference;
6742
+ }
6710
6743
  this._onAccepted(session, response.session, true);
6711
6744
  },
6712
6745
  onReject: (response ) => {
@@ -7578,6 +7611,16 @@ class WebRTCClient extends Emitter {
7578
7611
  return this.hasRemoteVideo(sessionId) ? this.getRemoteStream(sessionId) : null;
7579
7612
  }
7580
7613
 
7614
+ // Useful in a react-native environment when remoteMediaStream is not updated
7615
+ getRemoteVideoStreamFromPc(sessionId ) {
7616
+ const pc = this.getPeerConnection(sessionId);
7617
+ if (!pc) {
7618
+ return null;
7619
+ }
7620
+
7621
+ return pc.getRemoteStreams().find(stream => !!stream.getVideoTracks().length);
7622
+ }
7623
+
7581
7624
  hasVideo(sessionId ) {
7582
7625
  return this.hasLocalVideo(sessionId) || this.hasRemoteVideo(sessionId);
7583
7626
  }
@@ -8088,6 +8131,7 @@ class WebRTCClient extends Emitter {
8088
8131
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8089
8132
 
8090
8133
  pc.oniceconnectionstatechange = () => {
8134
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
8091
8135
  if (pc.iceConnectionState === 'disconnected') {
8092
8136
  this.eventEmitter.emit(ON_DISCONNECTED$1);
8093
8137
  }
@@ -8316,25 +8360,25 @@ class WebRTCClient extends Emitter {
8316
8360
 
8317
8361
  stats.forEach(report => {
8318
8362
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8319
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8363
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8320
8364
  }
8321
8365
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8322
- audioBytesSent += report.bytesSent;
8366
+ audioBytesSent += Number(report.bytesSent);
8323
8367
  }
8324
8368
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8325
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8369
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8326
8370
  }
8327
8371
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8328
- packetsLost += report.packetsLost;
8329
- networkStats.packetsReceived = report.packetsReceived;
8330
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8372
+ packetsLost += Number(report.packetsLost);
8373
+ networkStats.packetsReceived = Number(report.packetsReceived);
8374
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8331
8375
  }
8332
8376
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8333
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8377
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8334
8378
  }
8335
8379
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8336
8380
  if ('framesPerSecond' in report) {
8337
- networkStats.framesPerSecond = report.framesPerSecond;
8381
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8338
8382
  }
8339
8383
  if ('framerateMean' in report) {
8340
8384
  // framerateMean is only available in FF
@@ -8342,32 +8386,36 @@ class WebRTCClient extends Emitter {
8342
8386
  }
8343
8387
  }
8344
8388
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8345
- packetsLost += report.packetsLost;
8346
- networkStats.roundTripTime = report.roundTripTime;
8347
- networkStats.jitter = report.jitter;
8389
+ packetsLost += Number(report.packetsLost);
8390
+ networkStats.roundTripTime = Number(report.roundTripTime);
8391
+ networkStats.jitter = Number(report.jitter);
8348
8392
  }
8349
8393
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8350
- packetsLost += report.packetsLost;
8394
+ packetsLost += Number(report.packetsLost);
8351
8395
  }
8352
8396
  if (report.type === 'transport') {
8353
- transportSent += report.bytesSent;
8354
- transportReceived += report.bytesReceived;
8397
+ transportSent += Number(report.bytesSent);
8398
+ transportReceived += Number(report.bytesReceived);
8355
8399
  }
8356
8400
  });
8357
8401
 
8358
8402
  networkStats.packetsLost = packetsLost;
8359
- networkStats.audioBytesSent = audioBytesSent;
8403
+ networkStats.totalAudioBytesSent = audioBytesSent;
8404
+ networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8405
+ networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8360
8406
  networkStats.audioBytesReceived = audioBytesReceived;
8361
- networkStats.videoBytesSent = videoBytesSent;
8362
- networkStats.videoBytesReceived = videoBytesReceived;
8407
+ networkStats.totalVideoBytesSent = videoBytesSent;
8408
+ networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8409
+ networkStats.totalVideoBytesReceived = videoBytesReceived;
8410
+ networkStats.videoBytesReceived = videoBytesReceived - lastVideoReceived;
8411
+ networkStats.totalTransportSent = transportSent - lastTransportSent;
8363
8412
  networkStats.transportSent = transportSent;
8364
- networkStats.transportReceived = transportReceived;
8413
+ networkStats.totalTransportReceived = transportReceived;
8414
+ networkStats.transportReceived = transportReceived - lastTransportReceived;
8365
8415
 
8366
- const bandwidth = (networkStats.audioBytesSent - lastAudioSent) + (networkStats.videoBytesSent - lastVideoSent)
8367
- + (networkStats.audioBytesReceived - lastAudioReceived) + (networkStats.videoBytesReceived - lastVideoReceived)
8368
- + (networkStats.transportReceived - lastTransportReceived) + (networkStats.transportSent - lastTransportSent);
8369
-
8370
- networkStats.bandwidth = bandwidth;
8416
+ networkStats.bandwidth = networkStats.audioBytesSent + networkStats.audioBytesReceived
8417
+ + networkStats.videoBytesSent + networkStats.videoBytesReceived + networkStats.transportReceived
8418
+ + networkStats.transportSent;
8371
8419
 
8372
8420
  this.eventEmitter.emit(ON_NETWORK_STATS$1, session, networkStats, this.sessionNetworkStats[sessionId]);
8373
8421
  this.sessionNetworkStats[sessionId].push(networkStats);
@@ -8749,7 +8797,10 @@ class WebRTCPhone extends Emitter {
8749
8797
 
8750
8798
  onCancel(message);
8751
8799
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
8752
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
8800
+ const callSession = this._createCallSession(sipSession);
8801
+ delete this.callSessions[callSession.getId()];
8802
+
8803
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
8753
8804
  };
8754
8805
  } else if (sipSession instanceof invitation.Invitation) {
8755
8806
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -8778,9 +8829,11 @@ class WebRTCPhone extends Emitter {
8778
8829
  case sessionState.SessionState.Terminated: {
8779
8830
  logger$8.info('WebRTC phone - call terminated', { sipId: sipSession.id });
8780
8831
 
8832
+ // Should be called before `_onCallTerminated` or the callCount will not decrement...
8833
+ const callSession = this._createCallSession(sipSession);
8781
8834
  const wasCurrentSession = this._onCallTerminated(sipSession);
8782
8835
 
8783
- return this.eventEmitter.emit(ON_CALL_ENDED, this._createCallSession(sipSession), wasCurrentSession);
8836
+ return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
8784
8837
  }
8785
8838
  }
8786
8839
  });
@@ -8928,18 +8981,20 @@ class WebRTCPhone extends Emitter {
8928
8981
  screenTrack,
8929
8982
  });
8930
8983
 
8931
- screenTrack.onended = () => {
8932
- logger$8.info('WebRTC phone - on screenshare ended', {
8933
- hadVideo,
8934
- id: this.getSipSessionId(sipSession),
8935
- screenTrack,
8936
- });
8984
+ if (screenTrack) {
8985
+ screenTrack.onended = () => {
8986
+ logger$8.info('WebRTC phone - on screenshare ended', {
8987
+ hadVideo,
8988
+ id: this.getSipSessionId(sipSession),
8989
+ screenTrack,
8990
+ });
8937
8991
 
8938
- this.eventEmitter.emit(
8939
- ON_SHARE_SCREEN_ENDING,
8940
- this._createCallSession(sipSession, callSession),
8941
- );
8942
- };
8992
+ this.eventEmitter.emit(
8993
+ ON_SHARE_SCREEN_ENDING,
8994
+ this._createCallSession(sipSession, callSession),
8995
+ );
8996
+ };
8997
+ }
8943
8998
 
8944
8999
  this.currentScreenShare = {
8945
9000
  stream: screenStream,
@@ -9728,6 +9783,10 @@ class WebRTCPhone extends Emitter {
9728
9783
  return callSession ? this.client.getRemoteVideoStream(callSession.sipCallId) : null;
9729
9784
  }
9730
9785
 
9786
+ getRemoteVideoStreamFromPc(callSession ) {
9787
+ return callSession ? this.client.getRemoteVideoStreamFromPc(callSession.sipCallId) : null;
9788
+ }
9789
+
9731
9790
  hasRemoteVideo(callSession ) {
9732
9791
  return callSession ? this.client.hasRemoteVideo(callSession.sipCallId) : false;
9733
9792
  }
@@ -10411,6 +10470,11 @@ class Phone extends Emitter {
10411
10470
  return this.getRemoteVideoStream(callSession);
10412
10471
  }
10413
10472
 
10473
+ // Useful in a react-native environment when remoteMediaStream is not updated
10474
+ getRemoteVideoStreamFromPc(callSession ) {
10475
+ return this.phone ? this.phone.getRemoteVideoStreamFromPc(callSession) : false;
10476
+ }
10477
+
10414
10478
  hasVideo(callSession ) {
10415
10479
  return this.phone ? this.phone.hasVideo(callSession) : false;
10416
10480
  }
@@ -10570,6 +10634,7 @@ const AGENT_PAUSED = 'agent_paused';
10570
10634
  const AGENT_UNPAUSED = 'agent_unpaused';
10571
10635
  const CONFERENCE_ADHOC_PARTICIPANT_LEFT = 'conference_adhoc_participant_left';
10572
10636
  const CONFERENCE_ADHOC_DELETED = 'conference_adhoc_deleted';
10637
+ const MEETING_USER_PROGRESS = 'meeting_user_progress';
10573
10638
 
10574
10639
  const BLACKLIST_EVENTS = [
10575
10640
  CHAT_MESSAGE_SENT,
@@ -10920,6 +10985,7 @@ WebSocketClient.eventLists = [
10920
10985
  AGENT_UNPAUSED,
10921
10986
  CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10922
10987
  CONFERENCE_ADHOC_DELETED,
10988
+ MEETING_USER_PROGRESS,
10923
10989
  ];
10924
10990
 
10925
10991
  var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
@@ -10990,6 +11056,7 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
10990
11056
  AGENT_UNPAUSED: AGENT_UNPAUSED,
10991
11057
  CONFERENCE_ADHOC_PARTICIPANT_LEFT: CONFERENCE_ADHOC_PARTICIPANT_LEFT,
10992
11058
  CONFERENCE_ADHOC_DELETED: CONFERENCE_ADHOC_DELETED,
11059
+ MEETING_USER_PROGRESS: MEETING_USER_PROGRESS,
10993
11060
  HEARTBEAT_ENGINE_VERSION: HEARTBEAT_ENGINE_VERSION,
10994
11061
  'default': WebSocketClient
10995
11062
  });
@@ -136,6 +136,7 @@ class IssueReporter {
136
136
 
137
137
 
138
138
 
139
+
139
140
 
140
141
  constructor() {
141
142
  addLevelsTo(this);
@@ -147,12 +148,17 @@ class IssueReporter {
147
148
  this.bufferTimeout = null;
148
149
  this._boundProcessBuffer = this._processBuffer.bind(this);
149
150
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
151
+ this._callback = null;
150
152
  }
151
153
 
152
154
  init() {
153
155
  this._catchConsole();
154
156
  }
155
157
 
158
+ setCallback(cb ) {
159
+ this._callback = cb;
160
+ }
161
+
156
162
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
157
163
  this.remoteClientConfiguration = configuration;
158
164
  }
@@ -188,6 +194,7 @@ class IssueReporter {
188
194
 
189
195
  // Handle category label
190
196
  let category = null;
197
+ let skipSendToRemote = false;
191
198
  let extra = {};
192
199
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
193
200
  category = args[0].split('=')[1];
@@ -203,6 +210,7 @@ class IssueReporter {
203
210
  errorMessage: lastArg.message,
204
211
  errorStack: lastArg.stack,
205
212
  errorType: lastArg.constructor.name,
213
+ skipSendToRemote: lastArg.skipSendToRemote,
206
214
  };
207
215
  } else {
208
216
  extra = lastArg;
@@ -211,6 +219,11 @@ class IssueReporter {
211
219
  args.splice(1, 1);
212
220
  }
213
221
 
222
+ if (extra.skipSendToRemote) {
223
+ skipSendToRemote = true;
224
+ delete extra.skipSendToRemote;
225
+ }
226
+
214
227
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
215
228
  const message = args.join(', ');
216
229
  let consoleMessage = message;
@@ -231,7 +244,13 @@ class IssueReporter {
231
244
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
232
245
  oldMethod.apply(oldMethod, [date, consoleMessage]);
233
246
 
234
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
247
+ if (this._callback) {
248
+ this._callback(level, consoleMessage);
249
+ }
250
+
251
+ if (!skipSendToRemote) {
252
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
253
+ }
235
254
  }
236
255
 
237
256
  logRequest(url , options , response , start ) {
@@ -376,7 +395,11 @@ class IssueReporter {
376
395
  },
377
396
  // $FlowFixMe
378
397
  body,
379
- }).catch(() => {
398
+ }).catch((e ) => {
399
+ // $FlowFixMe
400
+ e.skipSendToRemote = true;
401
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
402
+
380
403
  setTimeout(() => {
381
404
  if (isArray) {
382
405
  payload = payload.map(message => {
@@ -1514,6 +1537,9 @@ class Contact {
1514
1537
  }
1515
1538
 
1516
1539
  static parseMany(response ) {
1540
+ if (!response || !response.results) {
1541
+ return [];
1542
+ }
1517
1543
  return response.results.map(r => Contact.parse(r, response.column_types));
1518
1544
  }
1519
1545
 
@@ -2620,11 +2646,27 @@ class Meeting {
2620
2646
  });
2621
2647
  }
2622
2648
 
2649
+ static parseMany(items ) {
2650
+ if (!items) {
2651
+ return [];
2652
+ }
2653
+ return items.map(plain => Meeting.parse(plain));
2654
+ }
2655
+
2623
2656
  static newFrom(meeting ) {
2624
2657
  return newFrom(meeting, Meeting);
2625
2658
  }
2626
2659
 
2627
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2660
+ constructor({
2661
+ uuid,
2662
+ name,
2663
+ guestSipAuthorization,
2664
+ ownerUuids,
2665
+ port,
2666
+ uri,
2667
+ number,
2668
+ persistent,
2669
+ } = {}) {
2628
2670
  this.guestSipAuthorization = guestSipAuthorization;
2629
2671
  this.uri = uri;
2630
2672
  this.name = name;
@@ -2710,8 +2752,11 @@ var confdMethods = (client , baseUrl ) => ({
2710
2752
  }
2711
2753
  },
2712
2754
 
2713
- createMyMeeting: (name ) =>
2714
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2755
+ getMyMeetings: () =>
2756
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2757
+
2758
+ createMyMeeting: (name , persistent ) =>
2759
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2715
2760
 
2716
2761
  deleteMyMeeting: (meetingUuid ) =>
2717
2762
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2807,6 +2852,10 @@ class ChatMessage {
2807
2852
 
2808
2853
 
2809
2854
  static parseMany(plain ) {
2855
+ if (!plain || !plain.items) {
2856
+ return [];
2857
+ }
2858
+
2810
2859
  return plain.items.map(item => ChatMessage.parse(item));
2811
2860
  }
2812
2861
 
@@ -2916,6 +2965,9 @@ class Voicemail {
2916
2965
  }
2917
2966
 
2918
2967
  static parseMany(plain ) {
2968
+ if (!plain) {
2969
+ return [];
2970
+ }
2919
2971
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2920
2972
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2921
2973
 
@@ -3025,6 +3077,9 @@ class Call {
3025
3077
 
3026
3078
 
3027
3079
  static parseMany(plain ) {
3080
+ if (!plain) {
3081
+ return [];
3082
+ }
3028
3083
  return plain.map((plainCall ) => Call.parse(plainCall));
3029
3084
  }
3030
3085
 
@@ -3197,6 +3252,9 @@ class Recording {
3197
3252
 
3198
3253
 
3199
3254
  static parseMany(recordings = []) {
3255
+ if (!recordings) {
3256
+ return [];
3257
+ }
3200
3258
  return recordings.map(item => Recording.parse(item));
3201
3259
  }
3202
3260
 
@@ -3298,6 +3356,10 @@ class CallLog {
3298
3356
  }
3299
3357
 
3300
3358
  static parseMany(plain ) {
3359
+ if (!plain || !plain.items) {
3360
+ return [];
3361
+ }
3362
+
3301
3363
  return plain.items.map(item => CallLog.parse(item));
3302
3364
  }
3303
3365
 
@@ -3855,6 +3917,9 @@ class ChatRoom {
3855
3917
 
3856
3918
 
3857
3919
  static parseMany(plain ) {
3920
+ if (!plain || !plain.items) {
3921
+ return [];
3922
+ }
3858
3923
  return plain.items.map(item => ChatRoom.parse(item));
3859
3924
  }
3860
3925