@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
@@ -105,6 +105,9 @@ class Call {
105
105
 
106
106
 
107
107
  static parseMany(plain ) {
108
+ if (!plain) {
109
+ return [];
110
+ }
108
111
  return plain.map((plainCall ) => Call.parse(plainCall));
109
112
  }
110
113
 
@@ -2111,6 +2114,9 @@ class Contact {
2111
2114
  }
2112
2115
 
2113
2116
  static parseMany(response ) {
2117
+ if (!response || !response.results) {
2118
+ return [];
2119
+ }
2114
2120
  return response.results.map(r => Contact.parse(r, response.column_types));
2115
2121
  }
2116
2122
 
@@ -2481,7 +2487,7 @@ class Contact {
2481
2487
  this[key] = old[key] || this[key];
2482
2488
  });
2483
2489
 
2484
- if (old.lineState && !this.lineState) {
2490
+ if (old.lineState) {
2485
2491
  this.lineState = old.lineState;
2486
2492
  }
2487
2493
 
@@ -3188,8 +3194,9 @@ class ExternalApp {
3188
3194
 
3189
3195
 
3190
3196
 
3191
-
3197
+
3192
3198
 
3199
+
3193
3200
 
3194
3201
 
3195
3202
  class Meeting {
@@ -3200,9 +3207,10 @@ class Meeting {
3200
3207
 
3201
3208
 
3202
3209
 
3203
-
3210
+
3204
3211
 
3205
3212
 
3213
+
3206
3214
 
3207
3215
  static parse(plain ) {
3208
3216
  return new Meeting({
@@ -3212,12 +3220,16 @@ class Meeting {
3212
3220
  ownerUuids: plain.owner_uuids,
3213
3221
  port: plain.port,
3214
3222
  uuid: plain.uuid,
3215
- number: plain.number,
3223
+ extension: plain.exten,
3216
3224
  persistent: plain.persistent,
3225
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
3217
3226
  });
3218
3227
  }
3219
3228
 
3220
3229
  static parseMany(items ) {
3230
+ if (!items) {
3231
+ return [];
3232
+ }
3221
3233
  return items.map(plain => Meeting.parse(plain));
3222
3234
  }
3223
3235
 
@@ -3232,8 +3244,9 @@ class Meeting {
3232
3244
  ownerUuids,
3233
3245
  port,
3234
3246
  uri,
3235
- number,
3247
+ extension,
3236
3248
  persistent,
3249
+ creationTime,
3237
3250
  } = {}) {
3238
3251
  this.guestSipAuthorization = guestSipAuthorization;
3239
3252
  this.uri = uri;
@@ -3241,8 +3254,9 @@ class Meeting {
3241
3254
  this.ownerUuids = ownerUuids;
3242
3255
  this.port = port;
3243
3256
  this.uuid = uuid;
3244
- this.number = number;
3257
+ this.extension = extension;
3245
3258
  this.persistent = persistent;
3259
+ this.creationTime = creationTime;
3246
3260
 
3247
3261
  // Useful to compare instead of instanceof with minified code
3248
3262
  this.type = 'Meeting';
@@ -3420,6 +3434,10 @@ class ChatMessage {
3420
3434
 
3421
3435
 
3422
3436
  static parseMany(plain ) {
3437
+ if (!plain || !plain.items) {
3438
+ return [];
3439
+ }
3440
+
3423
3441
  return plain.items.map(item => ChatMessage.parse(item));
3424
3442
  }
3425
3443
 
@@ -3529,6 +3547,9 @@ class Voicemail {
3529
3547
  }
3530
3548
 
3531
3549
  static parseMany(plain ) {
3550
+ if (!plain) {
3551
+ return [];
3552
+ }
3532
3553
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3533
3554
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3534
3555
 
@@ -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,12 +8137,14 @@ class WebRTCClient extends Emitter {
8138
8137
 
8139
8138
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8140
8139
 
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
- };
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
+ }
8147
8148
 
8148
8149
  if (withEvent) {
8149
8150
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
@@ -8353,13 +8354,17 @@ class WebRTCClient extends Emitter {
8353
8354
  const nbStats = this.sessionNetworkStats[sessionId].length;
8354
8355
  const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
8355
8356
  const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
8357
+ const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
8356
8358
  const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
8357
8359
  const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
8360
+ const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
8358
8361
  const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
8359
8362
  const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
8360
8363
  const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
8361
- let audioBytesSent = 0;
8362
- 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;
8363
8368
  let videoBytesSent = 0;
8364
8369
  let videoBytesReceived = 0;
8365
8370
  let transportSent = 0;
@@ -8368,25 +8373,27 @@ class WebRTCClient extends Emitter {
8368
8373
 
8369
8374
  stats.forEach(report => {
8370
8375
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8371
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8376
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8377
+ audioContentSent += Number(report.bytesSent);
8372
8378
  }
8373
8379
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8374
- audioBytesSent += report.bytesSent;
8380
+ audioBytesSent += Number(report.bytesSent);
8375
8381
  }
8376
8382
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8377
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8383
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8378
8384
  }
8379
8385
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8380
- packetsLost += report.packetsLost;
8381
- networkStats.packetsReceived = report.packetsReceived;
8382
- 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);
8383
8390
  }
8384
8391
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8385
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8392
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8386
8393
  }
8387
8394
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8388
8395
  if ('framesPerSecond' in report) {
8389
- networkStats.framesPerSecond = report.framesPerSecond;
8396
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8390
8397
  }
8391
8398
  if ('framerateMean' in report) {
8392
8399
  // framerateMean is only available in FF
@@ -8394,24 +8401,31 @@ class WebRTCClient extends Emitter {
8394
8401
  }
8395
8402
  }
8396
8403
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8397
- packetsLost += report.packetsLost;
8398
- networkStats.roundTripTime = report.roundTripTime;
8399
- networkStats.jitter = report.jitter;
8404
+ packetsLost += Number(report.packetsLost);
8405
+ networkStats.roundTripTime = Number(report.roundTripTime);
8406
+ networkStats.jitter = Number(report.jitter);
8400
8407
  }
8401
8408
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8402
- packetsLost += report.packetsLost;
8409
+ packetsLost += Number(report.packetsLost);
8403
8410
  }
8404
8411
  if (report.type === 'transport') {
8405
- transportSent += report.bytesSent;
8406
- transportReceived += report.bytesReceived;
8412
+ transportSent += Number(report.bytesSent);
8413
+ transportReceived += Number(report.bytesReceived);
8407
8414
  }
8408
8415
  });
8409
8416
 
8410
8417
  networkStats.packetsLost = packetsLost;
8418
+
8411
8419
  networkStats.totalAudioBytesSent = audioBytesSent;
8412
8420
  networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8413
8421
  networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8414
8422
  networkStats.audioBytesReceived = audioBytesReceived;
8423
+
8424
+ networkStats.totalAudioContentSent = audioContentSent;
8425
+ networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
8426
+ networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
8427
+ networkStats.audioContentReceived = audioContentReceived;
8428
+
8415
8429
  networkStats.totalVideoBytesSent = videoBytesSent;
8416
8430
  networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8417
8431
  networkStats.totalVideoBytesReceived = videoBytesReceived;
@@ -8623,6 +8637,7 @@ class WebRTCPhone extends Emitter {
8623
8637
  constraints,
8624
8638
  audioOnly,
8625
8639
  conference,
8640
+ iceRestart,
8626
8641
  });
8627
8642
 
8628
8643
  if (!sipSession) {
@@ -8726,6 +8741,11 @@ class WebRTCPhone extends Emitter {
8726
8741
 
8727
8742
  this.client.downgradeToAudio(sipSession);
8728
8743
 
8744
+ if (callSession) {
8745
+ callSession.cameraEnabled = false;
8746
+ this._updateCallSession(callSession);
8747
+ }
8748
+
8729
8749
  if (withMessage) {
8730
8750
  this._sendReinviteMessage(callSession, false);
8731
8751
  }
@@ -8753,6 +8773,11 @@ class WebRTCPhone extends Emitter {
8753
8773
 
8754
8774
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
8755
8775
 
8776
+ if (callSession) {
8777
+ callSession.cameraEnabled = true;
8778
+ this._updateCallSession(callSession);
8779
+ }
8780
+
8756
8781
  // If no stream is returned, it means we have to reinvite
8757
8782
  if (!newStream) {
8758
8783
  return true;
@@ -8989,18 +9014,20 @@ class WebRTCPhone extends Emitter {
8989
9014
  screenTrack,
8990
9015
  });
8991
9016
 
8992
- screenTrack.onended = () => {
8993
- logger$8.info('WebRTC phone - on screenshare ended', {
8994
- hadVideo,
8995
- id: this.getSipSessionId(sipSession),
8996
- screenTrack,
8997
- });
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
+ });
8998
9024
 
8999
- this.eventEmitter.emit(
9000
- ON_SHARE_SCREEN_ENDING,
9001
- this._createCallSession(sipSession, callSession),
9002
- );
9003
- };
9025
+ this.eventEmitter.emit(
9026
+ ON_SHARE_SCREEN_ENDING,
9027
+ this._createCallSession(sipSession, callSession),
9028
+ );
9029
+ };
9030
+ }
9004
9031
 
9005
9032
  this.currentScreenShare = {
9006
9033
  stream: screenStream,
@@ -9020,7 +9047,7 @@ class WebRTCPhone extends Emitter {
9020
9047
  }
9021
9048
 
9022
9049
  _onCallAccepted(sipSession , cameraEnabled ) {
9023
- 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 });
9024
9051
 
9025
9052
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
9026
9053
  this.currentSipSession = sipSession;
@@ -9532,7 +9559,7 @@ class WebRTCPhone extends Emitter {
9532
9559
  // @TODO: line is not used here
9533
9560
  async makeCall(number , line , cameraEnabled ,
9534
9561
  audioOnly = false, conference = false) {
9535
- 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 });
9536
9563
  if (!number) {
9537
9564
  return Promise.resolve(null);
9538
9565
  }
@@ -9893,9 +9920,13 @@ class WebRTCPhone extends Emitter {
9893
9920
  if (this.shouldSendReinvite && this.currentSipSession
9894
9921
  && this.currentSipSession.state === sessionState.SessionState.Established) {
9895
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
+
9896
9927
  try {
9897
9928
  // Send reinvite with iceRestart
9898
- this.sendReinvite(this.currentCallSession, null, false, false, true);
9929
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
9899
9930
  } catch (e) {
9900
9931
  logger$8.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
9901
9932
  }
@@ -9979,6 +10010,15 @@ class WebRTCPhone extends Emitter {
9979
10010
  return this.client.getSipSessionId(sipSession);
9980
10011
  }
9981
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
+
9982
10022
  _onMessage(message ) {
9983
10023
  if (!message || message.method !== 'MESSAGE') {
9984
10024
  return;