@whereby.com/media 1.11.1 → 1.12.1

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.cjs CHANGED
@@ -3548,6 +3548,7 @@ class P2pRtcManager {
3548
3548
  this._isAudioOnlyMode = false;
3549
3549
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3550
3550
  this._pendingActionsForConnectedPeerConnections = [];
3551
+ this._nodeJsClients = [];
3551
3552
  this._audioTrackOnEnded = () => {
3552
3553
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3553
3554
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3629,9 +3630,6 @@ class P2pRtcManager {
3629
3630
  }
3630
3631
  return this._replaceTrackToPeerConnections(oldTrack, newTrack);
3631
3632
  }
3632
- accept({ clientId, shouldAddLocalVideo }) {
3633
- return this.acceptNewStream({ streamId: clientId, clientId, shouldAddLocalVideo });
3634
- }
3635
3633
  disconnectAll() {
3636
3634
  Object.keys(this.peerConnections).forEach((peerConnectionId) => {
3637
3635
  this.disconnect(peerConnectionId);
@@ -3666,6 +3664,11 @@ class P2pRtcManager {
3666
3664
  setupSocketListeners() {
3667
3665
  this._socketListenerDeregisterFunctions = [
3668
3666
  () => this._clearMediaServersRefresh(),
3667
+ this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3668
+ if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3669
+ this._nodeJsClients.push(data.client.id);
3670
+ }
3671
+ }),
3669
3672
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3670
3673
  if (data.error) {
3671
3674
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3863,7 +3866,7 @@ class P2pRtcManager {
3863
3866
  _transformOutgoingSdp(original) {
3864
3867
  return { type: original.type, sdpU: original.sdp };
3865
3868
  }
3866
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3869
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3867
3870
  if (!peerConnectionId) {
3868
3871
  throw new Error("peerConnectionId is missing");
3869
3872
  }
@@ -3899,13 +3902,13 @@ class P2pRtcManager {
3899
3902
  return entry;
3900
3903
  });
3901
3904
  }
3902
- if (this._features.useOnlyTURN) {
3905
+ if (enforceTurnProtocol || this._features.useOnlyTURN) {
3903
3906
  peerConnectionConfig.iceTransportPolicy = "relay";
3904
3907
  const filter = {
3905
3908
  onlyudp: /^turn:.*transport=udp$/,
3906
3909
  onlytcp: /^turn:.*transport=tcp$/,
3907
3910
  onlytls: /^turns:.*transport=tcp$/,
3908
- }[this._features.useOnlyTURN];
3911
+ }[enforceTurnProtocol || this._features.useOnlyTURN];
3909
3912
  if (filter) {
3910
3913
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3911
3914
  }
@@ -4157,17 +4160,26 @@ class P2pRtcManager {
4157
4160
  }
4158
4161
  _connect(clientId) {
4159
4162
  this.rtcStatsReconnect();
4160
- const shouldAddLocalVideo = true;
4161
4163
  let session = this._getSession(clientId);
4162
- let bandwidth = (session && session.bandwidth) || 0;
4164
+ let initialBandwidth = (session && session.bandwidth) || 0;
4163
4165
  if (session) {
4164
4166
  logger$4.warn("Replacing peer session", clientId);
4165
4167
  this._cleanup(clientId);
4166
4168
  }
4167
4169
  else {
4168
- bandwidth = this._changeBandwidthForAllClients(true);
4170
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4169
4171
  }
4170
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo, true);
4172
+ let enforceTurnProtocol;
4173
+ if (this._nodeJsClients.includes(clientId)) {
4174
+ enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4175
+ }
4176
+ session = this._createP2pSession({
4177
+ clientId,
4178
+ initialBandwidth,
4179
+ shouldAddLocalVideo: true,
4180
+ isOfferer: true,
4181
+ enforceTurnProtocol,
4182
+ });
4171
4183
  this._negotiatePeerConnection(clientId, session);
4172
4184
  return Promise.resolve(session);
4173
4185
  }
@@ -4338,13 +4350,14 @@ class P2pRtcManager {
4338
4350
  });
4339
4351
  return bandwidth;
4340
4352
  }
4341
- _createP2pSession(clientId, initialBandwidth, shouldAddLocalVideo, isOfferer) {
4353
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4342
4354
  const session = this._createSession({
4343
4355
  peerConnectionId: clientId,
4344
4356
  clientId,
4345
4357
  initialBandwidth,
4346
4358
  shouldAddLocalVideo,
4347
4359
  isOfferer,
4360
+ enforceTurnProtocol,
4348
4361
  });
4349
4362
  const pc = session.pc;
4350
4363
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4458,20 +4471,26 @@ class P2pRtcManager {
4458
4471
  };
4459
4472
  return session;
4460
4473
  }
4461
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4474
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4462
4475
  let session = this._getSession(clientId);
4463
4476
  if (session && streamId !== clientId) {
4464
4477
  return session;
4465
4478
  }
4466
- let bandwidth = (session && session.bandwidth) || 0;
4479
+ let initialBandwidth = (session && session.bandwidth) || 0;
4467
4480
  if (session) {
4468
4481
  logger$4.warn("Replacing peer session", clientId);
4469
4482
  this._cleanup(clientId);
4470
4483
  }
4471
4484
  else {
4472
- bandwidth = this._changeBandwidthForAllClients(true);
4485
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4473
4486
  }
4474
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo);
4487
+ session = this._createP2pSession({
4488
+ clientId,
4489
+ initialBandwidth,
4490
+ shouldAddLocalVideo: !!shouldAddLocalVideo,
4491
+ enforceTurnProtocol,
4492
+ isOfferer: false,
4493
+ });
4475
4494
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
4476
4495
  receiverId: clientId,
4477
4496
  });