@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
@@ -95,6 +95,9 @@ class Call {
95
95
 
96
96
 
97
97
  static parseMany(plain ) {
98
+ if (!plain) {
99
+ return [];
100
+ }
98
101
  return plain.map((plainCall ) => Call.parse(plainCall));
99
102
  }
100
103
 
@@ -2101,6 +2104,9 @@ class Contact {
2101
2104
  }
2102
2105
 
2103
2106
  static parseMany(response ) {
2107
+ if (!response || !response.results) {
2108
+ return [];
2109
+ }
2104
2110
  return response.results.map(r => Contact.parse(r, response.column_types));
2105
2111
  }
2106
2112
 
@@ -3178,8 +3184,9 @@ class ExternalApp {
3178
3184
 
3179
3185
 
3180
3186
 
3181
-
3187
+
3182
3188
 
3189
+
3183
3190
 
3184
3191
 
3185
3192
  class Meeting {
@@ -3190,9 +3197,10 @@ class Meeting {
3190
3197
 
3191
3198
 
3192
3199
 
3193
-
3200
+
3194
3201
 
3195
3202
 
3203
+
3196
3204
 
3197
3205
  static parse(plain ) {
3198
3206
  return new Meeting({
@@ -3202,12 +3210,16 @@ class Meeting {
3202
3210
  ownerUuids: plain.owner_uuids,
3203
3211
  port: plain.port,
3204
3212
  uuid: plain.uuid,
3205
- number: plain.number,
3213
+ extension: plain.exten,
3206
3214
  persistent: plain.persistent,
3215
+ creationTime: moment(plain.creation_time).toDate(),
3207
3216
  });
3208
3217
  }
3209
3218
 
3210
3219
  static parseMany(items ) {
3220
+ if (!items) {
3221
+ return [];
3222
+ }
3211
3223
  return items.map(plain => Meeting.parse(plain));
3212
3224
  }
3213
3225
 
@@ -3222,8 +3234,9 @@ class Meeting {
3222
3234
  ownerUuids,
3223
3235
  port,
3224
3236
  uri,
3225
- number,
3237
+ extension,
3226
3238
  persistent,
3239
+ creationTime,
3227
3240
  } = {}) {
3228
3241
  this.guestSipAuthorization = guestSipAuthorization;
3229
3242
  this.uri = uri;
@@ -3231,8 +3244,9 @@ class Meeting {
3231
3244
  this.ownerUuids = ownerUuids;
3232
3245
  this.port = port;
3233
3246
  this.uuid = uuid;
3234
- this.number = number;
3247
+ this.extension = extension;
3235
3248
  this.persistent = persistent;
3249
+ this.creationTime = creationTime;
3236
3250
 
3237
3251
  // Useful to compare instead of instanceof with minified code
3238
3252
  this.type = 'Meeting';
@@ -3410,6 +3424,10 @@ class ChatMessage {
3410
3424
 
3411
3425
 
3412
3426
  static parseMany(plain ) {
3427
+ if (!plain || !plain.items) {
3428
+ return [];
3429
+ }
3430
+
3413
3431
  return plain.items.map(item => ChatMessage.parse(item));
3414
3432
  }
3415
3433
 
@@ -3519,6 +3537,9 @@ class Voicemail {
3519
3537
  }
3520
3538
 
3521
3539
  static parseMany(plain ) {
3540
+ if (!plain) {
3541
+ return [];
3542
+ }
3522
3543
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3523
3544
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3524
3545
 
@@ -3620,6 +3641,9 @@ class Recording {
3620
3641
 
3621
3642
 
3622
3643
  static parseMany(recordings = []) {
3644
+ if (!recordings) {
3645
+ return [];
3646
+ }
3623
3647
  return recordings.map(item => Recording.parse(item));
3624
3648
  }
3625
3649
 
@@ -3721,6 +3745,10 @@ class CallLog {
3721
3745
  }
3722
3746
 
3723
3747
  static parseMany(plain ) {
3748
+ if (!plain || !plain.items) {
3749
+ return [];
3750
+ }
3751
+
3724
3752
  return plain.items.map(item => CallLog.parse(item));
3725
3753
  }
3726
3754
 
@@ -4290,6 +4318,10 @@ class CTIPhone extends Emitter {
4290
4318
  return false;
4291
4319
  }
4292
4320
 
4321
+ hasAVideoTrack() {
4322
+ return false;
4323
+ }
4324
+
4293
4325
  getLocalStreamForCall() {
4294
4326
  return null;
4295
4327
  }
@@ -4683,6 +4715,9 @@ class ChatRoom {
4683
4715
 
4684
4716
 
4685
4717
  static parseMany(plain ) {
4718
+ if (!plain || !plain.items) {
4719
+ return [];
4720
+ }
4686
4721
  return plain.items.map(item => ChatRoom.parse(item));
4687
4722
  }
4688
4723
 
@@ -5664,10 +5699,6 @@ const getSrflxOrRelay = (candidates ) =>
5664
5699
  candidates
5665
5700
  .filter(candidate => candidate && (candidate.type === 'srflx' || candidate.type === 'relay'));
5666
5701
 
5667
- const areCandidateValid = (candidates ) =>
5668
- getSrflxOrRelay(candidates)
5669
- .length > 0;
5670
-
5671
5702
  const getVideoDirection = (sdp ) => {
5672
5703
  const parsedSdp = sdpParser.parse(sdp);
5673
5704
  const videoMedia = parsedSdp.media.find(media => media.type === 'video');
@@ -5720,8 +5751,6 @@ const fixSdp = (sdp , candidates , forcePort = true)
5720
5751
  /* global RTCSessionDescriptionInit, navigator */
5721
5752
 
5722
5753
  const wazoLogger = IssueReporter$1 ? IssueReporter$1.loggerFor('webrtc-sdh') : console;
5723
- const MAX_WAIT_FOR_ICE_TRIES = 20;
5724
- const WAIT_FOR_ICE_TIMEOUT = 500;
5725
5754
 
5726
5755
  // Customized mediaStreamFactory allowing to send screensharing stream directory when upgrading
5727
5756
  const wazoMediaStreamFactory = (constraints ) => {
@@ -5911,38 +5940,6 @@ class WazoSessionDescriptionHandler extends SessionDescriptionHandler {
5911
5940
  this._peerConnection = undefined;
5912
5941
  }
5913
5942
 
5914
- async _waitForValidGatheredIce() {
5915
- let tries = 0;
5916
-
5917
- while (!areCandidateValid(this.gatheredCandidates) && tries < MAX_WAIT_FOR_ICE_TRIES) {
5918
- wazoLogger.trace('SessionDescriptionHandler._waitForValidGatheredIce, waiting for ice', {
5919
- tries,
5920
- max: MAX_WAIT_FOR_ICE_TRIES,
5921
- });
5922
-
5923
- tries++;
5924
-
5925
- // eslint-disable-next-line no-await-in-loop
5926
- await new Promise(resolve => setTimeout(resolve, WAIT_FOR_ICE_TIMEOUT));
5927
- }
5928
-
5929
- if (tries >= MAX_WAIT_FOR_ICE_TRIES) {
5930
- const errorMsg = 'No valid candidates found, can\'t answer the call';
5931
- const error = new Error(errorMsg);
5932
- wazoLogger.error(errorMsg, { tries, max: MAX_WAIT_FOR_ICE_TRIES });
5933
-
5934
- // Emit an error, because sip.js catches the exception and switch to status Terminated.
5935
- this.eventEmitter.emit('error', error);
5936
-
5937
- wazoLogger.error('No valid candidates found', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5938
- }
5939
-
5940
- // eslint-disable-next-line
5941
- wazoLogger.trace('Found valid candidates', { tries, candidates: JSON.stringify(this.gatheredCandidates) });
5942
-
5943
- return this.getLocalSessionDescription();
5944
- }
5945
-
5946
5943
  // Overridden to send `inactive` in conference
5947
5944
  updateDirection(options , isConference = false,
5948
5945
  audioOnly = false) {
@@ -6710,7 +6707,7 @@ class WebRTCClient extends Emitter {
6710
6707
  }
6711
6708
 
6712
6709
  call(number , enableVideo , audioOnly = false, conference = false) {
6713
- logger$9.info('sdk webrtc creating call', { number, enableVideo, audioOnly });
6710
+ logger$9.info('sdk webrtc creating call', { number, enableVideo, audioOnly, conference });
6714
6711
  const inviterOptions = {
6715
6712
  sessionDescriptionHandlerOptionsReInvite: {
6716
6713
  conference,
@@ -7786,6 +7783,7 @@ class WebRTCClient extends Emitter {
7786
7783
  const screenSharing = constraints && 'screen' in constraints ? constraints.screen : false;
7787
7784
  const isDesktop = constraints && 'desktop' in constraints ? constraints.desktop : false;
7788
7785
  const withAudio = constraints && 'audio' in constraints ? constraints.audio : true;
7786
+ const mandatoryVideo = constraints && typeof constraints.video === 'object' ? constraints.video.mandatory : {};
7789
7787
 
7790
7788
  logger$9.info('Retrieving media a configuration', { enableVideo, screenSharing, isDesktop, withAudio, constraints });
7791
7789
 
@@ -7793,7 +7791,8 @@ class WebRTCClient extends Emitter {
7793
7791
  constraints: {
7794
7792
  // Exact constraint are not supported with `getDisplayMedia` and we must have a video=false in desktop screenshare
7795
7793
  audio: screenSharing ? !isDesktop : (withAudio ? this._getAudioConstraints() : false),
7796
- video: screenSharing ? (isDesktop ? ({ mandatory: { chromeMediaSource: 'desktop' } }) : { cursor: 'always' })
7794
+ video: screenSharing ? (isDesktop
7795
+ ? ({ mandatory: { chromeMediaSource: 'desktop', ...(mandatoryVideo || {}) } }) : { cursor: 'always' })
7797
7796
  : this._getVideoConstraints(enableVideo),
7798
7797
  screen: screenSharing,
7799
7798
  desktop: isDesktop,
@@ -8128,11 +8127,14 @@ class WebRTCClient extends Emitter {
8128
8127
 
8129
8128
  session.sessionDescriptionHandler.remoteMediaStream.onaddtrack = onTrack;
8130
8129
 
8131
- pc.oniceconnectionstatechange = () => {
8132
- if (pc.iceConnectionState === 'disconnected') {
8133
- this.eventEmitter.emit(ON_DISCONNECTED$1);
8134
- }
8135
- };
8130
+ if (pc) {
8131
+ pc.oniceconnectionstatechange = () => {
8132
+ logger$9.info('on ice connection state changed', { state: pc.iceConnectionState });
8133
+ if (pc.iceConnectionState === 'disconnected') {
8134
+ this.eventEmitter.emit(ON_DISCONNECTED$1);
8135
+ }
8136
+ };
8137
+ }
8136
8138
 
8137
8139
  if (withEvent) {
8138
8140
  this.eventEmitter.emit(ACCEPTED, session, sessionDialog);
@@ -8342,13 +8344,17 @@ class WebRTCClient extends Emitter {
8342
8344
  const nbStats = this.sessionNetworkStats[sessionId].length;
8343
8345
  const lastNetworkStats = this.sessionNetworkStats[sessionId][nbStats - 1];
8344
8346
  const lastAudioSent = lastNetworkStats ? lastNetworkStats.audioBytesSent : 0;
8347
+ const lastAudioContentSent = lastNetworkStats ? lastNetworkStats.audioContentSent : 0;
8345
8348
  const lastVideoSent = lastNetworkStats ? lastNetworkStats.videoBytesSent : 0;
8346
8349
  const lastAudioReceived = lastNetworkStats ? lastNetworkStats.audioBytesReceived : 0;
8350
+ const lastAudioContentReceived = lastNetworkStats ? lastNetworkStats.audioContentReceived : 0;
8347
8351
  const lastVideoReceived = lastNetworkStats ? lastNetworkStats.videoBytesReceived : 0;
8348
8352
  const lastTransportSent = lastNetworkStats ? lastNetworkStats.transportSent : 0;
8349
8353
  const lastTransportReceived = lastNetworkStats ? lastNetworkStats.transportReceived : 0;
8350
- let audioBytesSent = 0;
8351
- let audioBytesReceived = 0;
8354
+ let audioBytesSent = 0; // content + header
8355
+ let audioBytesReceived = 0; // content + header
8356
+ let audioContentSent = 0; // useful to detect blank call
8357
+ let audioContentReceived = 0;
8352
8358
  let videoBytesSent = 0;
8353
8359
  let videoBytesReceived = 0;
8354
8360
  let transportSent = 0;
@@ -8357,25 +8363,27 @@ class WebRTCClient extends Emitter {
8357
8363
 
8358
8364
  stats.forEach(report => {
8359
8365
  if (report.type === 'outbound-rtp' && report.kind === 'audio') {
8360
- audioBytesSent += report.bytesSent + report.headerBytesSent;
8366
+ audioBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8367
+ audioContentSent += Number(report.bytesSent);
8361
8368
  }
8362
8369
  if (report.type === 'remote-outbound-rtp' && report.kind === 'audio') {
8363
- audioBytesSent += report.bytesSent;
8370
+ audioBytesSent += Number(report.bytesSent);
8364
8371
  }
8365
8372
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8366
- videoBytesSent += report.bytesSent + report.headerBytesSent;
8373
+ videoBytesSent += Number(report.bytesSent) + Number(report.headerBytesSent);
8367
8374
  }
8368
8375
  if (report.type === 'inbound-rtp' && report.kind === 'audio') {
8369
- packetsLost += report.packetsLost;
8370
- networkStats.packetsReceived = report.packetsReceived;
8371
- audioBytesReceived += report.bytesReceived + report.headerBytesReceived;
8376
+ packetsLost += Number(report.packetsLost);
8377
+ networkStats.packetsReceived = Number(report.packetsReceived);
8378
+ audioBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8379
+ audioContentReceived += Number(report.bytesReceived);
8372
8380
  }
8373
8381
  if (report.type === 'inbound-rtp' && report.kind === 'video') {
8374
- videoBytesReceived += report.bytesReceived + report.headerBytesReceived;
8382
+ videoBytesReceived += Number(report.bytesReceived) + Number(report.headerBytesReceived);
8375
8383
  }
8376
8384
  if (report.type === 'outbound-rtp' && report.kind === 'video') {
8377
8385
  if ('framesPerSecond' in report) {
8378
- networkStats.framesPerSecond = report.framesPerSecond;
8386
+ networkStats.framesPerSecond = Number(report.framesPerSecond);
8379
8387
  }
8380
8388
  if ('framerateMean' in report) {
8381
8389
  // framerateMean is only available in FF
@@ -8383,24 +8391,31 @@ class WebRTCClient extends Emitter {
8383
8391
  }
8384
8392
  }
8385
8393
  if (report.type === 'remote-inbound-rtp' && report.kind === 'audio') {
8386
- packetsLost += report.packetsLost;
8387
- networkStats.roundTripTime = report.roundTripTime;
8388
- networkStats.jitter = report.jitter;
8394
+ packetsLost += Number(report.packetsLost);
8395
+ networkStats.roundTripTime = Number(report.roundTripTime);
8396
+ networkStats.jitter = Number(report.jitter);
8389
8397
  }
8390
8398
  if (report.type === 'remote-inbound-rtp' && report.kind === 'video') {
8391
- packetsLost += report.packetsLost;
8399
+ packetsLost += Number(report.packetsLost);
8392
8400
  }
8393
8401
  if (report.type === 'transport') {
8394
- transportSent += report.bytesSent;
8395
- transportReceived += report.bytesReceived;
8402
+ transportSent += Number(report.bytesSent);
8403
+ transportReceived += Number(report.bytesReceived);
8396
8404
  }
8397
8405
  });
8398
8406
 
8399
8407
  networkStats.packetsLost = packetsLost;
8408
+
8400
8409
  networkStats.totalAudioBytesSent = audioBytesSent;
8401
8410
  networkStats.audioBytesSent = audioBytesSent - lastAudioSent;
8402
8411
  networkStats.totalAudioBytesReceived = audioBytesReceived - lastAudioReceived;
8403
8412
  networkStats.audioBytesReceived = audioBytesReceived;
8413
+
8414
+ networkStats.totalAudioContentSent = audioContentSent;
8415
+ networkStats.audioContentSent = audioContentSent - lastAudioContentSent;
8416
+ networkStats.totalAudioBytesReceived = audioContentReceived - lastAudioContentReceived;
8417
+ networkStats.audioContentReceived = audioContentReceived;
8418
+
8404
8419
  networkStats.totalVideoBytesSent = videoBytesSent;
8405
8420
  networkStats.videoBytesSent = videoBytesSent - lastVideoSent;
8406
8421
  networkStats.totalVideoBytesReceived = videoBytesReceived;
@@ -8612,6 +8627,7 @@ class WebRTCPhone extends Emitter {
8612
8627
  constraints,
8613
8628
  audioOnly,
8614
8629
  conference,
8630
+ iceRestart,
8615
8631
  });
8616
8632
 
8617
8633
  if (!sipSession) {
@@ -8715,6 +8731,11 @@ class WebRTCPhone extends Emitter {
8715
8731
 
8716
8732
  this.client.downgradeToAudio(sipSession);
8717
8733
 
8734
+ if (callSession) {
8735
+ callSession.cameraEnabled = false;
8736
+ this._updateCallSession(callSession);
8737
+ }
8738
+
8718
8739
  if (withMessage) {
8719
8740
  this._sendReinviteMessage(callSession, false);
8720
8741
  }
@@ -8742,6 +8763,11 @@ class WebRTCPhone extends Emitter {
8742
8763
 
8743
8764
  const newStream = await this.client.upgradeToVideo(sipSession, constraints, isConference);
8744
8765
 
8766
+ if (callSession) {
8767
+ callSession.cameraEnabled = true;
8768
+ this._updateCallSession(callSession);
8769
+ }
8770
+
8745
8771
  // If no stream is returned, it means we have to reinvite
8746
8772
  if (!newStream) {
8747
8773
  return true;
@@ -8794,7 +8820,10 @@ class WebRTCPhone extends Emitter {
8794
8820
 
8795
8821
  onCancel(message);
8796
8822
  const elsewhere = message.data.indexOf('cause=26') !== -1 && message.data.indexOf('completed elsewhere') !== -1;
8797
- this.eventEmitter.emit(ON_CALL_CANCELED, this._createCallSession(sipSession), elsewhere);
8823
+ const callSession = this._createCallSession(sipSession);
8824
+ delete this.callSessions[callSession.getId()];
8825
+
8826
+ this.eventEmitter.emit(ON_CALL_CANCELED, callSession, elsewhere);
8798
8827
  };
8799
8828
  } else if (sipSession instanceof Invitation) {
8800
8829
  console.warn('sipSession._onCancel not found, please update the wazo SDK accordingly');
@@ -8975,18 +9004,20 @@ class WebRTCPhone extends Emitter {
8975
9004
  screenTrack,
8976
9005
  });
8977
9006
 
8978
- screenTrack.onended = () => {
8979
- logger$8.info('WebRTC phone - on screenshare ended', {
8980
- hadVideo,
8981
- id: this.getSipSessionId(sipSession),
8982
- screenTrack,
8983
- });
9007
+ if (screenTrack) {
9008
+ screenTrack.onended = () => {
9009
+ logger$8.info('WebRTC phone - on screenshare ended', {
9010
+ hadVideo,
9011
+ id: this.getSipSessionId(sipSession),
9012
+ screenTrack,
9013
+ });
8984
9014
 
8985
- this.eventEmitter.emit(
8986
- ON_SHARE_SCREEN_ENDING,
8987
- this._createCallSession(sipSession, callSession),
8988
- );
8989
- };
9015
+ this.eventEmitter.emit(
9016
+ ON_SHARE_SCREEN_ENDING,
9017
+ this._createCallSession(sipSession, callSession),
9018
+ );
9019
+ };
9020
+ }
8990
9021
 
8991
9022
  this.currentScreenShare = {
8992
9023
  stream: screenStream,
@@ -9006,7 +9037,7 @@ class WebRTCPhone extends Emitter {
9006
9037
  }
9007
9038
 
9008
9039
  _onCallAccepted(sipSession , cameraEnabled ) {
9009
- logger$8.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9040
+ logger$8.info('WebRTC phone - on call accepted', { sipId: sipSession.id, cameraEnabled });
9010
9041
 
9011
9042
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
9012
9043
  this.currentSipSession = sipSession;
@@ -9518,7 +9549,7 @@ class WebRTCPhone extends Emitter {
9518
9549
  // @TODO: line is not used here
9519
9550
  async makeCall(number , line , cameraEnabled ,
9520
9551
  audioOnly = false, conference = false) {
9521
- logger$8.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled });
9552
+ logger$8.info('make WebRTC call', { number, lineId: line ? line.id : null, cameraEnabled, audioOnly, conference });
9522
9553
  if (!number) {
9523
9554
  return Promise.resolve(null);
9524
9555
  }
@@ -9879,9 +9910,13 @@ class WebRTCPhone extends Emitter {
9879
9910
  if (this.shouldSendReinvite && this.currentSipSession
9880
9911
  && this.currentSipSession.state === SessionState.Established) {
9881
9912
  this.shouldSendReinvite = false;
9913
+ const pc = this.currentSipSession.sessionDescriptionHandler.peerConnection;
9914
+ const isConference = pc ? pc.sfu : false;
9915
+ const hasVideo = this.currentCallSession && this.currentCallSession.cameraEnabled;
9916
+
9882
9917
  try {
9883
9918
  // Send reinvite with iceRestart
9884
- this.sendReinvite(this.currentCallSession, null, false, false, true);
9919
+ this.sendReinvite(this.currentCallSession, null, isConference, !hasVideo, true);
9885
9920
  } catch (e) {
9886
9921
  logger$8.error('WebRTC reinvite after register, error', { message: e.message, stack: e.stack });
9887
9922
  }
@@ -9965,6 +10000,15 @@ class WebRTCPhone extends Emitter {
9965
10000
  return this.client.getSipSessionId(sipSession);
9966
10001
  }
9967
10002
 
10003
+ _updateCallSession(callSession ) {
10004
+ const sipSession = this.findSipSession(callSession);
10005
+ const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10006
+
10007
+ if (sipSessionId) {
10008
+ this.callSessions[sipSessionId] = callSession;
10009
+ }
10010
+ }
10011
+
9968
10012
  _onMessage(message ) {
9969
10013
  if (!message || message.method !== 'MESSAGE') {
9970
10014
  return;