@whereby.com/media 1.14.2 → 1.16.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.cjs CHANGED
@@ -2722,6 +2722,27 @@ function setCodecPreferenceSDP(sdp, vp9On, redOn) {
2722
2722
  logger$6.error("setCodecPreferenceSDP error:", error);
2723
2723
  }
2724
2724
  }
2725
+ function cleanSdp(sdp) {
2726
+ try {
2727
+ const sdpObject = sdpTransform__namespace.parse(sdp);
2728
+ sdpObject.media.forEach(mediaObject => {
2729
+ const usedPayloads = {};
2730
+ if (mediaObject.payloads)
2731
+ mediaObject.payloads = ("" + mediaObject.payloads).split(' ').filter(p => !usedPayloads[p] && (usedPayloads[p] = true)).join(' ');
2732
+ const usedRtps = {};
2733
+ mediaObject.rtp = mediaObject.rtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtps[p.payload] && (usedRtps[p.payload] = true)));
2734
+ const usedFmtps = {};
2735
+ if (mediaObject.fmtp)
2736
+ mediaObject.fmtp = mediaObject.fmtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedFmtps[p.payload] && (usedFmtps[p.payload] = true)));
2737
+ const usedRtcpFb = {};
2738
+ if (mediaObject.rtcpFb)
2739
+ mediaObject.rtcpFb = mediaObject.rtcpFb.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtcpFb[p.payload + p.type] && (usedRtcpFb[p.payload + p.type] = true)));
2740
+ });
2741
+ return sdpTransform__namespace.write(sdpObject);
2742
+ }
2743
+ catch (_) { }
2744
+ return sdp;
2745
+ }
2725
2746
  function maybeRejectNoH264(sdp) {
2726
2747
  if (browserName$2 !== "safari") {
2727
2748
  return sdp;
@@ -3043,13 +3064,7 @@ class Session {
3043
3064
  });
3044
3065
  }
3045
3066
  handleAnswer(message) {
3046
- if (this.pendingOffer) {
3047
- const pendingOffer = this.pendingOffer;
3048
- delete this.pendingOffer;
3049
- return this.pc.setLocalDescription(pendingOffer).then(() => this.handleAnswer(message));
3050
- }
3051
- let sdp = message.sdp;
3052
- sdp = filterMsidSemantic(sdp);
3067
+ const sdp = filterMsidSemantic(message.sdp);
3053
3068
  const desc = { type: message.type, sdp };
3054
3069
  return this._setRemoteDescription(desc).then(() => {
3055
3070
  return setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
@@ -3503,6 +3518,9 @@ var rtcManagerEvents = {
3503
3518
  SFU_CONNECTION_CLOSED: "sfu_connection_closed",
3504
3519
  COLOCATION_SPEAKER: "colocation_speaker",
3505
3520
  DOMINANT_SPEAKER: "dominant_speaker",
3521
+ PC_SLD_FAILURE: "pc_sld_failure",
3522
+ PC_ON_ANSWER_FAILURE: "pc_on_answer_failure",
3523
+ PC_ON_OFFER_FAILURE: "pc_on_offer_failure",
3506
3524
  };
3507
3525
 
3508
3526
  var _a$2, _b;
@@ -3540,7 +3558,6 @@ class P2pRtcManager {
3540
3558
  this._isAudioOnlyMode = false;
3541
3559
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
3542
3560
  this._pendingActionsForConnectedPeerConnections = [];
3543
- this._nodeJsClients = [];
3544
3561
  this._audioTrackOnEnded = () => {
3545
3562
  rtcStats.sendEvent("audio_ended", { unloading: unloading$1 });
3546
3563
  this._emit(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -3656,11 +3673,6 @@ class P2pRtcManager {
3656
3673
  setupSocketListeners() {
3657
3674
  this._socketListenerDeregisterFunctions = [
3658
3675
  () => this._clearMediaServersRefresh(),
3659
- this._serverSocket.on(PROTOCOL_RESPONSES.NEW_CLIENT, (data) => {
3660
- if (data.client.isDialIn && !this._nodeJsClients.includes(data.client.id)) {
3661
- this._nodeJsClients.push(data.client.id);
3662
- }
3663
- }),
3664
3676
  this._serverSocket.on(PROTOCOL_RESPONSES.MEDIASERVER_CONFIG, (data) => {
3665
3677
  if (data.error) {
3666
3678
  logger$4.warn("FETCH_MEDIASERVER_CONFIG failed:", data.error);
@@ -3688,27 +3700,33 @@ class P2pRtcManager {
3688
3700
  session.addIceCandidate(null);
3689
3701
  }),
3690
3702
  this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
3703
+ var _a, _b;
3691
3704
  const session = this._getSession(data.clientId);
3692
3705
  if (!session) {
3693
3706
  logger$4.warn("No RTCPeerConnection on SDP_OFFER", data);
3694
3707
  return;
3695
3708
  }
3696
3709
  const offer = this._transformIncomingSdp(data.message, session.pc);
3697
- session.handleOffer(offer).then((answer) => {
3710
+ (_b = (_a = session.handleOffer(offer).then((answer) => {
3698
3711
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
3699
3712
  receiverId: data.clientId,
3700
3713
  message: this._transformOutgoingSdp(answer),
3701
3714
  });
3715
+ })).catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3716
+ this._emit(rtcManagerEvents.PC_ON_OFFER_FAILURE, e);
3702
3717
  });
3703
3718
  }),
3704
3719
  this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
3720
+ var _a, _b;
3705
3721
  const session = this._getSession(data.clientId);
3706
3722
  if (!session) {
3707
3723
  logger$4.warn("No RTCPeerConnection on SDP_ANSWER", data);
3708
3724
  return;
3709
3725
  }
3710
3726
  const answer = this._transformIncomingSdp(data.message, session.pc);
3711
- session.handleAnswer(answer);
3727
+ (_b = (_a = session.handleAnswer(answer)) === null || _a === void 0 ? void 0 : _a.catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3728
+ this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3729
+ });
3712
3730
  }),
3713
3731
  this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3714
3732
  if (isSfu || !this._wasScreenSharing)
@@ -3858,7 +3876,7 @@ class P2pRtcManager {
3858
3876
  _transformOutgoingSdp(original) {
3859
3877
  return { type: original.type, sdpU: original.sdp };
3860
3878
  }
3861
- _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, enforceTurnProtocol, }) {
3879
+ _createSession({ clientId, initialBandwidth, isOfferer, peerConnectionId, shouldAddLocalVideo, }) {
3862
3880
  if (!peerConnectionId) {
3863
3881
  throw new Error("peerConnectionId is missing");
3864
3882
  }
@@ -3894,13 +3912,13 @@ class P2pRtcManager {
3894
3912
  return entry;
3895
3913
  });
3896
3914
  }
3897
- if (enforceTurnProtocol || this._features.useOnlyTURN) {
3915
+ if (this._features.useOnlyTURN) {
3898
3916
  peerConnectionConfig.iceTransportPolicy = "relay";
3899
3917
  const filter = {
3900
3918
  onlyudp: /^turn:.*transport=udp$/,
3901
3919
  onlytcp: /^turn:.*transport=tcp$/,
3902
3920
  onlytls: /^turns:.*transport=tcp$/,
3903
- }[enforceTurnProtocol || this._features.useOnlyTURN];
3921
+ }[this._features.useOnlyTURN];
3904
3922
  if (filter) {
3905
3923
  peerConnectionConfig.iceServers = peerConnectionConfig.iceServers.filter((entry) => entry.url && entry.url.match(filter));
3906
3924
  }
@@ -4160,16 +4178,11 @@ class P2pRtcManager {
4160
4178
  else {
4161
4179
  initialBandwidth = this._changeBandwidthForAllClients(true);
4162
4180
  }
4163
- let enforceTurnProtocol;
4164
- if (this._nodeJsClients.includes(clientId)) {
4165
- enforceTurnProtocol = this._features.isNodeSdk ? "onlyudp" : "onlytls";
4166
- }
4167
4181
  session = this._createP2pSession({
4168
4182
  clientId,
4169
4183
  initialBandwidth,
4170
4184
  shouldAddLocalVideo: true,
4171
4185
  isOfferer: true,
4172
- enforceTurnProtocol,
4173
4186
  });
4174
4187
  this._negotiatePeerConnection(clientId, session);
4175
4188
  return Promise.resolve(session);
@@ -4250,7 +4263,7 @@ class P2pRtcManager {
4250
4263
  return;
4251
4264
  }
4252
4265
  session.isOperationPending = true;
4253
- const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn } = this._features;
4266
+ const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
4254
4267
  if (vp9On || av1On || redOn) {
4255
4268
  this._setCodecPreferences(pc, vp9On, av1On, redOn);
4256
4269
  }
@@ -4261,26 +4274,17 @@ class P2pRtcManager {
4261
4274
  if ((vp9On || redOn) && browserName$1 === "firefox") {
4262
4275
  offer.sdp = setCodecPreferenceSDP(offer.sdp, vp9On, redOn);
4263
4276
  }
4264
- this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4265
- receiverId: clientId,
4266
- message: this._transformOutgoingSdp(offer),
4267
- });
4268
- if (browserName$1 === "chrome" &&
4269
- pc.getSenders().filter((sender) => sender.track && sender.track.kind === "video").length >= 2) {
4270
- session.pendingOffer = offer;
4271
- return;
4272
- }
4277
+ if (cleanSdpOn)
4278
+ offer.sdp = cleanSdp(offer.sdp);
4273
4279
  pc.setLocalDescription(offer).catch((e) => {
4274
4280
  logger$4.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4275
- if (this._features.reverseOfferOnFailure) {
4276
- if (!this._lastReverseDirectionAttemptByClientId)
4277
- this._lastReverseDirectionAttemptByClientId = {};
4278
- if (!this._lastReverseDirectionAttemptByClientId[clientId] ||
4279
- this._lastReverseDirectionAttemptByClientId[clientId] < Date.now() - 10000) {
4280
- this.acceptNewStream({ clientId, streamId: clientId, shouldAddLocalVideo: true });
4281
- this._lastReverseDirectionAttemptByClientId[clientId] = Date.now();
4282
- }
4283
- }
4281
+ this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4282
+ throw e;
4283
+ }).then(() => {
4284
+ this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4285
+ receiverId: clientId,
4286
+ message: this._transformOutgoingSdp(offer),
4287
+ });
4284
4288
  });
4285
4289
  })
4286
4290
  .catch((e) => {
@@ -4341,14 +4345,13 @@ class P2pRtcManager {
4341
4345
  });
4342
4346
  return bandwidth;
4343
4347
  }
4344
- _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, enforceTurnProtocol, }) {
4348
+ _createP2pSession({ clientId, initialBandwidth, shouldAddLocalVideo = false, isOfferer = false, }) {
4345
4349
  const session = this._createSession({
4346
4350
  peerConnectionId: clientId,
4347
4351
  clientId,
4348
4352
  initialBandwidth,
4349
4353
  shouldAddLocalVideo,
4350
4354
  isOfferer,
4351
- enforceTurnProtocol,
4352
4355
  });
4353
4356
  const pc = session.pc;
4354
4357
  if (this._features.increaseIncomingMediaBufferOn) {
@@ -4462,7 +4465,7 @@ class P2pRtcManager {
4462
4465
  };
4463
4466
  return session;
4464
4467
  }
4465
- acceptNewStream({ streamId, clientId, shouldAddLocalVideo, enforceTurnProtocol, }) {
4468
+ acceptNewStream({ streamId, clientId, shouldAddLocalVideo, }) {
4466
4469
  let session = this._getSession(clientId);
4467
4470
  if (session && streamId !== clientId) {
4468
4471
  return session;
@@ -4479,7 +4482,6 @@ class P2pRtcManager {
4479
4482
  clientId,
4480
4483
  initialBandwidth,
4481
4484
  shouldAddLocalVideo: !!shouldAddLocalVideo,
4482
- enforceTurnProtocol,
4483
4485
  isOfferer: false,
4484
4486
  });
4485
4487
  this._emitServerEvent(RELAY_MESSAGES.READY_TO_RECEIVE_OFFER, {
@@ -6929,6 +6931,7 @@ exports.captureCommonSsrcMetrics = captureCommonSsrcMetrics;
6929
6931
  exports.captureSsrcInfo = captureSsrcInfo;
6930
6932
  exports.captureVideoSsrcMetrics = captureVideoSsrcMetrics;
6931
6933
  exports.changeMediaDirection = changeMediaDirection;
6934
+ exports.cleanSdp = cleanSdp;
6932
6935
  exports.compareLocalDevices = compareLocalDevices;
6933
6936
  exports.createACFCalculator = createACFCalculator;
6934
6937
  exports.createMicAnalyser = createMicAnalyser;