@whereby.com/media 1.14.1 → 1.15.0

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.
package/dist/index.mjs CHANGED
@@ -1400,10 +1400,6 @@ class VegaConnection extends EventEmitter {
1400
1400
  var _a;
1401
1401
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
1402
1402
  }
1403
- isConnected() {
1404
- var _a, _b;
1405
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN || ((_b = this.socket) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.CONNECTING;
1406
- }
1407
1403
  _onOpen() {
1408
1404
  logger$9.info("Connected");
1409
1405
  this.emit("open");
@@ -3523,7 +3519,6 @@ class P2pRtcManager {
3523
3519
  this._isAudioOnlyMode = false;
3524
3520
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3525
3521
  this._pendingActionsForConnectedPeerConnections = [];
3526
- this._nodeJsClients = [];
3527
3522
  this._audioTrackOnEnded = () => {
3528
3523
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3529
3524
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3639,11 +3634,6 @@ class P2pRtcManager {
3639
3634
  setupSocketListeners() {
3640
3635
  this._socketListenerDeregisterFunctions = [
3641
3636
  () => this._clearMediaServersRefresh(),
3642
- this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3643
- if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3644
- this._nodeJsClients.push(data.client.id);
3645
- }
3646
- }),
3647
3637
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3648
3638
  if (data.error) {
3649
3639
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3841,7 +3831,7 @@ class P2pRtcManager {
3841
3831
  _transformOutgoingSdp(original) {
3842
3832
  return { type: original.type, sdpU: original.sdp };
3843
3833
  }
3844
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3834
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3845
3835
  if (!peerConnectionId) {
3846
3836
  throw new Error("peerConnectionId is missing");
3847
3837
  }
@@ -3877,13 +3867,13 @@ class P2pRtcManager {
3877
3867
  return entry;
3878
3868
  });
3879
3869
  }
3880
- if (enforceTurnProtocol || this._features.useOnlyTURN) {
3870
+ if (this._features.useOnlyTURN) {
3881
3871
  peerConnectionConfig.iceTransportPolicy = "relay";
3882
3872
  const filter = {
3883
3873
  onlyudp: /^turn:.*transport=udp$/,
3884
3874
  onlytcp: /^turn:.*transport=tcp$/,
3885
3875
  onlytls: /^turns:.*transport=tcp$/,
3886
- }[enforceTurnProtocol || this._features.useOnlyTURN];
3876
+ }[this._features.useOnlyTURN];
3887
3877
  if (filter) {
3888
3878
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3889
3879
  }
@@ -4143,16 +4133,11 @@ class P2pRtcManager {
4143
4133
  else {
4144
4134
  initialBandwidth = this._changeBandwidthForAllClients(true);
4145
4135
  }
4146
- let enforceTurnProtocol;
4147
- if (this._nodeJsClients.includes(clientId)) {
4148
- enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4149
- }
4150
4136
  session = this._createP2pSession({
4151
4137
  clientId,
4152
4138
  initialBandwidth,
4153
4139
  shouldAddLocalVideo: true,
4154
4140
  isOfferer: true,
4155
- enforceTurnProtocol,
4156
4141
  });
4157
4142
  this._negotiatePeerConnection(clientId, session);
4158
4143
  return Promise.resolve(session);
@@ -4324,14 +4309,13 @@ class P2pRtcManager {
4324
4309
  });
4325
4310
  return bandwidth;
4326
4311
  }
4327
- _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4312
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, }) {
4328
4313
  const session = this._createSession({
4329
4314
  peerConnectionId: clientId,
4330
4315
  clientId,
4331
4316
  initialBandwidth,
4332
4317
  shouldAddLocalVideo,
4333
4318
  isOfferer,
4334
- enforceTurnProtocol,
4335
4319
  });
4336
4320
  const pc = session.pc;
4337
4321
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4445,7 +4429,7 @@ class P2pRtcManager {
4445
4429
  };
4446
4430
  return session;
4447
4431
  }
4448
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4432
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4449
4433
  let session = this._getSession(clientId);
4450
4434
  if (session && streamId !== clientId) {
4451
4435
  return session;
@@ -4462,7 +4446,6 @@ class P2pRtcManager {
4462
4446
  clientId,
4463
4447
  initialBandwidth,
4464
4448
  shouldAddLocalVideo: !!shouldAddLocalVideo,
4465
- enforceTurnProtocol,
4466
4449
  isOfferer: false,
4467
4450
  });
4468
4451
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
@@ -5059,6 +5042,7 @@ class VegaRtcManager {
5059
5042
  this._socketListenerDeregisterFunctions = [];
5060
5043
  this._reconnect = true;
5061
5044
  this._reconnectTimeOut = null;
5045
+ this._hasVegaConnection = false;
5062
5046
  this._qualityMonitor = new VegaMediaQualityMonitor();
5063
5047
  this._qualityMonitor.on(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, (payload) => {
5064
5048
  this._emitToPWA(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, payload);
@@ -5093,7 +5077,7 @@ class VegaRtcManager {
5093
5077
  }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5094
5078
  if (this._screenVideoTrack)
5095
5079
  this._emitScreenshareStarted();
5096
- if (this._features.sfuReconnectV2On && !this._vegaConnection.isConnected() && this._reconnect) {
5080
+ if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
5097
5081
  this._connect();
5098
5082
  }
5099
5083
  }));
@@ -5107,6 +5091,8 @@ class VegaRtcManager {
5107
5091
  }
5108
5092
  _connect() {
5109
5093
  if (this._features.sfuReconnectV2On) {
5094
+ if (this._hasVegaConnection)
5095
+ return;
5110
5096
  if (!this._serverSocket.isConnected()) {
5111
5097
  const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5112
5098
  if (!reconnectThresholdInMs)
@@ -5124,6 +5110,7 @@ class VegaRtcManager {
5124
5110
  const queryString = searchParams.toString();
5125
5111
  const wsUrl = `wss://${host}?${queryString}`;
5126
5112
  this._vegaConnection = new VegaConnection(wsUrl);
5113
+ this._hasVegaConnection = true;
5127
5114
  this._vegaConnection.on("open", () => this._join());
5128
5115
  this._vegaConnection.on("close", () => this._onClose());
5129
5116
  this._vegaConnection.on("message", (message) => this._onMessage(message));
@@ -5131,6 +5118,7 @@ class VegaRtcManager {
5131
5118
  _onClose() {
5132
5119
  var _a, _b;
5133
5120
  logger$1.info("_onClose()");
5121
+ this._hasVegaConnection = false;
5134
5122
  (_a = this._sendTransport) === null || _a === void 0 ? void 0 : _a.close();
5135
5123
  (_b = this._receiveTransport) === null || _b === void 0 ? void 0 : _b.close();
5136
5124
  this._sendTransport = null;
@@ -5827,7 +5815,7 @@ class VegaRtcManager {
5827
5815
  if (!videoTrack.effectTrack) {
5828
5816
  this._monitorVideoTrack(videoTrack);
5829
5817
  }
5830
- const beforeEffectTrack = beforeEffectTracks.find(t => t.kind === "video");
5818
+ const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
5831
5819
  if (beforeEffectTrack) {
5832
5820
  this._monitorVideoTrack(beforeEffectTrack);
5833
5821
  }
@@ -5838,7 +5826,7 @@ class VegaRtcManager {
5838
5826
  if (!audioTrack.effectTrack) {
5839
5827
  this._monitorAudioTrack(audioTrack);
5840
5828
  }
5841
- const beforeEffectTrack = beforeEffectTracks.find(t => t.kind === "audio");
5829
+ const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
5842
5830
  if (beforeEffectTrack) {
5843
5831
  this._monitorAudioTrack(beforeEffectTrack);
5844
5832
  }
@@ -5909,7 +5897,9 @@ class VegaRtcManager {
5909
5897
  }
5910
5898
  if (!enable) {
5911
5899
  clearTimeout(this._stopCameraTimeout);
5912
- const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended" ? 0 : 5000;
5900
+ const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended"
5901
+ ? 0
5902
+ : 5000;
5913
5903
  this._stopCameraTimeout = setTimeout(() => {
5914
5904
  localStream.getVideoTracks().forEach((track) => {
5915
5905
  if (track.enabled === false) {
@@ -1400,10 +1400,6 @@ class VegaConnection extends EventEmitter {
1400
1400
  var _a;
1401
1401
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
1402
1402
  }
1403
- isConnected() {
1404
- var _a, _b;
1405
- return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN || ((_b = this.socket) === null || _b === void 0 ? void 0 : _b.readyState) === WebSocket.CONNECTING;
1406
- }
1407
1403
  _onOpen() {
1408
1404
  logger$9.info("Connected");
1409
1405
  this.emit("open");
@@ -3523,7 +3519,6 @@ class P2pRtcManager {
3523
3519
  this._isAudioOnlyMode = false;
3524
3520
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3525
3521
  this._pendingActionsForConnectedPeerConnections = [];
3526
- this._nodeJsClients = [];
3527
3522
  this._audioTrackOnEnded = () => {
3528
3523
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3529
3524
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3639,11 +3634,6 @@ class P2pRtcManager {
3639
3634
  setupSocketListeners() {
3640
3635
  this._socketListenerDeregisterFunctions = [
3641
3636
  () => this._clearMediaServersRefresh(),
3642
- this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3643
- if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3644
- this._nodeJsClients.push(data.client.id);
3645
- }
3646
- }),
3647
3637
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3648
3638
  if (data.error) {
3649
3639
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3841,7 +3831,7 @@ class P2pRtcManager {
3841
3831
  _transformOutgoingSdp(original) {
3842
3832
  return { type: original.type, sdpU: original.sdp };
3843
3833
  }
3844
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3834
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3845
3835
  if (!peerConnectionId) {
3846
3836
  throw new Error("peerConnectionId is missing");
3847
3837
  }
@@ -3877,13 +3867,13 @@ class P2pRtcManager {
3877
3867
  return entry;
3878
3868
  });
3879
3869
  }
3880
- if (enforceTurnProtocol || this._features.useOnlyTURN) {
3870
+ if (this._features.useOnlyTURN) {
3881
3871
  peerConnectionConfig.iceTransportPolicy = "relay";
3882
3872
  const filter = {
3883
3873
  onlyudp: /^turn:.*transport=udp$/,
3884
3874
  onlytcp: /^turn:.*transport=tcp$/,
3885
3875
  onlytls: /^turns:.*transport=tcp$/,
3886
- }[enforceTurnProtocol || this._features.useOnlyTURN];
3876
+ }[this._features.useOnlyTURN];
3887
3877
  if (filter) {
3888
3878
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3889
3879
  }
@@ -4143,16 +4133,11 @@ class P2pRtcManager {
4143
4133
  else {
4144
4134
  initialBandwidth = this._changeBandwidthForAllClients(true);
4145
4135
  }
4146
- let enforceTurnProtocol;
4147
- if (this._nodeJsClients.includes(clientId)) {
4148
- enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4149
- }
4150
4136
  session = this._createP2pSession({
4151
4137
  clientId,
4152
4138
  initialBandwidth,
4153
4139
  shouldAddLocalVideo: true,
4154
4140
  isOfferer: true,
4155
- enforceTurnProtocol,
4156
4141
  });
4157
4142
  this._negotiatePeerConnection(clientId, session);
4158
4143
  return Promise.resolve(session);
@@ -4324,14 +4309,13 @@ class P2pRtcManager {
4324
4309
  });
4325
4310
  return bandwidth;
4326
4311
  }
4327
- _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4312
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, }) {
4328
4313
  const session = this._createSession({
4329
4314
  peerConnectionId: clientId,
4330
4315
  clientId,
4331
4316
  initialBandwidth,
4332
4317
  shouldAddLocalVideo,
4333
4318
  isOfferer,
4334
- enforceTurnProtocol,
4335
4319
  });
4336
4320
  const pc = session.pc;
4337
4321
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4445,7 +4429,7 @@ class P2pRtcManager {
4445
4429
  };
4446
4430
  return session;
4447
4431
  }
4448
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4432
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4449
4433
  let session = this._getSession(clientId);
4450
4434
  if (session && streamId !== clientId) {
4451
4435
  return session;
@@ -4462,7 +4446,6 @@ class P2pRtcManager {
4462
4446
  clientId,
4463
4447
  initialBandwidth,
4464
4448
  shouldAddLocalVideo: !!shouldAddLocalVideo,
4465
- enforceTurnProtocol,
4466
4449
  isOfferer: false,
4467
4450
  });
4468
4451
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
@@ -5059,6 +5042,7 @@ class VegaRtcManager {
5059
5042
  this._socketListenerDeregisterFunctions = [];
5060
5043
  this._reconnect = true;
5061
5044
  this._reconnectTimeOut = null;
5045
+ this._hasVegaConnection = false;
5062
5046
  this._qualityMonitor = new VegaMediaQualityMonitor();
5063
5047
  this._qualityMonitor.on(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, (payload) => {
5064
5048
  this._emitToPWA(PROTOCOL_EVENTS.MEDIA_QUALITY_CHANGED, payload);
@@ -5093,7 +5077,7 @@ class VegaRtcManager {
5093
5077
  }), this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, () => {
5094
5078
  if (this._screenVideoTrack)
5095
5079
  this._emitScreenshareStarted();
5096
- if (this._features.sfuReconnectV2On && !this._vegaConnection.isConnected() && this._reconnect) {
5080
+ if (this._features.sfuReconnectV2On && !this._hasVegaConnection && this._reconnect) {
5097
5081
  this._connect();
5098
5082
  }
5099
5083
  }));
@@ -5107,6 +5091,8 @@ class VegaRtcManager {
5107
5091
  }
5108
5092
  _connect() {
5109
5093
  if (this._features.sfuReconnectV2On) {
5094
+ if (this._hasVegaConnection)
5095
+ return;
5110
5096
  if (!this._serverSocket.isConnected()) {
5111
5097
  const reconnectThresholdInMs = this._serverSocket.getReconnectThreshold();
5112
5098
  if (!reconnectThresholdInMs)
@@ -5124,6 +5110,7 @@ class VegaRtcManager {
5124
5110
  const queryString = searchParams.toString();
5125
5111
  const wsUrl = `wss://${host}?${queryString}`;
5126
5112
  this._vegaConnection = new VegaConnection(wsUrl);
5113
+ this._hasVegaConnection = true;
5127
5114
  this._vegaConnection.on("open", () => this._join());
5128
5115
  this._vegaConnection.on("close", () => this._onClose());
5129
5116
  this._vegaConnection.on("message", (message) => this._onMessage(message));
@@ -5131,6 +5118,7 @@ class VegaRtcManager {
5131
5118
  _onClose() {
5132
5119
  var _a, _b;
5133
5120
  logger$1.info("_onClose()");
5121
+ this._hasVegaConnection = false;
5134
5122
  (_a = this._sendTransport) === null || _a === void 0 ? void 0 : _a.close();
5135
5123
  (_b = this._receiveTransport) === null || _b === void 0 ? void 0 : _b.close();
5136
5124
  this._sendTransport = null;
@@ -5827,7 +5815,7 @@ class VegaRtcManager {
5827
5815
  if (!videoTrack.effectTrack) {
5828
5816
  this._monitorVideoTrack(videoTrack);
5829
5817
  }
5830
- const beforeEffectTrack = beforeEffectTracks.find(t => t.kind === "video");
5818
+ const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "video");
5831
5819
  if (beforeEffectTrack) {
5832
5820
  this._monitorVideoTrack(beforeEffectTrack);
5833
5821
  }
@@ -5838,7 +5826,7 @@ class VegaRtcManager {
5838
5826
  if (!audioTrack.effectTrack) {
5839
5827
  this._monitorAudioTrack(audioTrack);
5840
5828
  }
5841
- const beforeEffectTrack = beforeEffectTracks.find(t => t.kind === "audio");
5829
+ const beforeEffectTrack = beforeEffectTracks.find((t) => t.kind === "audio");
5842
5830
  if (beforeEffectTrack) {
5843
5831
  this._monitorAudioTrack(beforeEffectTrack);
5844
5832
  }
@@ -5909,7 +5897,9 @@ class VegaRtcManager {
5909
5897
  }
5910
5898
  if (!enable) {
5911
5899
  clearTimeout(this._stopCameraTimeout);
5912
- const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended" ? 0 : 5000;
5900
+ const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended"
5901
+ ? 0
5902
+ : 5000;
5913
5903
  this._stopCameraTimeout = setTimeout(() => {
5914
5904
  localStream.getVideoTracks().forEach((track) => {
5915
5905
  if (track.enabled === false) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@whereby.com/media",
3
3
  "description": "Media library for Whereby",
4
- "version": "1.14.1",
4
+ "version": "1.15.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {