@wazo/sdk 0.37.4 → 0.37.8

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 (45) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/web-rtc-client.test.js +4 -0
  3. package/esm/checker/Checker.js +4 -0
  4. package/esm/checker/checks/index.js +4 -0
  5. package/esm/checker/checks/webrtc-transport.js +4 -0
  6. package/esm/checker/checks/webrtc.js +4 -0
  7. package/esm/domain/Phone/WebRTCPhone.js +17 -4
  8. package/esm/index.js +23 -5
  9. package/esm/simple/Auth.js +23 -5
  10. package/esm/simple/Configuration.js +23 -5
  11. package/esm/simple/Phone.js +23 -5
  12. package/esm/simple/index.js +23 -5
  13. package/esm/simple/room/LocalParticipant.js +23 -5
  14. package/esm/simple/room/Participant.js +23 -5
  15. package/esm/simple/room/RemoteParticipant.js +23 -5
  16. package/esm/simple/room/Room.js +23 -5
  17. package/esm/simple/room/SipRoom.js +23 -5
  18. package/esm/simple/room/Stream.js +23 -5
  19. package/esm/simple/room/__tests__/RemoteParticipant.test.js +23 -5
  20. package/esm/simple/utils.js +23 -5
  21. package/esm/web-rtc-client.js +4 -0
  22. package/lib/__tests__/web-rtc-client.test.js +4 -0
  23. package/lib/checker/Checker.js +4 -0
  24. package/lib/checker/checks/index.js +4 -0
  25. package/lib/checker/checks/webrtc-transport.js +4 -0
  26. package/lib/checker/checks/webrtc.js +4 -0
  27. package/lib/domain/Phone/WebRTCPhone.js +17 -4
  28. package/lib/index.js +23 -5
  29. package/lib/simple/Auth.js +23 -5
  30. package/lib/simple/Configuration.js +23 -5
  31. package/lib/simple/Phone.js +23 -5
  32. package/lib/simple/index.js +23 -5
  33. package/lib/simple/room/LocalParticipant.js +23 -5
  34. package/lib/simple/room/Participant.js +23 -5
  35. package/lib/simple/room/RemoteParticipant.js +23 -5
  36. package/lib/simple/room/Room.js +23 -5
  37. package/lib/simple/room/SipRoom.js +23 -5
  38. package/lib/simple/room/Stream.js +23 -5
  39. package/lib/simple/room/__tests__/RemoteParticipant.test.js +23 -5
  40. package/lib/simple/utils.js +23 -5
  41. package/lib/web-rtc-client.js +4 -0
  42. package/package.json +1 -1
  43. package/src/domain/Phone/WebRTCPhone.js +17 -4
  44. package/src/simple/room/Room.js +2 -1
  45. package/src/web-rtc-client.js +4 -0
@@ -7043,6 +7043,8 @@ class WebRTCClient extends Emitter {
7043
7043
  }
7044
7044
  options.sessionDescriptionHandlerOptions = {
7045
7045
  constraints: options.constraints,
7046
+ hold: true,
7047
+ conference: isConference,
7046
7048
  };
7047
7049
 
7048
7050
  // Send re-INVITE
@@ -7085,6 +7087,8 @@ class WebRTCClient extends Emitter {
7085
7087
  }
7086
7088
  options.sessionDescriptionHandlerOptions = {
7087
7089
  constraints: options.constraints,
7090
+ hold: false,
7091
+ conference: isConference,
7088
7092
  };
7089
7093
 
7090
7094
  // Send re-INVITE
@@ -8414,7 +8418,7 @@ class WebRTCPhone extends Emitter {
8414
8418
  return this.client.onDisconnect();
8415
8419
  }
8416
8420
 
8417
- _downgradeToAudio(callSession ) {
8421
+ _downgradeToAudio(callSession , withMessage = true) {
8418
8422
  const sipSession = this.findSipSession(callSession);
8419
8423
  if (!sipSession) {
8420
8424
  return false;
@@ -8441,7 +8445,9 @@ class WebRTCPhone extends Emitter {
8441
8445
  localStream.removeTrack(videoTrack);
8442
8446
  });
8443
8447
 
8444
- this._sendReinviteMessage(callSession, false);
8448
+ if (withMessage) {
8449
+ this._sendReinviteMessage(callSession, false);
8450
+ }
8445
8451
 
8446
8452
  return true;
8447
8453
  }
@@ -8460,9 +8466,9 @@ class WebRTCPhone extends Emitter {
8460
8466
 
8461
8467
  // Check if a video sender already exists
8462
8468
  let videoSender;
8469
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8463
8470
  if (isConference) {
8464
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
- videoSender = trans ? trans.sender : null;
8471
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8466
8472
  } else {
8467
8473
  videoSender = pc.getSenders().find(sender => sender.track === null);
8468
8474
  }
@@ -8492,6 +8498,11 @@ class WebRTCPhone extends Emitter {
8492
8498
  videoSender.replaceTrack(videoTrack);
8493
8499
  }
8494
8500
 
8501
+ // Put back last direction (was set to `recvonly` when downgrading)
8502
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8503
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8504
+ }
8505
+
8495
8506
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8496
8507
  this._sendReinviteMessage(callSession, true);
8497
8508
 
@@ -8654,6 +8665,12 @@ class WebRTCPhone extends Emitter {
8654
8665
  // We have to downgrade to audio.
8655
8666
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8656
8667
  const constraints = { audio: false, video: screenshareStopped };
8668
+ if (!conference) {
8669
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8670
+ this._downgradeToAudio(targetCallSession, false);
8671
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8672
+ await new Promise(resolve => setTimeout(resolve, 500));
8673
+ }
8657
8674
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8658
8675
  }
8659
8676
  } catch (e) {
@@ -12961,7 +12978,8 @@ class Room extends Emitter {
12961
12978
  }
12962
12979
 
12963
12980
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
12964
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
12981
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
12982
+ stream && stream.id === streamId);
12965
12983
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
12966
12984
  }
12967
12985
 
@@ -7045,6 +7045,8 @@ class WebRTCClient extends Emitter {
7045
7045
  }
7046
7046
  options.sessionDescriptionHandlerOptions = {
7047
7047
  constraints: options.constraints,
7048
+ hold: true,
7049
+ conference: isConference,
7048
7050
  };
7049
7051
 
7050
7052
  // Send re-INVITE
@@ -7087,6 +7089,8 @@ class WebRTCClient extends Emitter {
7087
7089
  }
7088
7090
  options.sessionDescriptionHandlerOptions = {
7089
7091
  constraints: options.constraints,
7092
+ hold: false,
7093
+ conference: isConference,
7090
7094
  };
7091
7095
 
7092
7096
  // Send re-INVITE
@@ -8416,7 +8420,7 @@ class WebRTCPhone extends Emitter {
8416
8420
  return this.client.onDisconnect();
8417
8421
  }
8418
8422
 
8419
- _downgradeToAudio(callSession ) {
8423
+ _downgradeToAudio(callSession , withMessage = true) {
8420
8424
  const sipSession = this.findSipSession(callSession);
8421
8425
  if (!sipSession) {
8422
8426
  return false;
@@ -8443,7 +8447,9 @@ class WebRTCPhone extends Emitter {
8443
8447
  localStream.removeTrack(videoTrack);
8444
8448
  });
8445
8449
 
8446
- this._sendReinviteMessage(callSession, false);
8450
+ if (withMessage) {
8451
+ this._sendReinviteMessage(callSession, false);
8452
+ }
8447
8453
 
8448
8454
  return true;
8449
8455
  }
@@ -8462,9 +8468,9 @@ class WebRTCPhone extends Emitter {
8462
8468
 
8463
8469
  // Check if a video sender already exists
8464
8470
  let videoSender;
8471
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
8472
  if (isConference) {
8466
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8467
- videoSender = trans ? trans.sender : null;
8473
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8468
8474
  } else {
8469
8475
  videoSender = pc.getSenders().find(sender => sender.track === null);
8470
8476
  }
@@ -8494,6 +8500,11 @@ class WebRTCPhone extends Emitter {
8494
8500
  videoSender.replaceTrack(videoTrack);
8495
8501
  }
8496
8502
 
8503
+ // Put back last direction (was set to `recvonly` when downgrading)
8504
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8505
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8506
+ }
8507
+
8497
8508
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8498
8509
  this._sendReinviteMessage(callSession, true);
8499
8510
 
@@ -8656,6 +8667,12 @@ class WebRTCPhone extends Emitter {
8656
8667
  // We have to downgrade to audio.
8657
8668
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8658
8669
  const constraints = { audio: false, video: screenshareStopped };
8670
+ if (!conference) {
8671
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8672
+ this._downgradeToAudio(targetCallSession, false);
8673
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8674
+ await new Promise(resolve => setTimeout(resolve, 500));
8675
+ }
8659
8676
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8660
8677
  }
8661
8678
  } catch (e) {
@@ -12974,7 +12991,8 @@ class Room extends Emitter {
12974
12991
  }
12975
12992
 
12976
12993
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
12977
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
12994
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
12995
+ stream && stream.id === streamId);
12978
12996
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
12979
12997
  }
12980
12998
 
@@ -7043,6 +7043,8 @@ class WebRTCClient extends Emitter {
7043
7043
  }
7044
7044
  options.sessionDescriptionHandlerOptions = {
7045
7045
  constraints: options.constraints,
7046
+ hold: true,
7047
+ conference: isConference,
7046
7048
  };
7047
7049
 
7048
7050
  // Send re-INVITE
@@ -7085,6 +7087,8 @@ class WebRTCClient extends Emitter {
7085
7087
  }
7086
7088
  options.sessionDescriptionHandlerOptions = {
7087
7089
  constraints: options.constraints,
7090
+ hold: false,
7091
+ conference: isConference,
7088
7092
  };
7089
7093
 
7090
7094
  // Send re-INVITE
@@ -8414,7 +8418,7 @@ class WebRTCPhone extends Emitter {
8414
8418
  return this.client.onDisconnect();
8415
8419
  }
8416
8420
 
8417
- _downgradeToAudio(callSession ) {
8421
+ _downgradeToAudio(callSession , withMessage = true) {
8418
8422
  const sipSession = this.findSipSession(callSession);
8419
8423
  if (!sipSession) {
8420
8424
  return false;
@@ -8441,7 +8445,9 @@ class WebRTCPhone extends Emitter {
8441
8445
  localStream.removeTrack(videoTrack);
8442
8446
  });
8443
8447
 
8444
- this._sendReinviteMessage(callSession, false);
8448
+ if (withMessage) {
8449
+ this._sendReinviteMessage(callSession, false);
8450
+ }
8445
8451
 
8446
8452
  return true;
8447
8453
  }
@@ -8460,9 +8466,9 @@ class WebRTCPhone extends Emitter {
8460
8466
 
8461
8467
  // Check if a video sender already exists
8462
8468
  let videoSender;
8469
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8463
8470
  if (isConference) {
8464
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
- videoSender = trans ? trans.sender : null;
8471
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8466
8472
  } else {
8467
8473
  videoSender = pc.getSenders().find(sender => sender.track === null);
8468
8474
  }
@@ -8492,6 +8498,11 @@ class WebRTCPhone extends Emitter {
8492
8498
  videoSender.replaceTrack(videoTrack);
8493
8499
  }
8494
8500
 
8501
+ // Put back last direction (was set to `recvonly` when downgrading)
8502
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8503
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8504
+ }
8505
+
8495
8506
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8496
8507
  this._sendReinviteMessage(callSession, true);
8497
8508
 
@@ -8654,6 +8665,12 @@ class WebRTCPhone extends Emitter {
8654
8665
  // We have to downgrade to audio.
8655
8666
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8656
8667
  const constraints = { audio: false, video: screenshareStopped };
8668
+ if (!conference) {
8669
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8670
+ this._downgradeToAudio(targetCallSession, false);
8671
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8672
+ await new Promise(resolve => setTimeout(resolve, 500));
8673
+ }
8657
8674
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8658
8675
  }
8659
8676
  } catch (e) {
@@ -11816,7 +11833,8 @@ class Room$1 extends Emitter {
11816
11833
  }
11817
11834
 
11818
11835
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
11819
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
11836
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
11837
+ stream && stream.id === streamId);
11820
11838
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
11821
11839
  }
11822
11840
 
@@ -7043,6 +7043,8 @@ class WebRTCClient extends Emitter {
7043
7043
  }
7044
7044
  options.sessionDescriptionHandlerOptions = {
7045
7045
  constraints: options.constraints,
7046
+ hold: true,
7047
+ conference: isConference,
7046
7048
  };
7047
7049
 
7048
7050
  // Send re-INVITE
@@ -7085,6 +7087,8 @@ class WebRTCClient extends Emitter {
7085
7087
  }
7086
7088
  options.sessionDescriptionHandlerOptions = {
7087
7089
  constraints: options.constraints,
7090
+ hold: false,
7091
+ conference: isConference,
7088
7092
  };
7089
7093
 
7090
7094
  // Send re-INVITE
@@ -8414,7 +8418,7 @@ class WebRTCPhone extends Emitter {
8414
8418
  return this.client.onDisconnect();
8415
8419
  }
8416
8420
 
8417
- _downgradeToAudio(callSession ) {
8421
+ _downgradeToAudio(callSession , withMessage = true) {
8418
8422
  const sipSession = this.findSipSession(callSession);
8419
8423
  if (!sipSession) {
8420
8424
  return false;
@@ -8441,7 +8445,9 @@ class WebRTCPhone extends Emitter {
8441
8445
  localStream.removeTrack(videoTrack);
8442
8446
  });
8443
8447
 
8444
- this._sendReinviteMessage(callSession, false);
8448
+ if (withMessage) {
8449
+ this._sendReinviteMessage(callSession, false);
8450
+ }
8445
8451
 
8446
8452
  return true;
8447
8453
  }
@@ -8460,9 +8466,9 @@ class WebRTCPhone extends Emitter {
8460
8466
 
8461
8467
  // Check if a video sender already exists
8462
8468
  let videoSender;
8469
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8463
8470
  if (isConference) {
8464
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
- videoSender = trans ? trans.sender : null;
8471
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8466
8472
  } else {
8467
8473
  videoSender = pc.getSenders().find(sender => sender.track === null);
8468
8474
  }
@@ -8492,6 +8498,11 @@ class WebRTCPhone extends Emitter {
8492
8498
  videoSender.replaceTrack(videoTrack);
8493
8499
  }
8494
8500
 
8501
+ // Put back last direction (was set to `recvonly` when downgrading)
8502
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8503
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8504
+ }
8505
+
8495
8506
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8496
8507
  this._sendReinviteMessage(callSession, true);
8497
8508
 
@@ -8654,6 +8665,12 @@ class WebRTCPhone extends Emitter {
8654
8665
  // We have to downgrade to audio.
8655
8666
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8656
8667
  const constraints = { audio: false, video: screenshareStopped };
8668
+ if (!conference) {
8669
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8670
+ this._downgradeToAudio(targetCallSession, false);
8671
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8672
+ await new Promise(resolve => setTimeout(resolve, 500));
8673
+ }
8657
8674
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8658
8675
  }
8659
8676
  } catch (e) {
@@ -11816,7 +11833,8 @@ class Room$1 extends Emitter {
11816
11833
  }
11817
11834
 
11818
11835
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
11819
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
11836
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
11837
+ stream && stream.id === streamId);
11820
11838
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
11821
11839
  }
11822
11840
 
@@ -7043,6 +7043,8 @@ class WebRTCClient extends Emitter {
7043
7043
  }
7044
7044
  options.sessionDescriptionHandlerOptions = {
7045
7045
  constraints: options.constraints,
7046
+ hold: true,
7047
+ conference: isConference,
7046
7048
  };
7047
7049
 
7048
7050
  // Send re-INVITE
@@ -7085,6 +7087,8 @@ class WebRTCClient extends Emitter {
7085
7087
  }
7086
7088
  options.sessionDescriptionHandlerOptions = {
7087
7089
  constraints: options.constraints,
7090
+ hold: false,
7091
+ conference: isConference,
7088
7092
  };
7089
7093
 
7090
7094
  // Send re-INVITE
@@ -8414,7 +8418,7 @@ class WebRTCPhone extends Emitter {
8414
8418
  return this.client.onDisconnect();
8415
8419
  }
8416
8420
 
8417
- _downgradeToAudio(callSession ) {
8421
+ _downgradeToAudio(callSession , withMessage = true) {
8418
8422
  const sipSession = this.findSipSession(callSession);
8419
8423
  if (!sipSession) {
8420
8424
  return false;
@@ -8441,7 +8445,9 @@ class WebRTCPhone extends Emitter {
8441
8445
  localStream.removeTrack(videoTrack);
8442
8446
  });
8443
8447
 
8444
- this._sendReinviteMessage(callSession, false);
8448
+ if (withMessage) {
8449
+ this._sendReinviteMessage(callSession, false);
8450
+ }
8445
8451
 
8446
8452
  return true;
8447
8453
  }
@@ -8460,9 +8466,9 @@ class WebRTCPhone extends Emitter {
8460
8466
 
8461
8467
  // Check if a video sender already exists
8462
8468
  let videoSender;
8469
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8463
8470
  if (isConference) {
8464
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
- videoSender = trans ? trans.sender : null;
8471
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8466
8472
  } else {
8467
8473
  videoSender = pc.getSenders().find(sender => sender.track === null);
8468
8474
  }
@@ -8492,6 +8498,11 @@ class WebRTCPhone extends Emitter {
8492
8498
  videoSender.replaceTrack(videoTrack);
8493
8499
  }
8494
8500
 
8501
+ // Put back last direction (was set to `recvonly` when downgrading)
8502
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8503
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8504
+ }
8505
+
8495
8506
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8496
8507
  this._sendReinviteMessage(callSession, true);
8497
8508
 
@@ -8654,6 +8665,12 @@ class WebRTCPhone extends Emitter {
8654
8665
  // We have to downgrade to audio.
8655
8666
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8656
8667
  const constraints = { audio: false, video: screenshareStopped };
8668
+ if (!conference) {
8669
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8670
+ this._downgradeToAudio(targetCallSession, false);
8671
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8672
+ await new Promise(resolve => setTimeout(resolve, 500));
8673
+ }
8657
8674
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8658
8675
  }
8659
8676
  } catch (e) {
@@ -11816,7 +11833,8 @@ class Room$1 extends Emitter {
11816
11833
  }
11817
11834
 
11818
11835
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
11819
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
11836
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
11837
+ stream && stream.id === streamId);
11820
11838
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
11821
11839
  }
11822
11840
 
@@ -7045,6 +7045,8 @@ class WebRTCClient extends Emitter {
7045
7045
  }
7046
7046
  options.sessionDescriptionHandlerOptions = {
7047
7047
  constraints: options.constraints,
7048
+ hold: true,
7049
+ conference: isConference,
7048
7050
  };
7049
7051
 
7050
7052
  // Send re-INVITE
@@ -7087,6 +7089,8 @@ class WebRTCClient extends Emitter {
7087
7089
  }
7088
7090
  options.sessionDescriptionHandlerOptions = {
7089
7091
  constraints: options.constraints,
7092
+ hold: false,
7093
+ conference: isConference,
7090
7094
  };
7091
7095
 
7092
7096
  // Send re-INVITE
@@ -8416,7 +8420,7 @@ class WebRTCPhone extends Emitter {
8416
8420
  return this.client.onDisconnect();
8417
8421
  }
8418
8422
 
8419
- _downgradeToAudio(callSession ) {
8423
+ _downgradeToAudio(callSession , withMessage = true) {
8420
8424
  const sipSession = this.findSipSession(callSession);
8421
8425
  if (!sipSession) {
8422
8426
  return false;
@@ -8443,7 +8447,9 @@ class WebRTCPhone extends Emitter {
8443
8447
  localStream.removeTrack(videoTrack);
8444
8448
  });
8445
8449
 
8446
- this._sendReinviteMessage(callSession, false);
8450
+ if (withMessage) {
8451
+ this._sendReinviteMessage(callSession, false);
8452
+ }
8447
8453
 
8448
8454
  return true;
8449
8455
  }
@@ -8462,9 +8468,9 @@ class WebRTCPhone extends Emitter {
8462
8468
 
8463
8469
  // Check if a video sender already exists
8464
8470
  let videoSender;
8471
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8465
8472
  if (isConference) {
8466
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
8467
- videoSender = trans ? trans.sender : null;
8473
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
8468
8474
  } else {
8469
8475
  videoSender = pc.getSenders().find(sender => sender.track === null);
8470
8476
  }
@@ -8494,6 +8500,11 @@ class WebRTCPhone extends Emitter {
8494
8500
  videoSender.replaceTrack(videoTrack);
8495
8501
  }
8496
8502
 
8503
+ // Put back last direction (was set to `recvonly` when downgrading)
8504
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
8505
+ videoTransceiver.direction = videoTransceiver.currentDirection;
8506
+ }
8507
+
8497
8508
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
8498
8509
  this._sendReinviteMessage(callSession, true);
8499
8510
 
@@ -8656,6 +8667,12 @@ class WebRTCPhone extends Emitter {
8656
8667
  // We have to downgrade to audio.
8657
8668
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
8658
8669
  const constraints = { audio: false, video: screenshareStopped };
8670
+ if (!conference) {
8671
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
8672
+ this._downgradeToAudio(targetCallSession, false);
8673
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
8674
+ await new Promise(resolve => setTimeout(resolve, 500));
8675
+ }
8659
8676
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
8660
8677
  }
8661
8678
  } catch (e) {
@@ -11818,7 +11835,8 @@ class Room$1 extends Emitter {
11818
11835
  }
11819
11836
 
11820
11837
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
11821
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) => stream.id === streamId);
11838
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream ) =>
11839
+ stream && stream.id === streamId);
11822
11840
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
11823
11841
  }
11824
11842
 
@@ -5802,6 +5802,8 @@ class WebRTCClient extends Emitter {
5802
5802
  }
5803
5803
  options.sessionDescriptionHandlerOptions = {
5804
5804
  constraints: options.constraints,
5805
+ hold: true,
5806
+ conference: isConference,
5805
5807
  };
5806
5808
 
5807
5809
  // Send re-INVITE
@@ -5844,6 +5846,8 @@ class WebRTCClient extends Emitter {
5844
5846
  }
5845
5847
  options.sessionDescriptionHandlerOptions = {
5846
5848
  constraints: options.constraints,
5849
+ hold: false,
5850
+ conference: isConference,
5847
5851
  };
5848
5852
 
5849
5853
  // Send re-INVITE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.37.4",
3
+ "version": "0.37.8",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -290,7 +290,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
290
290
  return this.client.onDisconnect();
291
291
  }
292
292
 
293
- _downgradeToAudio(callSession: ?CallSession) {
293
+ _downgradeToAudio(callSession: ?CallSession, withMessage: boolean = true) {
294
294
  const sipSession = this.findSipSession(callSession);
295
295
  if (!sipSession) {
296
296
  return false;
@@ -317,7 +317,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
317
317
  localStream.removeTrack(videoTrack);
318
318
  });
319
319
 
320
- this._sendReinviteMessage(callSession, false);
320
+ if (withMessage) {
321
+ this._sendReinviteMessage(callSession, false);
322
+ }
321
323
 
322
324
  return true;
323
325
  }
@@ -336,9 +338,9 @@ export default class WebRTCPhone extends Emitter implements Phone {
336
338
 
337
339
  // Check if a video sender already exists
338
340
  let videoSender;
341
+ const videoTransceiver = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
339
342
  if (isConference) {
340
- const trans = pc.getTransceivers().find(transceiver => transceiver.mid === '1');
341
- videoSender = trans ? trans.sender : null;
343
+ videoSender = videoTransceiver ? videoTransceiver.sender : null;
342
344
  } else {
343
345
  videoSender = pc.getSenders().find(sender => sender.track === null);
344
346
  }
@@ -368,6 +370,11 @@ export default class WebRTCPhone extends Emitter implements Phone {
368
370
  videoSender.replaceTrack(videoTrack);
369
371
  }
370
372
 
373
+ // Put back last direction (was set to `recvonly` when downgrading)
374
+ if (videoTransceiver && videoTransceiver.currentDirection !== videoTransceiver.direction) {
375
+ videoTransceiver.direction = videoTransceiver.currentDirection;
376
+ }
377
+
371
378
  this.client.setLocalMediaStream(this.getSipSessionId(sipSession), newStream);
372
379
  this._sendReinviteMessage(callSession, true);
373
380
 
@@ -532,6 +539,12 @@ export default class WebRTCPhone extends Emitter implements Phone {
532
539
  // We have to downgrade to audio.
533
540
  const screenshareStopped = this.currentScreenShare.sender && this.currentScreenShare.hadVideo;
534
541
  const constraints = { audio: false, video: screenshareStopped };
542
+ if (!conference) {
543
+ // We have to remove the video sender to be able to re-upgrade to video in `sendReinvite` below
544
+ this._downgradeToAudio(targetCallSession, false);
545
+ // Wait for the track to be removed, unless the video sender won't have a null track in `_upgradeToVideo`.
546
+ await new Promise(resolve => setTimeout(resolve, 500));
547
+ }
535
548
  reinvited = await this.sendReinvite(targetCallSession, constraints, conference);
536
549
  }
537
550
  } catch (e) {
@@ -813,7 +813,8 @@ class Room extends Emitter {
813
813
  }
814
814
 
815
815
  // Find in all the streams by streamId (used on FF where we can't map by trackId)
816
- const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream: Object) => stream.id === streamId);
816
+ const idx = Object.values(this._unassociatedVideoStreams).findIndex((stream: Object) =>
817
+ stream && stream.id === streamId);
817
818
  return idx === -1 ? null : Object.keys(this._unassociatedVideoStreams)[idx];
818
819
  }
819
820
 
@@ -706,6 +706,8 @@ export default class WebRTCClient extends Emitter {
706
706
  }
707
707
  options.sessionDescriptionHandlerOptions = {
708
708
  constraints: options.constraints,
709
+ hold: true,
710
+ conference: isConference,
709
711
  };
710
712
 
711
713
  // Send re-INVITE
@@ -748,6 +750,8 @@ export default class WebRTCClient extends Emitter {
748
750
  }
749
751
  options.sessionDescriptionHandlerOptions = {
750
752
  constraints: options.constraints,
753
+ hold: false,
754
+ conference: isConference,
751
755
  };
752
756
 
753
757
  // Send re-INVITE