@wazo/sdk 0.37.22 → 0.37.26

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 +37 -6
  3. package/esm/__tests__/web-rtc-client.test.js +78 -68
  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 +4 -1
  10. package/esm/api-client.js +37 -6
  11. package/esm/checker/Checker.js +78 -68
  12. package/esm/checker/checks/aor.js +37 -6
  13. package/esm/checker/checks/api.js +37 -6
  14. package/esm/checker/checks/index.js +78 -68
  15. package/esm/checker/checks/webrtc-transport.js +78 -68
  16. package/esm/checker/checks/webrtc.js +78 -68
  17. package/esm/domain/AdHocAPIConference.js +37 -6
  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 +4 -1
  23. package/esm/domain/Features.js +37 -6
  24. package/esm/domain/Meeting.js +15 -5
  25. package/esm/domain/Phone/CTIPhone.js +41 -6
  26. package/esm/domain/Phone/WebRTCPhone.js +41 -15
  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 +4 -1
  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 +122 -82
  35. package/esm/lib/WazoSessionDescriptionHandler.js +0 -38
  36. package/esm/service/CallApi.js +37 -6
  37. package/esm/service/getApiClient.js +37 -6
  38. package/esm/simple/Auth.js +122 -82
  39. package/esm/simple/Configuration.js +122 -82
  40. package/esm/simple/Directory.js +37 -6
  41. package/esm/simple/Phone.js +122 -82
  42. package/esm/simple/index.js +122 -82
  43. package/esm/simple/room/LocalParticipant.js +122 -82
  44. package/esm/simple/room/Participant.js +122 -82
  45. package/esm/simple/room/RemoteParticipant.js +122 -82
  46. package/esm/simple/room/Room.js +122 -82
  47. package/esm/simple/room/SipRoom.js +122 -82
  48. package/esm/simple/room/Stream.js +122 -82
  49. package/esm/simple/room/__tests__/RemoteParticipant.test.js +122 -82
  50. package/esm/simple/utils.js +122 -82
  51. package/esm/types/WebSocketMessage.js +1 -1
  52. package/esm/web-rtc-client.js +78 -68
  53. package/lib/__tests__/api-client.test.js +37 -6
  54. package/lib/__tests__/web-rtc-client.test.js +78 -68
  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 +4 -1
  61. package/lib/api-client.js +37 -6
  62. package/lib/checker/Checker.js +78 -68
  63. package/lib/checker/checks/aor.js +37 -6
  64. package/lib/checker/checks/api.js +37 -6
  65. package/lib/checker/checks/index.js +78 -68
  66. package/lib/checker/checks/webrtc-transport.js +78 -68
  67. package/lib/checker/checks/webrtc.js +78 -68
  68. package/lib/domain/AdHocAPIConference.js +37 -6
  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 +4 -1
  74. package/lib/domain/Features.js +37 -6
  75. package/lib/domain/Meeting.js +19 -5
  76. package/lib/domain/Phone/CTIPhone.js +41 -6
  77. package/lib/domain/Phone/WebRTCPhone.js +41 -15
  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 +4 -1
  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 +122 -82
  86. package/lib/lib/WazoSessionDescriptionHandler.js +0 -38
  87. package/lib/service/CallApi.js +37 -6
  88. package/lib/service/getApiClient.js +37 -6
  89. package/lib/simple/Auth.js +122 -82
  90. package/lib/simple/Configuration.js +122 -82
  91. package/lib/simple/Directory.js +37 -6
  92. package/lib/simple/Phone.js +122 -82
  93. package/lib/simple/index.js +122 -82
  94. package/lib/simple/room/LocalParticipant.js +122 -82
  95. package/lib/simple/room/Participant.js +122 -82
  96. package/lib/simple/room/RemoteParticipant.js +122 -82
  97. package/lib/simple/room/Room.js +122 -82
  98. package/lib/simple/room/SipRoom.js +122 -82
  99. package/lib/simple/room/Stream.js +122 -82
  100. package/lib/simple/room/__tests__/RemoteParticipant.test.js +122 -82
  101. package/lib/simple/utils.js +122 -82
  102. package/lib/types/WebSocketMessage.js +2 -0
  103. package/lib/web-rtc-client.js +78 -68
  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 +4 -1
  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 +41 -15
  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 -24
@@ -875,6 +875,9 @@ class Contact {
875
875
  }
876
876
 
877
877
  static parseMany(response ) {
878
+ if (!response || !response.results) {
879
+ return [];
880
+ }
878
881
  return response.results.map(r => Contact.parse(r, response.column_types));
879
882
  }
880
883
 
@@ -1245,7 +1248,7 @@ class Contact {
1245
1248
  this[key] = old[key] || this[key];
1246
1249
  });
1247
1250
 
1248
- if (old.lineState && !this.lineState) {
1251
+ if (old.lineState) {
1249
1252
  this.lineState = old.lineState;
1250
1253
  }
1251
1254
 
@@ -2639,8 +2642,9 @@ class ExternalApp {
2639
2642
 
2640
2643
 
2641
2644
 
2642
-
2645
+
2643
2646
 
2647
+
2644
2648
 
2645
2649
 
2646
2650
  class Meeting {
@@ -2651,9 +2655,10 @@ class Meeting {
2651
2655
 
2652
2656
 
2653
2657
 
2654
-
2658
+
2655
2659
 
2656
2660
 
2661
+
2657
2662
 
2658
2663
  static parse(plain ) {
2659
2664
  return new Meeting({
@@ -2663,12 +2668,16 @@ class Meeting {
2663
2668
  ownerUuids: plain.owner_uuids,
2664
2669
  port: plain.port,
2665
2670
  uuid: plain.uuid,
2666
- number: plain.number,
2671
+ extension: plain.exten,
2667
2672
  persistent: plain.persistent,
2673
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
2668
2674
  });
2669
2675
  }
2670
2676
 
2671
2677
  static parseMany(items ) {
2678
+ if (!items) {
2679
+ return [];
2680
+ }
2672
2681
  return items.map(plain => Meeting.parse(plain));
2673
2682
  }
2674
2683
 
@@ -2683,8 +2692,9 @@ class Meeting {
2683
2692
  ownerUuids,
2684
2693
  port,
2685
2694
  uri,
2686
- number,
2695
+ extension,
2687
2696
  persistent,
2697
+ creationTime,
2688
2698
  } = {}) {
2689
2699
  this.guestSipAuthorization = guestSipAuthorization;
2690
2700
  this.uri = uri;
@@ -2692,8 +2702,9 @@ class Meeting {
2692
2702
  this.ownerUuids = ownerUuids;
2693
2703
  this.port = port;
2694
2704
  this.uuid = uuid;
2695
- this.number = number;
2705
+ this.extension = extension;
2696
2706
  this.persistent = persistent;
2707
+ this.creationTime = creationTime;
2697
2708
 
2698
2709
  // Useful to compare instead of instanceof with minified code
2699
2710
  this.type = 'Meeting';
@@ -2871,6 +2882,10 @@ class ChatMessage {
2871
2882
 
2872
2883
 
2873
2884
  static parseMany(plain ) {
2885
+ if (!plain || !plain.items) {
2886
+ return [];
2887
+ }
2888
+
2874
2889
  return plain.items.map(item => ChatMessage.parse(item));
2875
2890
  }
2876
2891
 
@@ -2980,6 +2995,9 @@ class Voicemail {
2980
2995
  }
2981
2996
 
2982
2997
  static parseMany(plain ) {
2998
+ if (!plain) {
2999
+ return [];
3000
+ }
2983
3001
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2984
3002
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2985
3003
 
@@ -3089,6 +3107,9 @@ class Call {
3089
3107
 
3090
3108
 
3091
3109
  static parseMany(plain ) {
3110
+ if (!plain) {
3111
+ return [];
3112
+ }
3092
3113
  return plain.map((plainCall ) => Call.parse(plainCall));
3093
3114
  }
3094
3115
 
@@ -3632,6 +3653,9 @@ class Recording {
3632
3653
 
3633
3654
 
3634
3655
  static parseMany(recordings = []) {
3656
+ if (!recordings) {
3657
+ return [];
3658
+ }
3635
3659
  return recordings.map(item => Recording.parse(item));
3636
3660
  }
3637
3661
 
@@ -3733,6 +3757,10 @@ class CallLog {
3733
3757
  }
3734
3758
 
3735
3759
  static parseMany(plain ) {
3760
+ if (!plain || !plain.items) {
3761
+ return [];
3762
+ }
3763
+
3736
3764
  return plain.items.map(item => CallLog.parse(item));
3737
3765
  }
3738
3766
 
@@ -4302,6 +4330,10 @@ class CTIPhone extends Emitter {
4302
4330
  return false;
4303
4331
  }
4304
4332
 
4333
+ hasAVideoTrack() {
4334
+ return false;
4335
+ }
4336
+
4305
4337
  getLocalStreamForCall() {
4306
4338
  return null;
4307
4339
  }
@@ -4695,6 +4727,9 @@ class ChatRoom {
4695
4727
 
4696
4728
 
4697
4729
  static parseMany(plain ) {
4730
+ if (!plain || !plain.items) {
4731
+ return [];
4732
+ }
4698
4733
  return plain.items.map(item => ChatRoom.parse(item));
4699
4734
  }
4700
4735
 
@@ -5940,10 +5975,6 @@ const getSrflxOrRelay = (candidates ) =>
5940
5975
  candidates
5941
5976
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5942
5977
 
5943
- const areCandidateValid = (candidates ) =>
5944
- getSrflxOrRelay(candidates)
5945
- .length > 0;
5946
-
5947
5978
  const getVideoDirection = (sdp ) => {
5948
5979
  const parsedSdp = sdpParser__default['default'].parse(sdp);
5949
5980
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5996,8 +6027,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5996
6027
  /* global RTCSessionDescriptionInit, navigator */
5997
6028
 
5998
6029
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5999
- const MAX_WAIT_FOR_ICE_TRIES = 20;
6000
- const WAIT_FOR_ICE_TIMEOUT = 500;
6001
6030
 
6002
6031
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
6003
6032
  const wazoMediaStreamFactory = (constraints ) => {
@@ -6187,38 +6216,6 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
6187
6216
  this._peerConnection = undefined;
6188
6217
  }
6189
6218
 
6190
- async _waitForValidGatheredIce() {
6191
- let tries = 0;
6192
-
6193
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
6194
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
6195
- tries,
6196
- max: MAX_WAIT_FOR_ICE_TRIES,
6197
- });
6198
-
6199
- tries++;
6200
-
6201
- // eslint-disable-next-line no-await-in-loop
6202
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
6203
- }
6204
-
6205
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
6206
- const errorMsg = 'No valid candidates found, can\'t answer the call';
6207
- const error = new Error(errorMsg);
6208
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
6209
-
6210
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
6211
- this.eventEmitter.emit('error', error);
6212
-
6213
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6214
- }
6215
-
6216
- // eslint-disable-next-line
6217
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
6218
-
6219
- return this.getLocalSessionDescription();
6220
- }
6221
-
6222
6219
  // Overridden to send `inactive` in conference
6223
6220
  updateDirection(options , isConference = false,
6224
6221
  audioOnly = false) {
@@ -6986,7 +6983,7 @@ class WebRTCClient extends Emitter {
6986
6983
  }
6987
6984
 
6988
6985
  call(number , enableVideo , audioOnly = false, conference = false) {
6989
- logger$8.info('sdk webrtc creating call', { number, enableVideo, audioOnly });
6986
+ logger$8.info('sdk webrtc creating call', { number, enableVideo, audioOnly, conference });
6990
6987
  const inviterOptions = {
6991
6988
  sessionDescriptionHandlerOptionsReInvite: {
6992
6989
  conference,
@@ -8062,6 +8059,7 @@ class WebRTCClient extends Emitter {
8062
8059
  const screenSharing = constraints && 'screen' in constraints ? constraints.screen : false;
8063
8060
  const isDesktop = constraints && 'desktop' in constraints ? constraints.desktop : false;
8064
8061
  const withAudio = constraints && 'audio' in constraints ? constraints.audio : true;
8062
+ const mandatoryVideo = constraints && typeof constraints.video === 'object' ? constraints.video.mandatory : {};
8065
8063
 
8066
8064
  logger$8.info('Retrieving media a configuration', { enableVideo, screenSharing, isDesktop, withAudio, constraints });
8067
8065
 
@@ -8069,7 +8067,8 @@ class WebRTCClient extends Emitter {
8069
8067
  constraints: {
8070
8068
  // Exact constraint are not supported with `getDisplayMedia` and we must have a video=false in desktop screenshare
8071
8069
  audio: screenSharing ? !isDesktop : (withAudio ? this._getAudioConstraints() : false),
8072
- video: screenSharing ? (isDesktop ? ({ mandatory: { chromeMediaSource: 'desktop' } }) : { cursor: 'always' })
8070
+ video: screenSharing ? (isDesktop
8071
+ ? ({ mandatory: { chromeMediaSource: 'desktop', ...(mandatoryVideo || {}) } }) : { cursor: 'always' })
8073
8072
  : this._getVideoConstraints(enableVideo),
8074
8073
  screen: screenSharing,
8075
8074
  desktop: isDesktop,
@@ -8404,12 +8403,14 @@ class WebRTCClient extends Emitter {
8404
8403
 
8405
8404
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8406
8405
 
8407
- pc.oniceconnectionstatechange = () => {
8408
- logger$8.info('on ice connection state changed', { state: pc.iceConnectionState });
8409
- if (pc.iceConnectionState === 'disconnected') {
8410
- this.eventEmitter.emit(ON_DISCONNECTED$1);
8411
- }
8412
- };
8406
+ if (pc) {
8407
+ pc.oniceconnectionstatechange = () => {
8408
+ logger$8.info('on ice connection state changed', { state: pc.iceConnectionState });
8409
+ if (pc.iceConnectionState === 'disconnected') {
8410
+ this.eventEmitter.emit(ON_DISCONNECTED$1);
8411
+ }
8412
+ };
8413
+ }
8413
8414
 
8414
8415
  if (withEvent) {
8415
8416
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
@@ -8619,13 +8620,17 @@ class WebRTCClient extends Emitter {
8619
8620
  const nbStats = this.sessionNetworkStats[sessionId].length;
8620
8621
  const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
8621
8622
  const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
8623
+ const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
8622
8624
  const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
8623
8625
  const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
8626
+ const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
8624
8627
  const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
8625
8628
  const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
8626
8629
  const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
8627
- let audioBytesSent = 0;
8628
- let audioBytesReceived = 0;
8630
+ let audioBytesSent = 0; // content + header
8631
+ let audioBytesReceived = 0; // content + header
8632
+ let audioContentSent = 0; // useful to detect blank call
8633
+ let audioContentReceived = 0;
8629
8634
  let videoBytesSent = 0;
8630
8635
  let videoBytesReceived = 0;
8631
8636
  let transportSent = 0;
@@ -8634,25 +8639,27 @@ class WebRTCClient extends Emitter {
8634
8639
 
8635
8640
  stats.forEach(report => {
8636
8641
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8637
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8642
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8643
+ audioContentSent += Number(report.bytesSent);
8638
8644
  }
8639
8645
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8640
- audioBytesSent += report.bytesSent;
8646
+ audioBytesSent += Number(report.bytesSent);
8641
8647
  }
8642
8648
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8643
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8649
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8644
8650
  }
8645
8651
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8646
- packetsLost += report.packetsLost;
8647
- networkStats.packetsReceived = report.packetsReceived;
8648
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8652
+ packetsLost += Number(report.packetsLost);
8653
+ networkStats.packetsReceived = Number(report.packetsReceived);
8654
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8655
+ audioContentReceived += Number(report.bytesReceived);
8649
8656
  }
8650
8657
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8651
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8658
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8652
8659
  }
8653
8660
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8654
8661
  if ('framesPerSecond' in report) {
8655
- networkStats.framesPerSecond = report.framesPerSecond;
8662
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8656
8663
  }
8657
8664
  if ('framerateMean' in report) {
8658
8665
  // framerateMean is only available in FF
@@ -8660,24 +8667,31 @@ class WebRTCClient extends Emitter {
8660
8667
  }
8661
8668
  }
8662
8669
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8663
- packetsLost += report.packetsLost;
8664
- networkStats.roundTripTime = report.roundTripTime;
8665
- networkStats.jitter = report.jitter;
8670
+ packetsLost += Number(report.packetsLost);
8671
+ networkStats.roundTripTime = Number(report.roundTripTime);
8672
+ networkStats.jitter = Number(report.jitter);
8666
8673
  }
8667
8674
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8668
- packetsLost += report.packetsLost;
8675
+ packetsLost += Number(report.packetsLost);
8669
8676
  }
8670
8677
  if (report.type === 'transport') {
8671
- transportSent += report.bytesSent;
8672
- transportReceived += report.bytesReceived;
8678
+ transportSent += Number(report.bytesSent);
8679
+ transportReceived += Number(report.bytesReceived);
8673
8680
  }
8674
8681
  });
8675
8682
 
8676
8683
  networkStats.packetsLost = packetsLost;
8684
+
8677
8685
  networkStats.totalAudioBytesSent = audioBytesSent;
8678
8686
  networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8679
8687
  networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8680
8688
  networkStats.audioBytesReceived = audioBytesReceived;
8689
+
8690
+ networkStats.totalAudioContentSent = audioContentSent;
8691
+ networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
8692
+ networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
8693
+ networkStats.audioContentReceived = audioContentReceived;
8694
+
8681
8695
  networkStats.totalVideoBytesSent = videoBytesSent;
8682
8696
  networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8683
8697
  networkStats.totalVideoBytesReceived = videoBytesReceived;
@@ -8889,6 +8903,7 @@ class WebRTCPhone extends Emitter {
8889
8903
  constraints,
8890
8904
  audioOnly,
8891
8905
  conference,
8906
+ iceRestart,
8892
8907
  });
8893
8908
 
8894
8909
  if (!sipSession) {
@@ -8992,6 +9007,11 @@ class WebRTCPhone extends Emitter {
8992
9007
 
8993
9008
  this.client.downgradeToAudio(sipSession);
8994
9009
 
9010
+ if (callSession) {
9011
+ callSession.cameraEnabled = false;
9012
+ this._updateCallSession(callSession);
9013
+ }
9014
+
8995
9015
  if (withMessage) {
8996
9016
  this._sendReinviteMessage(callSession, false);
8997
9017
  }
@@ -9019,6 +9039,11 @@ class WebRTCPhone extends Emitter {
9019
9039
 
9020
9040
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
9021
9041
 
9042
+ if (callSession) {
9043
+ callSession.cameraEnabled = true;
9044
+ this._updateCallSession(callSession);
9045
+ }
9046
+
9022
9047
  // If no stream is returned, it means we have to reinvite
9023
9048
  if (!newStream) {
9024
9049
  return true;
@@ -9255,18 +9280,20 @@ class WebRTCPhone extends Emitter {
9255
9280
  screenTrack,
9256
9281
  });
9257
9282
 
9258
- screenTrack.onended = () => {
9259
- logger$7.info('WebRTC phone - on screenshare ended', {
9260
- hadVideo,
9261
- id: this.getSipSessionId(sipSession),
9262
- screenTrack,
9263
- });
9283
+ if (screenTrack) {
9284
+ screenTrack.onended = () => {
9285
+ logger$7.info('WebRTC phone - on screenshare ended', {
9286
+ hadVideo,
9287
+ id: this.getSipSessionId(sipSession),
9288
+ screenTrack,
9289
+ });
9264
9290
 
9265
- this.eventEmitter.emit(
9266
- ON_SHARE_SCREEN_ENDING,
9267
- this._createCallSession(sipSession, callSession),
9268
- );
9269
- };
9291
+ this.eventEmitter.emit(
9292
+ ON_SHARE_SCREEN_ENDING,
9293
+ this._createCallSession(sipSession, callSession),
9294
+ );
9295
+ };
9296
+ }
9270
9297
 
9271
9298
  this.currentScreenShare = {
9272
9299
  stream: screenStream,
@@ -9286,7 +9313,7 @@ class WebRTCPhone extends Emitter {
9286
9313
  }
9287
9314
 
9288
9315
  _onCallAccepted(sipSession , cameraEnabled ) {
9289
- logger$7.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9316
+ logger$7.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9290
9317
 
9291
9318
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
9292
9319
  this.currentSipSession = sipSession;
@@ -9798,7 +9825,7 @@ class WebRTCPhone extends Emitter {
9798
9825
  // @TODO: line is not used here
9799
9826
  async makeCall(number , line , cameraEnabled ,
9800
9827
  audioOnly = false, conference = false) {
9801
- logger$7.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled });
9828
+ logger$7.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled, audioOnly, conference });
9802
9829
  if (!number) {
9803
9830
  return Promise.resolve(null);
9804
9831
  }
@@ -10159,9 +10186,13 @@ class WebRTCPhone extends Emitter {
10159
10186
  if (this.shouldSendReinvite && this.currentSipSession
10160
10187
  && this.currentSipSession.state === sessionState.SessionState.Established) {
10161
10188
  this.shouldSendReinvite = false;
10189
+ const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
10190
+ const isConference = pc ? pc.sfu : false;
10191
+ const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
10192
+
10162
10193
  try {
10163
10194
  // Send reinvite with iceRestart
10164
- this.sendReinvite(this.currentCallSession, null, false, false, true);
10195
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
10165
10196
  } catch (e) {
10166
10197
  logger$7.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
10167
10198
  }
@@ -10245,6 +10276,15 @@ class WebRTCPhone extends Emitter {
10245
10276
  return this.client.getSipSessionId(sipSession);
10246
10277
  }
10247
10278
 
10279
+ _updateCallSession(callSession ) {
10280
+ const sipSession = this.findSipSession(callSession);
10281
+ const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10282
+
10283
+ if (sipSessionId) {
10284
+ this.callSessions[sipSessionId] = callSession;
10285
+ }
10286
+ }
10287
+
10248
10288
  _onMessage(message ) {
10249
10289
  if (!message || message.method !== 'MESSAGE') {
10250
10290
  return;
@@ -1,2 +1,4 @@
1
1
  'use strict';
2
2
 
3
+ require('moment');
4
+