@wazo/sdk 0.37.21 → 0.37.25

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 (118) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +36 -5
  3. package/esm/__tests__/web-rtc-client.test.js +77 -66
  4. package/esm/api/call-logd.js +7 -0
  5. package/esm/api/calld.js +10 -0
  6. package/esm/api/chatd.js +7 -0
  7. package/esm/api/confd.js +13 -5
  8. package/esm/api/ctid-ng.js +10 -0
  9. package/esm/api/dird.js +3 -0
  10. package/esm/api-client.js +36 -5
  11. package/esm/checker/Checker.js +77 -66
  12. package/esm/checker/checks/aor.js +36 -5
  13. package/esm/checker/checks/api.js +36 -5
  14. package/esm/checker/checks/index.js +77 -66
  15. package/esm/checker/checks/webrtc-transport.js +77 -66
  16. package/esm/checker/checks/webrtc.js +77 -66
  17. package/esm/domain/AdHocAPIConference.js +36 -5
  18. package/esm/domain/Call.js +3 -0
  19. package/esm/domain/CallLog.js +7 -0
  20. package/esm/domain/ChatMessage.js +4 -0
  21. package/esm/domain/ChatRoom.js +3 -0
  22. package/esm/domain/Contact.js +3 -0
  23. package/esm/domain/Features.js +36 -5
  24. package/esm/domain/Meeting.js +15 -5
  25. package/esm/domain/Phone/CTIPhone.js +40 -5
  26. package/esm/domain/Phone/WebRTCPhone.js +45 -16
  27. package/esm/domain/Recording.js +3 -0
  28. package/esm/domain/Voicemail.js +3 -0
  29. package/esm/domain/__tests__/Call.test.js +3 -0
  30. package/esm/domain/__tests__/CallLog.test.js +7 -0
  31. package/esm/domain/__tests__/Contact.test.js +3 -0
  32. package/esm/domain/__tests__/Meeting.test.js +144 -0
  33. package/esm/domain/__tests__/Voicemail.test.js +3 -0
  34. package/esm/index.js +125 -81
  35. package/esm/lib/WazoSessionDescriptionHandler.js +0 -38
  36. package/esm/service/CallApi.js +36 -5
  37. package/esm/service/getApiClient.js +36 -5
  38. package/esm/simple/Auth.js +125 -81
  39. package/esm/simple/Configuration.js +125 -81
  40. package/esm/simple/Directory.js +36 -5
  41. package/esm/simple/Phone.js +125 -81
  42. package/esm/simple/index.js +125 -81
  43. package/esm/simple/room/LocalParticipant.js +125 -81
  44. package/esm/simple/room/Participant.js +125 -81
  45. package/esm/simple/room/RemoteParticipant.js +125 -81
  46. package/esm/simple/room/Room.js +125 -81
  47. package/esm/simple/room/SipRoom.js +125 -81
  48. package/esm/simple/room/Stream.js +125 -81
  49. package/esm/simple/room/__tests__/RemoteParticipant.test.js +125 -81
  50. package/esm/simple/utils.js +125 -81
  51. package/esm/types/WebSocketMessage.js +1 -1
  52. package/esm/web-rtc-client.js +77 -66
  53. package/lib/__tests__/api-client.test.js +36 -5
  54. package/lib/__tests__/web-rtc-client.test.js +77 -66
  55. package/lib/api/call-logd.js +7 -0
  56. package/lib/api/calld.js +10 -0
  57. package/lib/api/chatd.js +7 -0
  58. package/lib/api/confd.js +13 -5
  59. package/lib/api/ctid-ng.js +10 -0
  60. package/lib/api/dird.js +3 -0
  61. package/lib/api-client.js +36 -5
  62. package/lib/checker/Checker.js +77 -66
  63. package/lib/checker/checks/aor.js +36 -5
  64. package/lib/checker/checks/api.js +36 -5
  65. package/lib/checker/checks/index.js +77 -66
  66. package/lib/checker/checks/webrtc-transport.js +77 -66
  67. package/lib/checker/checks/webrtc.js +77 -66
  68. package/lib/domain/AdHocAPIConference.js +36 -5
  69. package/lib/domain/Call.js +3 -0
  70. package/lib/domain/CallLog.js +7 -0
  71. package/lib/domain/ChatMessage.js +4 -0
  72. package/lib/domain/ChatRoom.js +3 -0
  73. package/lib/domain/Contact.js +3 -0
  74. package/lib/domain/Features.js +36 -5
  75. package/lib/domain/Meeting.js +19 -5
  76. package/lib/domain/Phone/CTIPhone.js +40 -5
  77. package/lib/domain/Phone/WebRTCPhone.js +45 -16
  78. package/lib/domain/Recording.js +3 -0
  79. package/lib/domain/Voicemail.js +3 -0
  80. package/lib/domain/__tests__/Call.test.js +3 -0
  81. package/lib/domain/__tests__/CallLog.test.js +7 -0
  82. package/lib/domain/__tests__/Contact.test.js +3 -0
  83. package/lib/domain/__tests__/Meeting.test.js +150 -0
  84. package/lib/domain/__tests__/Voicemail.test.js +3 -0
  85. package/lib/index.js +125 -81
  86. package/lib/lib/WazoSessionDescriptionHandler.js +0 -38
  87. package/lib/service/CallApi.js +36 -5
  88. package/lib/service/getApiClient.js +36 -5
  89. package/lib/simple/Auth.js +125 -81
  90. package/lib/simple/Configuration.js +125 -81
  91. package/lib/simple/Directory.js +36 -5
  92. package/lib/simple/Phone.js +125 -81
  93. package/lib/simple/index.js +125 -81
  94. package/lib/simple/room/LocalParticipant.js +125 -81
  95. package/lib/simple/room/Participant.js +125 -81
  96. package/lib/simple/room/RemoteParticipant.js +125 -81
  97. package/lib/simple/room/Room.js +125 -81
  98. package/lib/simple/room/SipRoom.js +125 -81
  99. package/lib/simple/room/Stream.js +125 -81
  100. package/lib/simple/room/__tests__/RemoteParticipant.test.js +125 -81
  101. package/lib/simple/utils.js +125 -81
  102. package/lib/types/WebSocketMessage.js +2 -0
  103. package/lib/web-rtc-client.js +77 -66
  104. package/package.json +1 -1
  105. package/src/domain/Call.js +3 -0
  106. package/src/domain/CallLog.js +4 -0
  107. package/src/domain/ChatMessage.js +4 -0
  108. package/src/domain/ChatRoom.js +3 -0
  109. package/src/domain/Contact.js +3 -0
  110. package/src/domain/Meeting.js +15 -5
  111. package/src/domain/Phone/CTIPhone.js +4 -0
  112. package/src/domain/Phone/Phone.js +2 -0
  113. package/src/domain/Phone/WebRTCPhone.js +45 -16
  114. package/src/domain/Recording.js +3 -0
  115. package/src/domain/Voicemail.js +3 -0
  116. package/src/domain/__tests__/Meeting.test.js +50 -0
  117. package/src/lib/WazoSessionDescriptionHandler.js +1 -35
  118. package/src/web-rtc-client.js +41 -23
@@ -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
 
@@ -2637,8 +2640,9 @@ class ExternalApp {
2637
2640
 
2638
2641
 
2639
2642
 
2640
-
2643
+
2641
2644
 
2645
+
2642
2646
 
2643
2647
 
2644
2648
  class Meeting {
@@ -2649,9 +2653,10 @@ class Meeting {
2649
2653
 
2650
2654
 
2651
2655
 
2652
-
2656
+
2653
2657
 
2654
2658
 
2659
+
2655
2660
 
2656
2661
  static parse(plain ) {
2657
2662
  return new Meeting({
@@ -2661,12 +2666,16 @@ class Meeting {
2661
2666
  ownerUuids: plain.owner_uuids,
2662
2667
  port: plain.port,
2663
2668
  uuid: plain.uuid,
2664
- number: plain.number,
2669
+ extension: plain.exten,
2665
2670
  persistent: plain.persistent,
2671
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
2666
2672
  });
2667
2673
  }
2668
2674
 
2669
2675
  static parseMany(items ) {
2676
+ if (!items) {
2677
+ return [];
2678
+ }
2670
2679
  return items.map(plain => Meeting.parse(plain));
2671
2680
  }
2672
2681
 
@@ -2681,8 +2690,9 @@ class Meeting {
2681
2690
  ownerUuids,
2682
2691
  port,
2683
2692
  uri,
2684
- number,
2693
+ extension,
2685
2694
  persistent,
2695
+ creationTime,
2686
2696
  } = {}) {
2687
2697
  this.guestSipAuthorization = guestSipAuthorization;
2688
2698
  this.uri = uri;
@@ -2690,8 +2700,9 @@ class Meeting {
2690
2700
  this.ownerUuids = ownerUuids;
2691
2701
  this.port = port;
2692
2702
  this.uuid = uuid;
2693
- this.number = number;
2703
+ this.extension = extension;
2694
2704
  this.persistent = persistent;
2705
+ this.creationTime = creationTime;
2695
2706
 
2696
2707
  // Useful to compare instead of instanceof with minified code
2697
2708
  this.type = 'Meeting';
@@ -2869,6 +2880,10 @@ class ChatMessage {
2869
2880
 
2870
2881
 
2871
2882
  static parseMany(plain ) {
2883
+ if (!plain || !plain.items) {
2884
+ return [];
2885
+ }
2886
+
2872
2887
  return plain.items.map(item => ChatMessage.parse(item));
2873
2888
  }
2874
2889
 
@@ -2978,6 +2993,9 @@ class Voicemail {
2978
2993
  }
2979
2994
 
2980
2995
  static parseMany(plain ) {
2996
+ if (!plain) {
2997
+ return [];
2998
+ }
2981
2999
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2982
3000
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2983
3001
 
@@ -3087,6 +3105,9 @@ class Call {
3087
3105
 
3088
3106
 
3089
3107
  static parseMany(plain ) {
3108
+ if (!plain) {
3109
+ return [];
3110
+ }
3090
3111
  return plain.map((plainCall ) => Call.parse(plainCall));
3091
3112
  }
3092
3113
 
@@ -3630,6 +3651,9 @@ class Recording {
3630
3651
 
3631
3652
 
3632
3653
  static parseMany(recordings = []) {
3654
+ if (!recordings) {
3655
+ return [];
3656
+ }
3633
3657
  return recordings.map(item => Recording.parse(item));
3634
3658
  }
3635
3659
 
@@ -3731,6 +3755,10 @@ class CallLog {
3731
3755
  }
3732
3756
 
3733
3757
  static parseMany(plain ) {
3758
+ if (!plain || !plain.items) {
3759
+ return [];
3760
+ }
3761
+
3734
3762
  return plain.items.map(item => CallLog.parse(item));
3735
3763
  }
3736
3764
 
@@ -4300,6 +4328,10 @@ class CTIPhone extends Emitter {
4300
4328
  return false;
4301
4329
  }
4302
4330
 
4331
+ hasAVideoTrack() {
4332
+ return false;
4333
+ }
4334
+
4303
4335
  getLocalStreamForCall() {
4304
4336
  return null;
4305
4337
  }
@@ -4693,6 +4725,9 @@ class ChatRoom {
4693
4725
 
4694
4726
 
4695
4727
  static parseMany(plain ) {
4728
+ if (!plain || !plain.items) {
4729
+ return [];
4730
+ }
4696
4731
  return plain.items.map(item => ChatRoom.parse(item));
4697
4732
  }
4698
4733
 
@@ -5674,10 +5709,6 @@ const getSrflxOrRelay = (candidates ) =>
5674
5709
  candidates
5675
5710
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5676
5711
 
5677
- const areCandidateValid = (candidates ) =>
5678
- getSrflxOrRelay(candidates)
5679
- .length > 0;
5680
-
5681
5712
  const getVideoDirection = (sdp ) => {
5682
5713
  const parsedSdp = sdpParser__default['default'].parse(sdp);
5683
5714
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5730,8 +5761,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5730
5761
  /* global RTCSessionDescriptionInit, navigator */
5731
5762
 
5732
5763
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5733
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5734
- const WAIT_FOR_ICE_TIMEOUT = 500;
5735
5764
 
5736
5765
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5737
5766
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5921,38 +5950,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5921
5950
  this._peerConnection = undefined;
5922
5951
  }
5923
5952
 
5924
- async _waitForValidGatheredIce() {
5925
- let tries = 0;
5926
-
5927
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5928
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5929
- tries,
5930
- max: MAX_WAIT_FOR_ICE_TRIES,
5931
- });
5932
-
5933
- tries++;
5934
-
5935
- // eslint-disable-next-line no-await-in-loop
5936
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5937
- }
5938
-
5939
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5940
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5941
- const error = new Error(errorMsg);
5942
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5943
-
5944
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5945
- this.eventEmitter.emit('error', error);
5946
-
5947
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5948
- }
5949
-
5950
- // eslint-disable-next-line
5951
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5952
-
5953
- return this.getLocalSessionDescription();
5954
- }
5955
-
5956
5953
  // Overridden to send `inactive` in conference
5957
5954
  updateDirection(options , isConference = false,
5958
5955
  audioOnly = false) {
@@ -6720,7 +6717,7 @@ class WebRTCClient extends Emitter {
6720
6717
  }
6721
6718
 
6722
6719
  call(number , enableVideo , audioOnly = false, conference = false) {
6723
- logger$9.info('sdk webrtc creating call', { number, enableVideo, audioOnly });
6720
+ logger$9.info('sdk webrtc creating call', { number, enableVideo, audioOnly, conference });
6724
6721
  const inviterOptions = {
6725
6722
  sessionDescriptionHandlerOptionsReInvite: {
6726
6723
  conference,
@@ -7796,6 +7793,7 @@ class WebRTCClient extends Emitter {
7796
7793
  const screenSharing = constraints && 'screen' in constraints ? constraints.screen : false;
7797
7794
  const isDesktop = constraints && 'desktop' in constraints ? constraints.desktop : false;
7798
7795
  const withAudio = constraints && 'audio' in constraints ? constraints.audio : true;
7796
+ const mandatoryVideo = constraints && typeof constraints.video === 'object' ? constraints.video.mandatory : {};
7799
7797
 
7800
7798
  logger$9.info('Retrieving media a configuration', { enableVideo, screenSharing, isDesktop, withAudio, constraints });
7801
7799
 
@@ -7803,7 +7801,8 @@ class WebRTCClient extends Emitter {
7803
7801
  constraints: {
7804
7802
  // Exact constraint are not supported with `getDisplayMedia` and we must have a video=false in desktop screenshare
7805
7803
  audio: screenSharing ? !isDesktop : (withAudio ? this._getAudioConstraints() : false),
7806
- video: screenSharing ? (isDesktop ? ({ mandatory: { chromeMediaSource: 'desktop' } }) : { cursor: 'always' })
7804
+ video: screenSharing ? (isDesktop
7805
+ ? ({ mandatory: { chromeMediaSource: 'desktop', ...(mandatoryVideo || {}) } }) : { cursor: 'always' })
7807
7806
  : this._getVideoConstraints(enableVideo),
7808
7807
  screen: screenSharing,
7809
7808
  desktop: isDesktop,
@@ -8138,11 +8137,14 @@ class WebRTCClient extends Emitter {
8138
8137
 
8139
8138
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8140
8139
 
8141
- pc.oniceconnectionstatechange = () => {
8142
- if (pc.iceConnectionState === 'disconnected') {
8143
- this.eventEmitter.emit(ON_DISCONNECTED$1);
8144
- }
8145
- };
8140
+ if (pc) {
8141
+ pc.oniceconnectionstatechange = () => {
8142
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
8143
+ if (pc.iceConnectionState === 'disconnected') {
8144
+ this.eventEmitter.emit(ON_DISCONNECTED$1);
8145
+ }
8146
+ };
8147
+ }
8146
8148
 
8147
8149
  if (withEvent) {
8148
8150
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
@@ -8352,13 +8354,17 @@ class WebRTCClient extends Emitter {
8352
8354
  const nbStats = this.sessionNetworkStats[sessionId].length;
8353
8355
  const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
8354
8356
  const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
8357
+ const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
8355
8358
  const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
8356
8359
  const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
8360
+ const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
8357
8361
  const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
8358
8362
  const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
8359
8363
  const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
8360
- let audioBytesSent = 0;
8361
- let audioBytesReceived = 0;
8364
+ let audioBytesSent = 0; // content + header
8365
+ let audioBytesReceived = 0; // content + header
8366
+ let audioContentSent = 0; // useful to detect blank call
8367
+ let audioContentReceived = 0;
8362
8368
  let videoBytesSent = 0;
8363
8369
  let videoBytesReceived = 0;
8364
8370
  let transportSent = 0;
@@ -8367,25 +8373,27 @@ class WebRTCClient extends Emitter {
8367
8373
 
8368
8374
  stats.forEach(report => {
8369
8375
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8370
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8376
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8377
+ audioContentSent += Number(report.bytesSent);
8371
8378
  }
8372
8379
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8373
- audioBytesSent += report.bytesSent;
8380
+ audioBytesSent += Number(report.bytesSent);
8374
8381
  }
8375
8382
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8376
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8383
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8377
8384
  }
8378
8385
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8379
- packetsLost += report.packetsLost;
8380
- networkStats.packetsReceived = report.packetsReceived;
8381
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8386
+ packetsLost += Number(report.packetsLost);
8387
+ networkStats.packetsReceived = Number(report.packetsReceived);
8388
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8389
+ audioContentReceived += Number(report.bytesReceived);
8382
8390
  }
8383
8391
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8384
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8392
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8385
8393
  }
8386
8394
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8387
8395
  if ('framesPerSecond' in report) {
8388
- networkStats.framesPerSecond = report.framesPerSecond;
8396
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8389
8397
  }
8390
8398
  if ('framerateMean' in report) {
8391
8399
  // framerateMean is only available in FF
@@ -8393,24 +8401,31 @@ class WebRTCClient extends Emitter {
8393
8401
  }
8394
8402
  }
8395
8403
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8396
- packetsLost += report.packetsLost;
8397
- networkStats.roundTripTime = report.roundTripTime;
8398
- networkStats.jitter = report.jitter;
8404
+ packetsLost += Number(report.packetsLost);
8405
+ networkStats.roundTripTime = Number(report.roundTripTime);
8406
+ networkStats.jitter = Number(report.jitter);
8399
8407
  }
8400
8408
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8401
- packetsLost += report.packetsLost;
8409
+ packetsLost += Number(report.packetsLost);
8402
8410
  }
8403
8411
  if (report.type === 'transport') {
8404
- transportSent += report.bytesSent;
8405
- transportReceived += report.bytesReceived;
8412
+ transportSent += Number(report.bytesSent);
8413
+ transportReceived += Number(report.bytesReceived);
8406
8414
  }
8407
8415
  });
8408
8416
 
8409
8417
  networkStats.packetsLost = packetsLost;
8418
+
8410
8419
  networkStats.totalAudioBytesSent = audioBytesSent;
8411
8420
  networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8412
8421
  networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8413
8422
  networkStats.audioBytesReceived = audioBytesReceived;
8423
+
8424
+ networkStats.totalAudioContentSent = audioContentSent;
8425
+ networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
8426
+ networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
8427
+ networkStats.audioContentReceived = audioContentReceived;
8428
+
8414
8429
  networkStats.totalVideoBytesSent = videoBytesSent;
8415
8430
  networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8416
8431
  networkStats.totalVideoBytesReceived = videoBytesReceived;
@@ -8622,6 +8637,7 @@ class WebRTCPhone extends Emitter {
8622
8637
  constraints,
8623
8638
  audioOnly,
8624
8639
  conference,
8640
+ iceRestart,
8625
8641
  });
8626
8642
 
8627
8643
  if (!sipSession) {
@@ -8725,6 +8741,11 @@ class WebRTCPhone extends Emitter {
8725
8741
 
8726
8742
  this.client.downgradeToAudio(sipSession);
8727
8743
 
8744
+ if (callSession) {
8745
+ callSession.cameraEnabled = false;
8746
+ this._updateCallSession(callSession);
8747
+ }
8748
+
8728
8749
  if (withMessage) {
8729
8750
  this._sendReinviteMessage(callSession, false);
8730
8751
  }
@@ -8752,6 +8773,11 @@ class WebRTCPhone extends Emitter {
8752
8773
 
8753
8774
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
8754
8775
 
8776
+ if (callSession) {
8777
+ callSession.cameraEnabled = true;
8778
+ this._updateCallSession(callSession);
8779
+ }
8780
+
8755
8781
  // If no stream is returned, it means we have to reinvite
8756
8782
  if (!newStream) {
8757
8783
  return true;
@@ -8804,7 +8830,10 @@ class WebRTCPhone extends Emitter {
8804
8830
 
8805
8831
  onCancel(message);
8806
8832
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
8807
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
8833
+ const callSession = this._createCallSession(sipSession);
8834
+ delete this.callSessions[callSession.getId()];
8835
+
8836
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
8808
8837
  };
8809
8838
  } else if (sipSession instanceof invitation.Invitation) {
8810
8839
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -8985,18 +9014,20 @@ class WebRTCPhone extends Emitter {
8985
9014
  screenTrack,
8986
9015
  });
8987
9016
 
8988
- screenTrack.onended = () => {
8989
- logger$8.info('WebRTC phone - on screenshare ended', {
8990
- hadVideo,
8991
- id: this.getSipSessionId(sipSession),
8992
- screenTrack,
8993
- });
9017
+ if (screenTrack) {
9018
+ screenTrack.onended = () => {
9019
+ logger$8.info('WebRTC phone - on screenshare ended', {
9020
+ hadVideo,
9021
+ id: this.getSipSessionId(sipSession),
9022
+ screenTrack,
9023
+ });
8994
9024
 
8995
- this.eventEmitter.emit(
8996
- ON_SHARE_SCREEN_ENDING,
8997
- this._createCallSession(sipSession, callSession),
8998
- );
8999
- };
9025
+ this.eventEmitter.emit(
9026
+ ON_SHARE_SCREEN_ENDING,
9027
+ this._createCallSession(sipSession, callSession),
9028
+ );
9029
+ };
9030
+ }
9000
9031
 
9001
9032
  this.currentScreenShare = {
9002
9033
  stream: screenStream,
@@ -9016,7 +9047,7 @@ class WebRTCPhone extends Emitter {
9016
9047
  }
9017
9048
 
9018
9049
  _onCallAccepted(sipSession , cameraEnabled ) {
9019
- logger$8.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9050
+ logger$8.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9020
9051
 
9021
9052
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
9022
9053
  this.currentSipSession = sipSession;
@@ -9528,7 +9559,7 @@ class WebRTCPhone extends Emitter {
9528
9559
  // @TODO: line is not used here
9529
9560
  async makeCall(number , line , cameraEnabled ,
9530
9561
  audioOnly = false, conference = false) {
9531
- logger$8.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled });
9562
+ logger$8.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled, audioOnly, conference });
9532
9563
  if (!number) {
9533
9564
  return Promise.resolve(null);
9534
9565
  }
@@ -9889,9 +9920,13 @@ class WebRTCPhone extends Emitter {
9889
9920
  if (this.shouldSendReinvite && this.currentSipSession
9890
9921
  && this.currentSipSession.state === sessionState.SessionState.Established) {
9891
9922
  this.shouldSendReinvite = false;
9923
+ const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
9924
+ const isConference = pc ? pc.sfu : false;
9925
+ const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
9926
+
9892
9927
  try {
9893
9928
  // Send reinvite with iceRestart
9894
- this.sendReinvite(this.currentCallSession, null, false, false, true);
9929
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
9895
9930
  } catch (e) {
9896
9931
  logger$8.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
9897
9932
  }
@@ -9975,6 +10010,15 @@ class WebRTCPhone extends Emitter {
9975
10010
  return this.client.getSipSessionId(sipSession);
9976
10011
  }
9977
10012
 
10013
+ _updateCallSession(callSession ) {
10014
+ const sipSession = this.findSipSession(callSession);
10015
+ const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10016
+
10017
+ if (sipSessionId) {
10018
+ this.callSessions[sipSessionId] = callSession;
10019
+ }
10020
+ }
10021
+
9978
10022
  _onMessage(message ) {
9979
10023
  if (!message || message.method !== 'MESSAGE') {
9980
10024
  return;
@@ -1537,6 +1537,9 @@ class Contact {
1537
1537
  }
1538
1538
 
1539
1539
  static parseMany(response ) {
1540
+ if (!response || !response.results) {
1541
+ return [];
1542
+ }
1540
1543
  return response.results.map(r => Contact.parse(r, response.column_types));
1541
1544
  }
1542
1545
 
@@ -2614,8 +2617,9 @@ class ExternalApp {
2614
2617
 
2615
2618
 
2616
2619
 
2617
-
2620
+
2618
2621
 
2622
+
2619
2623
 
2620
2624
 
2621
2625
  class Meeting {
@@ -2626,9 +2630,10 @@ class Meeting {
2626
2630
 
2627
2631
 
2628
2632
 
2629
-
2633
+
2630
2634
 
2631
2635
 
2636
+
2632
2637
 
2633
2638
  static parse(plain ) {
2634
2639
  return new Meeting({
@@ -2638,12 +2643,16 @@ class Meeting {
2638
2643
  ownerUuids: plain.owner_uuids,
2639
2644
  port: plain.port,
2640
2645
  uuid: plain.uuid,
2641
- number: plain.number,
2646
+ extension: plain.exten,
2642
2647
  persistent: plain.persistent,
2648
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
2643
2649
  });
2644
2650
  }
2645
2651
 
2646
2652
  static parseMany(items ) {
2653
+ if (!items) {
2654
+ return [];
2655
+ }
2647
2656
  return items.map(plain => Meeting.parse(plain));
2648
2657
  }
2649
2658
 
@@ -2658,8 +2667,9 @@ class Meeting {
2658
2667
  ownerUuids,
2659
2668
  port,
2660
2669
  uri,
2661
- number,
2670
+ extension,
2662
2671
  persistent,
2672
+ creationTime,
2663
2673
  } = {}) {
2664
2674
  this.guestSipAuthorization = guestSipAuthorization;
2665
2675
  this.uri = uri;
@@ -2667,8 +2677,9 @@ class Meeting {
2667
2677
  this.ownerUuids = ownerUuids;
2668
2678
  this.port = port;
2669
2679
  this.uuid = uuid;
2670
- this.number = number;
2680
+ this.extension = extension;
2671
2681
  this.persistent = persistent;
2682
+ this.creationTime = creationTime;
2672
2683
 
2673
2684
  // Useful to compare instead of instanceof with minified code
2674
2685
  this.type = 'Meeting';
@@ -2846,6 +2857,10 @@ class ChatMessage {
2846
2857
 
2847
2858
 
2848
2859
  static parseMany(plain ) {
2860
+ if (!plain || !plain.items) {
2861
+ return [];
2862
+ }
2863
+
2849
2864
  return plain.items.map(item => ChatMessage.parse(item));
2850
2865
  }
2851
2866
 
@@ -2955,6 +2970,9 @@ class Voicemail {
2955
2970
  }
2956
2971
 
2957
2972
  static parseMany(plain ) {
2973
+ if (!plain) {
2974
+ return [];
2975
+ }
2958
2976
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2959
2977
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2960
2978
 
@@ -3064,6 +3082,9 @@ class Call {
3064
3082
 
3065
3083
 
3066
3084
  static parseMany(plain ) {
3085
+ if (!plain) {
3086
+ return [];
3087
+ }
3067
3088
  return plain.map((plainCall ) => Call.parse(plainCall));
3068
3089
  }
3069
3090
 
@@ -3236,6 +3257,9 @@ class Recording {
3236
3257
 
3237
3258
 
3238
3259
  static parseMany(recordings = []) {
3260
+ if (!recordings) {
3261
+ return [];
3262
+ }
3239
3263
  return recordings.map(item => Recording.parse(item));
3240
3264
  }
3241
3265
 
@@ -3337,6 +3361,10 @@ class CallLog {
3337
3361
  }
3338
3362
 
3339
3363
  static parseMany(plain ) {
3364
+ if (!plain || !plain.items) {
3365
+ return [];
3366
+ }
3367
+
3340
3368
  return plain.items.map(item => CallLog.parse(item));
3341
3369
  }
3342
3370
 
@@ -3894,6 +3922,9 @@ class ChatRoom {
3894
3922
 
3895
3923
 
3896
3924
  static parseMany(plain ) {
3925
+ if (!plain || !plain.items) {
3926
+ return [];
3927
+ }
3897
3928
  return plain.items.map(item => ChatRoom.parse(item));
3898
3929
  }
3899
3930