@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
@@ -1586,6 +1586,9 @@ class Contact {
1586
1586
  }
1587
1587
 
1588
1588
  static parseMany(response ) {
1589
+ if (!response || !response.results) {
1590
+ return [];
1591
+ }
1589
1592
  return response.results.map(r => Contact.parse(r, response.column_types));
1590
1593
  }
1591
1594
 
@@ -2663,8 +2666,9 @@ class ExternalApp {
2663
2666
 
2664
2667
 
2665
2668
 
2666
-
2669
+
2667
2670
 
2671
+
2668
2672
 
2669
2673
 
2670
2674
  class Meeting {
@@ -2675,9 +2679,10 @@ class Meeting {
2675
2679
 
2676
2680
 
2677
2681
 
2678
-
2682
+
2679
2683
 
2680
2684
 
2685
+
2681
2686
 
2682
2687
  static parse(plain ) {
2683
2688
  return new Meeting({
@@ -2687,12 +2692,16 @@ class Meeting {
2687
2692
  ownerUuids: plain.owner_uuids,
2688
2693
  port: plain.port,
2689
2694
  uuid: plain.uuid,
2690
- number: plain.number,
2695
+ extension: plain.exten,
2691
2696
  persistent: plain.persistent,
2697
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
2692
2698
  });
2693
2699
  }
2694
2700
 
2695
2701
  static parseMany(items ) {
2702
+ if (!items) {
2703
+ return [];
2704
+ }
2696
2705
  return items.map(plain => Meeting.parse(plain));
2697
2706
  }
2698
2707
 
@@ -2707,8 +2716,9 @@ class Meeting {
2707
2716
  ownerUuids,
2708
2717
  port,
2709
2718
  uri,
2710
- number,
2719
+ extension,
2711
2720
  persistent,
2721
+ creationTime,
2712
2722
  } = {}) {
2713
2723
  this.guestSipAuthorization = guestSipAuthorization;
2714
2724
  this.uri = uri;
@@ -2716,8 +2726,9 @@ class Meeting {
2716
2726
  this.ownerUuids = ownerUuids;
2717
2727
  this.port = port;
2718
2728
  this.uuid = uuid;
2719
- this.number = number;
2729
+ this.extension = extension;
2720
2730
  this.persistent = persistent;
2731
+ this.creationTime = creationTime;
2721
2732
 
2722
2733
  // Useful to compare instead of instanceof with minified code
2723
2734
  this.type = 'Meeting';
@@ -2895,6 +2906,10 @@ class ChatMessage {
2895
2906
 
2896
2907
 
2897
2908
  static parseMany(plain ) {
2909
+ if (!plain || !plain.items) {
2910
+ return [];
2911
+ }
2912
+
2898
2913
  return plain.items.map(item => ChatMessage.parse(item));
2899
2914
  }
2900
2915
 
@@ -3004,6 +3019,9 @@ class Voicemail {
3004
3019
  }
3005
3020
 
3006
3021
  static parseMany(plain ) {
3022
+ if (!plain) {
3023
+ return [];
3024
+ }
3007
3025
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3008
3026
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3009
3027
 
@@ -3113,6 +3131,9 @@ class Call {
3113
3131
 
3114
3132
 
3115
3133
  static parseMany(plain ) {
3134
+ if (!plain) {
3135
+ return [];
3136
+ }
3116
3137
  return plain.map((plainCall ) => Call.parse(plainCall));
3117
3138
  }
3118
3139
 
@@ -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
 
@@ -5938,10 +5973,6 @@ const getSrflxOrRelay = (candidates ) =>
5938
5973
  candidates
5939
5974
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5940
5975
 
5941
- const areCandidateValid = (candidates ) =>
5942
- getSrflxOrRelay(candidates)
5943
- .length > 0;
5944
-
5945
5976
  const getVideoDirection = (sdp ) => {
5946
5977
  const parsedSdp = sdpParser__default['default'].parse(sdp);
5947
5978
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5994,8 +6025,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5994
6025
  /* global RTCSessionDescriptionInit, navigator */
5995
6026
 
5996
6027
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5997
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5998
- const WAIT_FOR_ICE_TIMEOUT = 500;
5999
6028
 
6000
6029
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
6001
6030
  const wazoMediaStreamFactory = (constraints ) => {
@@ -6185,38 +6214,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
6185
6214
  this._peerConnection = undefined;
6186
6215
  }
6187
6216
 
6188
- async _waitForValidGatheredIce() {
6189
- let tries = 0;
6190
-
6191
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
6192
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
6193
- tries,
6194
- max: MAX_WAIT_FOR_ICE_TRIES,
6195
- });
6196
-
6197
- tries++;
6198
-
6199
- // eslint-disable-next-line no-await-in-loop
6200
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
6201
- }
6202
-
6203
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
6204
- const errorMsg = 'No valid candidates found, can\'t answer the call';
6205
- const error = new Error(errorMsg);
6206
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
6207
-
6208
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
6209
- this.eventEmitter.emit('error', error);
6210
-
6211
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6212
- }
6213
-
6214
- // eslint-disable-next-line
6215
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6216
-
6217
- return this.getLocalSessionDescription();
6218
- }
6219
-
6220
6217
  // Overridden to send `inactive` in conference
6221
6218
  updateDirection(options , isConference = false,
6222
6219
  audioOnly = false) {
@@ -6984,7 +6981,7 @@ class WebRTCClient extends Emitter {
6984
6981
  }
6985
6982
 
6986
6983
  call(number , enableVideo , audioOnly = false, conference = false) {
6987
- logger$8.info('sdk webrtc creating call', { number, enableVideo, audioOnly });
6984
+ logger$8.info('sdk webrtc creating call', { number, enableVideo, audioOnly, conference });
6988
6985
  const inviterOptions = {
6989
6986
  sessionDescriptionHandlerOptionsReInvite: {
6990
6987
  conference,
@@ -8060,6 +8057,7 @@ class WebRTCClient extends Emitter {
8060
8057
  const screenSharing = constraints && 'screen' in constraints ? constraints.screen : false;
8061
8058
  const isDesktop = constraints && 'desktop' in constraints ? constraints.desktop : false;
8062
8059
  const withAudio = constraints && 'audio' in constraints ? constraints.audio : true;
8060
+ const mandatoryVideo = constraints && typeof constraints.video === 'object' ? constraints.video.mandatory : {};
8063
8061
 
8064
8062
  logger$8.info('Retrieving media a configuration', { enableVideo, screenSharing, isDesktop, withAudio, constraints });
8065
8063
 
@@ -8067,7 +8065,8 @@ class WebRTCClient extends Emitter {
8067
8065
  constraints: {
8068
8066
  // Exact constraint are not supported with `getDisplayMedia` and we must have a video=false in desktop screenshare
8069
8067
  audio: screenSharing ? !isDesktop : (withAudio ? this._getAudioConstraints() : false),
8070
- video: screenSharing ? (isDesktop ? ({ mandatory: { chromeMediaSource: 'desktop' } }) : { cursor: 'always' })
8068
+ video: screenSharing ? (isDesktop
8069
+ ? ({ mandatory: { chromeMediaSource: 'desktop', ...(mandatoryVideo || {}) } }) : { cursor: 'always' })
8071
8070
  : this._getVideoConstraints(enableVideo),
8072
8071
  screen: screenSharing,
8073
8072
  desktop: isDesktop,
@@ -8402,11 +8401,14 @@ class WebRTCClient extends Emitter {
8402
8401
 
8403
8402
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8404
8403
 
8405
- pc.oniceconnectionstatechange = () => {
8406
- if (pc.iceConnectionState === 'disconnected') {
8407
- this.eventEmitter.emit(ON_DISCONNECTED$1);
8408
- }
8409
- };
8404
+ if (pc) {
8405
+ pc.oniceconnectionstatechange = () => {
8406
+ logger$8.info('on ice connection state changed', { state: pc.iceConnectionState });
8407
+ if (pc.iceConnectionState === 'disconnected') {
8408
+ this.eventEmitter.emit(ON_DISCONNECTED$1);
8409
+ }
8410
+ };
8411
+ }
8410
8412
 
8411
8413
  if (withEvent) {
8412
8414
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
@@ -8616,13 +8618,17 @@ class WebRTCClient extends Emitter {
8616
8618
  const nbStats = this.sessionNetworkStats[sessionId].length;
8617
8619
  const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
8618
8620
  const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
8621
+ const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
8619
8622
  const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
8620
8623
  const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
8624
+ const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
8621
8625
  const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
8622
8626
  const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
8623
8627
  const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
8624
- let audioBytesSent = 0;
8625
- let audioBytesReceived = 0;
8628
+ let audioBytesSent = 0; // content + header
8629
+ let audioBytesReceived = 0; // content + header
8630
+ let audioContentSent = 0; // useful to detect blank call
8631
+ let audioContentReceived = 0;
8626
8632
  let videoBytesSent = 0;
8627
8633
  let videoBytesReceived = 0;
8628
8634
  let transportSent = 0;
@@ -8631,25 +8637,27 @@ class WebRTCClient extends Emitter {
8631
8637
 
8632
8638
  stats.forEach(report => {
8633
8639
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8634
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8640
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8641
+ audioContentSent += Number(report.bytesSent);
8635
8642
  }
8636
8643
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8637
- audioBytesSent += report.bytesSent;
8644
+ audioBytesSent += Number(report.bytesSent);
8638
8645
  }
8639
8646
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8640
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8647
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8641
8648
  }
8642
8649
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8643
- packetsLost += report.packetsLost;
8644
- networkStats.packetsReceived = report.packetsReceived;
8645
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8650
+ packetsLost += Number(report.packetsLost);
8651
+ networkStats.packetsReceived = Number(report.packetsReceived);
8652
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8653
+ audioContentReceived += Number(report.bytesReceived);
8646
8654
  }
8647
8655
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8648
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8656
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8649
8657
  }
8650
8658
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8651
8659
  if ('framesPerSecond' in report) {
8652
- networkStats.framesPerSecond = report.framesPerSecond;
8660
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8653
8661
  }
8654
8662
  if ('framerateMean' in report) {
8655
8663
  // framerateMean is only available in FF
@@ -8657,24 +8665,31 @@ class WebRTCClient extends Emitter {
8657
8665
  }
8658
8666
  }
8659
8667
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8660
- packetsLost += report.packetsLost;
8661
- networkStats.roundTripTime = report.roundTripTime;
8662
- networkStats.jitter = report.jitter;
8668
+ packetsLost += Number(report.packetsLost);
8669
+ networkStats.roundTripTime = Number(report.roundTripTime);
8670
+ networkStats.jitter = Number(report.jitter);
8663
8671
  }
8664
8672
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8665
- packetsLost += report.packetsLost;
8673
+ packetsLost += Number(report.packetsLost);
8666
8674
  }
8667
8675
  if (report.type === 'transport') {
8668
- transportSent += report.bytesSent;
8669
- transportReceived += report.bytesReceived;
8676
+ transportSent += Number(report.bytesSent);
8677
+ transportReceived += Number(report.bytesReceived);
8670
8678
  }
8671
8679
  });
8672
8680
 
8673
8681
  networkStats.packetsLost = packetsLost;
8682
+
8674
8683
  networkStats.totalAudioBytesSent = audioBytesSent;
8675
8684
  networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8676
8685
  networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8677
8686
  networkStats.audioBytesReceived = audioBytesReceived;
8687
+
8688
+ networkStats.totalAudioContentSent = audioContentSent;
8689
+ networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
8690
+ networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
8691
+ networkStats.audioContentReceived = audioContentReceived;
8692
+
8678
8693
  networkStats.totalVideoBytesSent = videoBytesSent;
8679
8694
  networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8680
8695
  networkStats.totalVideoBytesReceived = videoBytesReceived;
@@ -8886,6 +8901,7 @@ class WebRTCPhone extends Emitter {
8886
8901
  constraints,
8887
8902
  audioOnly,
8888
8903
  conference,
8904
+ iceRestart,
8889
8905
  });
8890
8906
 
8891
8907
  if (!sipSession) {
@@ -8989,6 +9005,11 @@ class WebRTCPhone extends Emitter {
8989
9005
 
8990
9006
  this.client.downgradeToAudio(sipSession);
8991
9007
 
9008
+ if (callSession) {
9009
+ callSession.cameraEnabled = false;
9010
+ this._updateCallSession(callSession);
9011
+ }
9012
+
8992
9013
  if (withMessage) {
8993
9014
  this._sendReinviteMessage(callSession, false);
8994
9015
  }
@@ -9016,6 +9037,11 @@ class WebRTCPhone extends Emitter {
9016
9037
 
9017
9038
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
9018
9039
 
9040
+ if (callSession) {
9041
+ callSession.cameraEnabled = true;
9042
+ this._updateCallSession(callSession);
9043
+ }
9044
+
9019
9045
  // If no stream is returned, it means we have to reinvite
9020
9046
  if (!newStream) {
9021
9047
  return true;
@@ -9068,7 +9094,10 @@ class WebRTCPhone extends Emitter {
9068
9094
 
9069
9095
  onCancel(message);
9070
9096
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
9071
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
9097
+ const callSession = this._createCallSession(sipSession);
9098
+ delete this.callSessions[callSession.getId()];
9099
+
9100
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
9072
9101
  };
9073
9102
  } else if (sipSession instanceof invitation.Invitation) {
9074
9103
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -9249,18 +9278,20 @@ class WebRTCPhone extends Emitter {
9249
9278
  screenTrack,
9250
9279
  });
9251
9280
 
9252
- screenTrack.onended = () => {
9253
- logger$7.info('WebRTC phone - on screenshare ended', {
9254
- hadVideo,
9255
- id: this.getSipSessionId(sipSession),
9256
- screenTrack,
9257
- });
9281
+ if (screenTrack) {
9282
+ screenTrack.onended = () => {
9283
+ logger$7.info('WebRTC phone - on screenshare ended', {
9284
+ hadVideo,
9285
+ id: this.getSipSessionId(sipSession),
9286
+ screenTrack,
9287
+ });
9258
9288
 
9259
- this.eventEmitter.emit(
9260
- ON_SHARE_SCREEN_ENDING,
9261
- this._createCallSession(sipSession, callSession),
9262
- );
9263
- };
9289
+ this.eventEmitter.emit(
9290
+ ON_SHARE_SCREEN_ENDING,
9291
+ this._createCallSession(sipSession, callSession),
9292
+ );
9293
+ };
9294
+ }
9264
9295
 
9265
9296
  this.currentScreenShare = {
9266
9297
  stream: screenStream,
@@ -9280,7 +9311,7 @@ class WebRTCPhone extends Emitter {
9280
9311
  }
9281
9312
 
9282
9313
  _onCallAccepted(sipSession , cameraEnabled ) {
9283
- logger$7.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9314
+ logger$7.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9284
9315
 
9285
9316
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
9286
9317
  this.currentSipSession = sipSession;
@@ -9792,7 +9823,7 @@ class WebRTCPhone extends Emitter {
9792
9823
  // @TODO: line is not used here
9793
9824
  async makeCall(number , line , cameraEnabled ,
9794
9825
  audioOnly = false, conference = false) {
9795
- logger$7.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled });
9826
+ logger$7.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled, audioOnly, conference });
9796
9827
  if (!number) {
9797
9828
  return Promise.resolve(null);
9798
9829
  }
@@ -10153,9 +10184,13 @@ class WebRTCPhone extends Emitter {
10153
10184
  if (this.shouldSendReinvite && this.currentSipSession
10154
10185
  && this.currentSipSession.state === sessionState.SessionState.Established) {
10155
10186
  this.shouldSendReinvite = false;
10187
+ const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
10188
+ const isConference = pc ? pc.sfu : false;
10189
+ const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
10190
+
10156
10191
  try {
10157
10192
  // Send reinvite with iceRestart
10158
- this.sendReinvite(this.currentCallSession, null, false, false, true);
10193
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
10159
10194
  } catch (e) {
10160
10195
  logger$7.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
10161
10196
  }
@@ -10239,6 +10274,15 @@ class WebRTCPhone extends Emitter {
10239
10274
  return this.client.getSipSessionId(sipSession);
10240
10275
  }
10241
10276
 
10277
+ _updateCallSession(callSession ) {
10278
+ const sipSession = this.findSipSession(callSession);
10279
+ const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10280
+
10281
+ if (sipSessionId) {
10282
+ this.callSessions[sipSessionId] = callSession;
10283
+ }
10284
+ }
10285
+
10242
10286
  _onMessage(message ) {
10243
10287
  if (!message || message.method !== 'MESSAGE') {
10244
10288
  return;