@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.mjs CHANGED
@@ -3527,6 +3527,7 @@ class P2pRtcManager {
3527
3527
  this._isAudioOnlyMode = false;
3528
3528
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3529
3529
  this._pendingActionsForConnectedPeerConnections = [];
3530
+ this._nodeJsClients = [];
3530
3531
  this._audioTrackOnEnded = () => {
3531
3532
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3532
3533
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3608,9 +3609,6 @@ class P2pRtcManager {
3608
3609
  }
3609
3610
  return this._replaceTrackToPeerConnections(oldTrack, newTrack);
3610
3611
  }
3611
- accept({ clientId, shouldAddLocalVideo }) {
3612
- return this.acceptNewStream({ streamId: clientId, clientId, shouldAddLocalVideo });
3613
- }
3614
3612
  disconnectAll() {
3615
3613
  Object.keys(this.peerConnections).forEach((peerConnectionId) => {
3616
3614
  this.disconnect(peerConnectionId);
@@ -3645,6 +3643,11 @@ class P2pRtcManager {
3645
3643
  setupSocketListeners() {
3646
3644
  this._socketListenerDeregisterFunctions = [
3647
3645
  () => this._clearMediaServersRefresh(),
3646
+ this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3647
+ if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3648
+ this._nodeJsClients.push(data.client.id);
3649
+ }
3650
+ }),
3648
3651
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3649
3652
  if (data.error) {
3650
3653
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3842,7 +3845,7 @@ class P2pRtcManager {
3842
3845
  _transformOutgoingSdp(original) {
3843
3846
  return { type: original.type, sdpU: original.sdp };
3844
3847
  }
3845
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3848
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3846
3849
  if (!peerConnectionId) {
3847
3850
  throw new Error("peerConnectionId is missing");
3848
3851
  }
@@ -3878,13 +3881,13 @@ class P2pRtcManager {
3878
3881
  return entry;
3879
3882
  });
3880
3883
  }
3881
- if (this._features.useOnlyTURN) {
3884
+ if (enforceTurnProtocol || this._features.useOnlyTURN) {
3882
3885
  peerConnectionConfig.iceTransportPolicy = "relay";
3883
3886
  const filter = {
3884
3887
  onlyudp: /^turn:.*transport=udp$/,
3885
3888
  onlytcp: /^turn:.*transport=tcp$/,
3886
3889
  onlytls: /^turns:.*transport=tcp$/,
3887
- }[this._features.useOnlyTURN];
3890
+ }[enforceTurnProtocol || this._features.useOnlyTURN];
3888
3891
  if (filter) {
3889
3892
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3890
3893
  }
@@ -4136,17 +4139,26 @@ class P2pRtcManager {
4136
4139
  }
4137
4140
  _connect(clientId) {
4138
4141
  this.rtcStatsReconnect();
4139
- const shouldAddLocalVideo = true;
4140
4142
  let session = this._getSession(clientId);
4141
- let bandwidth = (session && session.bandwidth) || 0;
4143
+ let initialBandwidth = (session && session.bandwidth) || 0;
4142
4144
  if (session) {
4143
4145
  logger$4.warn("Replacing peer session", clientId);
4144
4146
  this._cleanup(clientId);
4145
4147
  }
4146
4148
  else {
4147
- bandwidth = this._changeBandwidthForAllClients(true);
4149
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4148
4150
  }
4149
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo, true);
4151
+ let enforceTurnProtocol;
4152
+ if (this._nodeJsClients.includes(clientId)) {
4153
+ enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4154
+ }
4155
+ session = this._createP2pSession({
4156
+ clientId,
4157
+ initialBandwidth,
4158
+ shouldAddLocalVideo: true,
4159
+ isOfferer: true,
4160
+ enforceTurnProtocol,
4161
+ });
4150
4162
  this._negotiatePeerConnection(clientId, session);
4151
4163
  return Promise.resolve(session);
4152
4164
  }
@@ -4317,13 +4329,14 @@ class P2pRtcManager {
4317
4329
  });
4318
4330
  return bandwidth;
4319
4331
  }
4320
- _createP2pSession(clientId, initialBandwidth, shouldAddLocalVideo, isOfferer) {
4332
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4321
4333
  const session = this._createSession({
4322
4334
  peerConnectionId: clientId,
4323
4335
  clientId,
4324
4336
  initialBandwidth,
4325
4337
  shouldAddLocalVideo,
4326
4338
  isOfferer,
4339
+ enforceTurnProtocol,
4327
4340
  });
4328
4341
  const pc = session.pc;
4329
4342
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4437,20 +4450,26 @@ class P2pRtcManager {
4437
4450
  };
4438
4451
  return session;
4439
4452
  }
4440
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4453
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4441
4454
  let session = this._getSession(clientId);
4442
4455
  if (session && streamId !== clientId) {
4443
4456
  return session;
4444
4457
  }
4445
- let bandwidth = (session && session.bandwidth) || 0;
4458
+ let initialBandwidth = (session && session.bandwidth) || 0;
4446
4459
  if (session) {
4447
4460
  logger$4.warn("Replacing peer session", clientId);
4448
4461
  this._cleanup(clientId);
4449
4462
  }
4450
4463
  else {
4451
- bandwidth = this._changeBandwidthForAllClients(true);
4464
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4452
4465
  }
4453
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo);
4466
+ session = this._createP2pSession({
4467
+ clientId,
4468
+ initialBandwidth,
4469
+ shouldAddLocalVideo: !!shouldAddLocalVideo,
4470
+ enforceTurnProtocol,
4471
+ isOfferer: false,
4472
+ });
4454
4473
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
4455
4474
  receiverId: clientId,
4456
4475
  });
@@ -3527,6 +3527,7 @@ class P2pRtcManager {
3527
3527
  this._isAudioOnlyMode = false;
3528
3528
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3529
3529
  this._pendingActionsForConnectedPeerConnections = [];
3530
+ this._nodeJsClients = [];
3530
3531
  this._audioTrackOnEnded = () => {
3531
3532
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3532
3533
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3608,9 +3609,6 @@ class P2pRtcManager {
3608
3609
  }
3609
3610
  return this._replaceTrackToPeerConnections(oldTrack, newTrack);
3610
3611
  }
3611
- accept({ clientId, shouldAddLocalVideo }) {
3612
- return this.acceptNewStream({ streamId: clientId, clientId, shouldAddLocalVideo });
3613
- }
3614
3612
  disconnectAll() {
3615
3613
  Object.keys(this.peerConnections).forEach((peerConnectionId) => {
3616
3614
  this.disconnect(peerConnectionId);
@@ -3645,6 +3643,11 @@ class P2pRtcManager {
3645
3643
  setupSocketListeners() {
3646
3644
  this._socketListenerDeregisterFunctions = [
3647
3645
  () => this._clearMediaServersRefresh(),
3646
+ this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3647
+ if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3648
+ this._nodeJsClients.push(data.client.id);
3649
+ }
3650
+ }),
3648
3651
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3649
3652
  if (data.error) {
3650
3653
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3842,7 +3845,7 @@ class P2pRtcManager {
3842
3845
  _transformOutgoingSdp(original) {
3843
3846
  return { type: original.type, sdpU: original.sdp };
3844
3847
  }
3845
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3848
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3846
3849
  if (!peerConnectionId) {
3847
3850
  throw new Error("peerConnectionId is missing");
3848
3851
  }
@@ -3878,13 +3881,13 @@ class P2pRtcManager {
3878
3881
  return entry;
3879
3882
  });
3880
3883
  }
3881
- if (this._features.useOnlyTURN) {
3884
+ if (enforceTurnProtocol || this._features.useOnlyTURN) {
3882
3885
  peerConnectionConfig.iceTransportPolicy = "relay";
3883
3886
  const filter = {
3884
3887
  onlyudp: /^turn:.*transport=udp$/,
3885
3888
  onlytcp: /^turn:.*transport=tcp$/,
3886
3889
  onlytls: /^turns:.*transport=tcp$/,
3887
- }[this._features.useOnlyTURN];
3890
+ }[enforceTurnProtocol || this._features.useOnlyTURN];
3888
3891
  if (filter) {
3889
3892
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3890
3893
  }
@@ -4136,17 +4139,26 @@ class P2pRtcManager {
4136
4139
  }
4137
4140
  _connect(clientId) {
4138
4141
  this.rtcStatsReconnect();
4139
- const shouldAddLocalVideo = true;
4140
4142
  let session = this._getSession(clientId);
4141
- let bandwidth = (session && session.bandwidth) || 0;
4143
+ let initialBandwidth = (session && session.bandwidth) || 0;
4142
4144
  if (session) {
4143
4145
  logger$4.warn("Replacing peer session", clientId);
4144
4146
  this._cleanup(clientId);
4145
4147
  }
4146
4148
  else {
4147
- bandwidth = this._changeBandwidthForAllClients(true);
4149
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4148
4150
  }
4149
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo, true);
4151
+ let enforceTurnProtocol;
4152
+ if (this._nodeJsClients.includes(clientId)) {
4153
+ enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4154
+ }
4155
+ session = this._createP2pSession({
4156
+ clientId,
4157
+ initialBandwidth,
4158
+ shouldAddLocalVideo: true,
4159
+ isOfferer: true,
4160
+ enforceTurnProtocol,
4161
+ });
4150
4162
  this._negotiatePeerConnection(clientId, session);
4151
4163
  return Promise.resolve(session);
4152
4164
  }
@@ -4317,13 +4329,14 @@ class P2pRtcManager {
4317
4329
  });
4318
4330
  return bandwidth;
4319
4331
  }
4320
- _createP2pSession(clientId, initialBandwidth, shouldAddLocalVideo, isOfferer) {
4332
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4321
4333
  const session = this._createSession({
4322
4334
  peerConnectionId: clientId,
4323
4335
  clientId,
4324
4336
  initialBandwidth,
4325
4337
  shouldAddLocalVideo,
4326
4338
  isOfferer,
4339
+ enforceTurnProtocol,
4327
4340
  });
4328
4341
  const pc = session.pc;
4329
4342
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4437,20 +4450,26 @@ class P2pRtcManager {
4437
4450
  };
4438
4451
  return session;
4439
4452
  }
4440
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4453
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4441
4454
  let session = this._getSession(clientId);
4442
4455
  if (session && streamId !== clientId) {
4443
4456
  return session;
4444
4457
  }
4445
- let bandwidth = (session && session.bandwidth) || 0;
4458
+ let initialBandwidth = (session && session.bandwidth) || 0;
4446
4459
  if (session) {
4447
4460
  logger$4.warn("Replacing peer session", clientId);
4448
4461
  this._cleanup(clientId);
4449
4462
  }
4450
4463
  else {
4451
- bandwidth = this._changeBandwidthForAllClients(true);
4464
+ initialBandwidth = this._changeBandwidthForAllClients(true);
4452
4465
  }
4453
- session = this._createP2pSession(clientId, bandwidth, shouldAddLocalVideo);
4466
+ session = this._createP2pSession({
4467
+ clientId,
4468
+ initialBandwidth,
4469
+ shouldAddLocalVideo: !!shouldAddLocalVideo,
4470
+ enforceTurnProtocol,
4471
+ isOfferer: false,
4472
+ });
4454
4473
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
4455
4474
  receiverId: clientId,
4456
4475
  });
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.11.1",
4
+ "version": "1.12.1",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {
@@ -12,6 +12,7 @@
12
12
  "url": "https://github.com/whereby/sdk/issues"
13
13
  },
14
14
  "scripts": {
15
+ "clean": "rimraf dist node_modules .turbo",
15
16
  "build": "rimraf dist && rollup -c rollup.config.js",
16
17
  "test": "npm run test:lint && npm run test:unit",
17
18
  "test:unit": "jest",