@whereby.com/media 1.15.0 → 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;
@@ -3682,27 +3700,33 @@ class P2pRtcManager {
3682
3700
  session.addIceCandidate(null);
3683
3701
  }),
3684
3702
  this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
3703
+ var _a, _b;
3685
3704
  const session = this._getSession(data.clientId);
3686
3705
  if (!session) {
3687
3706
  logger$4.warn("No RTCPeerConnection on SDP_OFFER", data);
3688
3707
  return;
3689
3708
  }
3690
3709
  const offer = this._transformIncomingSdp(data.message, session.pc);
3691
- session.handleOffer(offer).then((answer) => {
3710
+ (_b = (_a = session.handleOffer(offer).then((answer) => {
3692
3711
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
3693
3712
  receiverId: data.clientId,
3694
3713
  message: this._transformOutgoingSdp(answer),
3695
3714
  });
3715
+ })).catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3716
+ this._emit(rtcManagerEvents.PC_ON_OFFER_FAILURE, e);
3696
3717
  });
3697
3718
  }),
3698
3719
  this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
3720
+ var _a, _b;
3699
3721
  const session = this._getSession(data.clientId);
3700
3722
  if (!session) {
3701
3723
  logger$4.warn("No RTCPeerConnection on SDP_ANSWER", data);
3702
3724
  return;
3703
3725
  }
3704
3726
  const answer = this._transformIncomingSdp(data.message, session.pc);
3705
- 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
+ });
3706
3730
  }),
3707
3731
  this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3708
3732
  if (isSfu || !this._wasScreenSharing)
@@ -4239,7 +4263,7 @@ class P2pRtcManager {
4239
4263
  return;
4240
4264
  }
4241
4265
  session.isOperationPending = true;
4242
- const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn } = this._features;
4266
+ const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
4243
4267
  if (vp9On || av1On || redOn) {
4244
4268
  this._setCodecPreferences(pc, vp9On, av1On, redOn);
4245
4269
  }
@@ -4250,26 +4274,17 @@ class P2pRtcManager {
4250
4274
  if ((vp9On || redOn) && browserName$1 === "firefox") {
4251
4275
  offer.sdp = setCodecPreferenceSDP(offer.sdp, vp9On, redOn);
4252
4276
  }
4253
- this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4254
- receiverId: clientId,
4255
- message: this._transformOutgoingSdp(offer),
4256
- });
4257
- if (browserName$1 === "chrome" &&
4258
- pc.getSenders().filter((sender) => sender.track && sender.track.kind === "video").length >= 2) {
4259
- session.pendingOffer = offer;
4260
- return;
4261
- }
4277
+ if (cleanSdpOn)
4278
+ offer.sdp = cleanSdp(offer.sdp);
4262
4279
  pc.setLocalDescription(offer).catch((e) => {
4263
4280
  logger$4.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4264
- if (this._features.reverseOfferOnFailure) {
4265
- if (!this._lastReverseDirectionAttemptByClientId)
4266
- this._lastReverseDirectionAttemptByClientId = {};
4267
- if (!this._lastReverseDirectionAttemptByClientId[clientId] ||
4268
- this._lastReverseDirectionAttemptByClientId[clientId] < Date.now() - 10000) {
4269
- this.acceptNewStream({ clientId, streamId: clientId, shouldAddLocalVideo: true });
4270
- this._lastReverseDirectionAttemptByClientId[clientId] = Date.now();
4271
- }
4272
- }
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
+ });
4273
4288
  });
4274
4289
  })
4275
4290
  .catch((e) => {
@@ -6916,6 +6931,7 @@ exports.captureCommonSsrcMetrics = captureCommonSsrcMetrics;
6916
6931
  exports.captureSsrcInfo = captureSsrcInfo;
6917
6932
  exports.captureVideoSsrcMetrics = captureVideoSsrcMetrics;
6918
6933
  exports.changeMediaDirection = changeMediaDirection;
6934
+ exports.cleanSdp = cleanSdp;
6919
6935
  exports.compareLocalDevices = compareLocalDevices;
6920
6936
  exports.createACFCalculator = createACFCalculator;
6921
6937
  exports.createMicAnalyser = createMicAnalyser;
package/dist/index.d.cts CHANGED
@@ -410,7 +410,6 @@ declare class P2pRtcManager implements RtcManager {
410
410
  ipv6HostCandidateTeredoSeen: any;
411
411
  ipv6HostCandidate6to4Seen: any;
412
412
  mdnsHostCandidateSeen: any;
413
- _lastReverseDirectionAttemptByClientId: any;
414
413
  _stoppedVideoTrack: any;
415
414
  icePublicIPGatheringTimeoutID: any;
416
415
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
@@ -953,6 +952,9 @@ declare const _default: {
953
952
  SFU_CONNECTION_CLOSED: string;
954
953
  COLOCATION_SPEAKER: string;
955
954
  DOMINANT_SPEAKER: string;
955
+ PC_SLD_FAILURE: string;
956
+ PC_ON_ANSWER_FAILURE: string;
957
+ PC_ON_OFFER_FAILURE: string;
956
958
  };
957
959
 
958
960
  declare function setVideoBandwidthUsingSetParameters(pc: any, bandwidth: any, logger?: any): any;
@@ -970,6 +972,7 @@ declare const rtcStats: {
970
972
  };
971
973
 
972
974
  declare function setCodecPreferenceSDP(sdp: any, vp9On: any, redOn: any): string | undefined;
975
+ declare function cleanSdp(sdp: string): string;
973
976
  declare function maybeRejectNoH264(sdp: any): any;
974
977
  declare function deprioritizeH264(sdp: any): string;
975
978
  declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
@@ -1014,7 +1017,6 @@ declare class Session {
1014
1017
  shouldAddLocalVideo: any;
1015
1018
  signalingState: any;
1016
1019
  srdComplete: any;
1017
- pendingOffer: any;
1018
1020
  constructor({ peerConnectionId, bandwidth, maximumTurnBandwidth, deprioritizeH264Encoding, }: {
1019
1021
  peerConnectionId: any;
1020
1022
  bandwidth: any;
@@ -1496,4 +1498,4 @@ declare class RtcStream {
1496
1498
  static getTypeFromId(id: string): string;
1497
1499
  }
1498
1500
 
1499
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1501
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.d.mts CHANGED
@@ -410,7 +410,6 @@ declare class P2pRtcManager implements RtcManager {
410
410
  ipv6HostCandidateTeredoSeen: any;
411
411
  ipv6HostCandidate6to4Seen: any;
412
412
  mdnsHostCandidateSeen: any;
413
- _lastReverseDirectionAttemptByClientId: any;
414
413
  _stoppedVideoTrack: any;
415
414
  icePublicIPGatheringTimeoutID: any;
416
415
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
@@ -953,6 +952,9 @@ declare const _default: {
953
952
  SFU_CONNECTION_CLOSED: string;
954
953
  COLOCATION_SPEAKER: string;
955
954
  DOMINANT_SPEAKER: string;
955
+ PC_SLD_FAILURE: string;
956
+ PC_ON_ANSWER_FAILURE: string;
957
+ PC_ON_OFFER_FAILURE: string;
956
958
  };
957
959
 
958
960
  declare function setVideoBandwidthUsingSetParameters(pc: any, bandwidth: any, logger?: any): any;
@@ -970,6 +972,7 @@ declare const rtcStats: {
970
972
  };
971
973
 
972
974
  declare function setCodecPreferenceSDP(sdp: any, vp9On: any, redOn: any): string | undefined;
975
+ declare function cleanSdp(sdp: string): string;
973
976
  declare function maybeRejectNoH264(sdp: any): any;
974
977
  declare function deprioritizeH264(sdp: any): string;
975
978
  declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
@@ -1014,7 +1017,6 @@ declare class Session {
1014
1017
  shouldAddLocalVideo: any;
1015
1018
  signalingState: any;
1016
1019
  srdComplete: any;
1017
- pendingOffer: any;
1018
1020
  constructor({ peerConnectionId, bandwidth, maximumTurnBandwidth, deprioritizeH264Encoding, }: {
1019
1021
  peerConnectionId: any;
1020
1022
  bandwidth: any;
@@ -1496,4 +1498,4 @@ declare class RtcStream {
1496
1498
  static getTypeFromId(id: string): string;
1497
1499
  }
1498
1500
 
1499
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1501
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.d.ts CHANGED
@@ -410,7 +410,6 @@ declare class P2pRtcManager implements RtcManager {
410
410
  ipv6HostCandidateTeredoSeen: any;
411
411
  ipv6HostCandidate6to4Seen: any;
412
412
  mdnsHostCandidateSeen: any;
413
- _lastReverseDirectionAttemptByClientId: any;
414
413
  _stoppedVideoTrack: any;
415
414
  icePublicIPGatheringTimeoutID: any;
416
415
  _videoTrackBeingMonitored?: CustomMediaStreamTrack;
@@ -953,6 +952,9 @@ declare const _default: {
953
952
  SFU_CONNECTION_CLOSED: string;
954
953
  COLOCATION_SPEAKER: string;
955
954
  DOMINANT_SPEAKER: string;
955
+ PC_SLD_FAILURE: string;
956
+ PC_ON_ANSWER_FAILURE: string;
957
+ PC_ON_OFFER_FAILURE: string;
956
958
  };
957
959
 
958
960
  declare function setVideoBandwidthUsingSetParameters(pc: any, bandwidth: any, logger?: any): any;
@@ -970,6 +972,7 @@ declare const rtcStats: {
970
972
  };
971
973
 
972
974
  declare function setCodecPreferenceSDP(sdp: any, vp9On: any, redOn: any): string | undefined;
975
+ declare function cleanSdp(sdp: string): string;
973
976
  declare function maybeRejectNoH264(sdp: any): any;
974
977
  declare function deprioritizeH264(sdp: any): string;
975
978
  declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
@@ -1014,7 +1017,6 @@ declare class Session {
1014
1017
  shouldAddLocalVideo: any;
1015
1018
  signalingState: any;
1016
1019
  srdComplete: any;
1017
- pendingOffer: any;
1018
1020
  constructor({ peerConnectionId, bandwidth, maximumTurnBandwidth, deprioritizeH264Encoding, }: {
1019
1021
  peerConnectionId: any;
1020
1022
  bandwidth: any;
@@ -1496,4 +1498,4 @@ declare class RtcStream {
1496
1498
  static getTypeFromId(id: string): string;
1497
1499
  }
1498
1500
 
1499
- export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
1501
+ export { type AddSpotlightRequest, type AudioEnableRequest, type AudioEnableRequestedEvent, type AudioEnabledEvent, BandwidthTester, type ChatMessage, type ClientKickedEvent, type ClientLeftEvent, type ClientMetadataPayload, type ClientMetadataReceivedEvent, type ClientRole, type ClientUnableToJoinEvent, type CloudRecordingStartedEvent, type Credentials, type CustomMediaStreamTrack, EVENTS, type GetConstraintsOptions, type GetDeviceDataResult, type GetMediaConstraintsOptions, type GetStreamOptions, type GetStreamResult, type GetUpdatedDevicesResult, type IdentifyDeviceRequest, type IssuesAndMetricsByView, type JoinRoomRequest, KNOCK_MESSAGES, KalmanFilter, type KnockAcceptedEvent, type KnockRejectedEvent, type KnockRoomRequest, type KnockerLeftEvent, type LiveTranscriptionStartedEvent, type LiveTranscriptionStoppedEvent, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, type NewClientEvent, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, type RemoveSpotlightRequest, type RoleName, type RoomJoinedEvent, type RoomKnockedEvent, type RoomLockedEvent, type RoomSessionEndedEvent, type RtcClientConnectionStatusChangedPayload, RtcEventNames, type RtcEvents, type RtcLocalStreamTrackAddedPayload, type RtcLocalStreamTrackRemovedPayload, type RtcManager, type RtcManagerCreatedPayload, RtcManagerDispatcher, RtcStream, type RtcStreamAddedPayload, STREAM_TYPES, type ScreenshareStartedEvent, type ScreenshareStoppedEvent, type SendClientMetadataRequest, ServerSocket, Session, SfuV2Parser, type SignalClient, type SignalEvents, type SignalKnocker, type SignalRequests, type SocketConf, type SocketManager, type Spotlight, type SpotlightAddedEvent, type SpotlightRemovedEvent, type StatsMonitorOptions, type StatsMonitorState, TYPES, type TurnTransportProtocol, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, type VideoEnableRequest, type VideoEnableRequestedEvent, type VideoEnabledEvent, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
package/dist/index.mjs CHANGED
@@ -2701,6 +2701,27 @@ function setCodecPreferenceSDP(sdp, vp9On, redOn) {
2701
2701
  logger$6.error("setCodecPreferenceSDP error:", error);
2702
2702
  }
2703
2703
  }
2704
+ function cleanSdp(sdp) {
2705
+ try {
2706
+ const sdpObject = sdpTransform.parse(sdp);
2707
+ sdpObject.media.forEach(mediaObject => {
2708
+ const usedPayloads = {};
2709
+ if (mediaObject.payloads)
2710
+ mediaObject.payloads = ("" + mediaObject.payloads).split(' ').filter(p => !usedPayloads[p] && (usedPayloads[p] = true)).join(' ');
2711
+ const usedRtps = {};
2712
+ mediaObject.rtp = mediaObject.rtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtps[p.payload] && (usedRtps[p.payload] = true)));
2713
+ const usedFmtps = {};
2714
+ if (mediaObject.fmtp)
2715
+ mediaObject.fmtp = mediaObject.fmtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedFmtps[p.payload] && (usedFmtps[p.payload] = true)));
2716
+ const usedRtcpFb = {};
2717
+ if (mediaObject.rtcpFb)
2718
+ mediaObject.rtcpFb = mediaObject.rtcpFb.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtcpFb[p.payload + p.type] && (usedRtcpFb[p.payload + p.type] = true)));
2719
+ });
2720
+ return sdpTransform.write(sdpObject);
2721
+ }
2722
+ catch (_) { }
2723
+ return sdp;
2724
+ }
2704
2725
  function maybeRejectNoH264(sdp) {
2705
2726
  if (browserName$2 !== "safari") {
2706
2727
  return sdp;
@@ -3022,13 +3043,7 @@ class Session {
3022
3043
  });
3023
3044
  }
3024
3045
  handleAnswer(message) {
3025
- if (this.pendingOffer) {
3026
- const pendingOffer = this.pendingOffer;
3027
- delete this.pendingOffer;
3028
- return this.pc.setLocalDescription(pendingOffer).then(() => this.handleAnswer(message));
3029
- }
3030
- let sdp = message.sdp;
3031
- sdp = filterMsidSemantic(sdp);
3046
+ const sdp = filterMsidSemantic(message.sdp);
3032
3047
  const desc = { type: message.type, sdp };
3033
3048
  return this._setRemoteDescription(desc).then(() => {
3034
3049
  return setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
@@ -3482,6 +3497,9 @@ var rtcManagerEvents = {
3482
3497
  SFU_CONNECTION_CLOSED: "sfu_connection_closed",
3483
3498
  COLOCATION_SPEAKER: "colocation_speaker",
3484
3499
  DOMINANT_SPEAKER: "dominant_speaker",
3500
+ PC_SLD_FAILURE: "pc_sld_failure",
3501
+ PC_ON_ANSWER_FAILURE: "pc_on_answer_failure",
3502
+ PC_ON_OFFER_FAILURE: "pc_on_offer_failure",
3485
3503
  };
3486
3504
 
3487
3505
  var _a$2, _b;
@@ -3661,27 +3679,33 @@ class P2pRtcManager {
3661
3679
  session.addIceCandidate(null);
3662
3680
  }),
3663
3681
  this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
3682
+ var _a, _b;
3664
3683
  const session = this._getSession(data.clientId);
3665
3684
  if (!session) {
3666
3685
  logger$4.warn("No RTCPeerConnection on SDP_OFFER", data);
3667
3686
  return;
3668
3687
  }
3669
3688
  const offer = this._transformIncomingSdp(data.message, session.pc);
3670
- session.handleOffer(offer).then((answer) => {
3689
+ (_b = (_a = session.handleOffer(offer).then((answer) => {
3671
3690
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
3672
3691
  receiverId: data.clientId,
3673
3692
  message: this._transformOutgoingSdp(answer),
3674
3693
  });
3694
+ })).catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3695
+ this._emit(rtcManagerEvents.PC_ON_OFFER_FAILURE, e);
3675
3696
  });
3676
3697
  }),
3677
3698
  this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
3699
+ var _a, _b;
3678
3700
  const session = this._getSession(data.clientId);
3679
3701
  if (!session) {
3680
3702
  logger$4.warn("No RTCPeerConnection on SDP_ANSWER", data);
3681
3703
  return;
3682
3704
  }
3683
3705
  const answer = this._transformIncomingSdp(data.message, session.pc);
3684
- session.handleAnswer(answer);
3706
+ (_b = (_a = session.handleAnswer(answer)) === null || _a === void 0 ? void 0 : _a.catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3707
+ this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3708
+ });
3685
3709
  }),
3686
3710
  this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3687
3711
  if (isSfu || !this._wasScreenSharing)
@@ -4218,7 +4242,7 @@ class P2pRtcManager {
4218
4242
  return;
4219
4243
  }
4220
4244
  session.isOperationPending = true;
4221
- const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn } = this._features;
4245
+ const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
4222
4246
  if (vp9On || av1On || redOn) {
4223
4247
  this._setCodecPreferences(pc, vp9On, av1On, redOn);
4224
4248
  }
@@ -4229,26 +4253,17 @@ class P2pRtcManager {
4229
4253
  if ((vp9On || redOn) && browserName$1 === "firefox") {
4230
4254
  offer.sdp = setCodecPreferenceSDP(offer.sdp, vp9On, redOn);
4231
4255
  }
4232
- this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4233
- receiverId: clientId,
4234
- message: this._transformOutgoingSdp(offer),
4235
- });
4236
- if (browserName$1 === "chrome" &&
4237
- pc.getSenders().filter((sender) => sender.track && sender.track.kind === "video").length >= 2) {
4238
- session.pendingOffer = offer;
4239
- return;
4240
- }
4256
+ if (cleanSdpOn)
4257
+ offer.sdp = cleanSdp(offer.sdp);
4241
4258
  pc.setLocalDescription(offer).catch((e) => {
4242
4259
  logger$4.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4243
- if (this._features.reverseOfferOnFailure) {
4244
- if (!this._lastReverseDirectionAttemptByClientId)
4245
- this._lastReverseDirectionAttemptByClientId = {};
4246
- if (!this._lastReverseDirectionAttemptByClientId[clientId] ||
4247
- this._lastReverseDirectionAttemptByClientId[clientId] < Date.now() - 10000) {
4248
- this.acceptNewStream({ clientId, streamId: clientId, shouldAddLocalVideo: true });
4249
- this._lastReverseDirectionAttemptByClientId[clientId] = Date.now();
4250
- }
4251
- }
4260
+ this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4261
+ throw e;
4262
+ }).then(() => {
4263
+ this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4264
+ receiverId: clientId,
4265
+ message: this._transformOutgoingSdp(offer),
4266
+ });
4252
4267
  });
4253
4268
  })
4254
4269
  .catch((e) => {
@@ -6858,4 +6873,4 @@ function fromLocation({ host = "whereby.com", protocol = "https:" } = {}) {
6858
6873
  }
6859
6874
  fromLocation(window && window.location);
6860
6875
 
6861
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6876
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
@@ -2701,6 +2701,27 @@ function setCodecPreferenceSDP(sdp, vp9On, redOn) {
2701
2701
  logger$6.error("setCodecPreferenceSDP error:", error);
2702
2702
  }
2703
2703
  }
2704
+ function cleanSdp(sdp) {
2705
+ try {
2706
+ const sdpObject = sdpTransform.parse(sdp);
2707
+ sdpObject.media.forEach(mediaObject => {
2708
+ const usedPayloads = {};
2709
+ if (mediaObject.payloads)
2710
+ mediaObject.payloads = ("" + mediaObject.payloads).split(' ').filter(p => !usedPayloads[p] && (usedPayloads[p] = true)).join(' ');
2711
+ const usedRtps = {};
2712
+ mediaObject.rtp = mediaObject.rtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtps[p.payload] && (usedRtps[p.payload] = true)));
2713
+ const usedFmtps = {};
2714
+ if (mediaObject.fmtp)
2715
+ mediaObject.fmtp = mediaObject.fmtp.filter(p => !p.payload || (usedPayloads[p.payload] && !usedFmtps[p.payload] && (usedFmtps[p.payload] = true)));
2716
+ const usedRtcpFb = {};
2717
+ if (mediaObject.rtcpFb)
2718
+ mediaObject.rtcpFb = mediaObject.rtcpFb.filter(p => !p.payload || (usedPayloads[p.payload] && !usedRtcpFb[p.payload + p.type] && (usedRtcpFb[p.payload + p.type] = true)));
2719
+ });
2720
+ return sdpTransform.write(sdpObject);
2721
+ }
2722
+ catch (_) { }
2723
+ return sdp;
2724
+ }
2704
2725
  function maybeRejectNoH264(sdp) {
2705
2726
  if (browserName$2 !== "safari") {
2706
2727
  return sdp;
@@ -3022,13 +3043,7 @@ class Session {
3022
3043
  });
3023
3044
  }
3024
3045
  handleAnswer(message) {
3025
- if (this.pendingOffer) {
3026
- const pendingOffer = this.pendingOffer;
3027
- delete this.pendingOffer;
3028
- return this.pc.setLocalDescription(pendingOffer).then(() => this.handleAnswer(message));
3029
- }
3030
- let sdp = message.sdp;
3031
- sdp = filterMsidSemantic(sdp);
3046
+ const sdp = filterMsidSemantic(message.sdp);
3032
3047
  const desc = { type: message.type, sdp };
3033
3048
  return this._setRemoteDescription(desc).then(() => {
3034
3049
  return setVideoBandwidthUsingSetParameters(this.pc, this.bandwidth);
@@ -3482,6 +3497,9 @@ var rtcManagerEvents = {
3482
3497
  SFU_CONNECTION_CLOSED: "sfu_connection_closed",
3483
3498
  COLOCATION_SPEAKER: "colocation_speaker",
3484
3499
  DOMINANT_SPEAKER: "dominant_speaker",
3500
+ PC_SLD_FAILURE: "pc_sld_failure",
3501
+ PC_ON_ANSWER_FAILURE: "pc_on_answer_failure",
3502
+ PC_ON_OFFER_FAILURE: "pc_on_offer_failure",
3485
3503
  };
3486
3504
 
3487
3505
  var _a$2, _b;
@@ -3661,27 +3679,33 @@ class P2pRtcManager {
3661
3679
  session.addIceCandidate(null);
3662
3680
  }),
3663
3681
  this._serverSocket.on(RELAY_MESSAGES.SDP_OFFER, (data) => {
3682
+ var _a, _b;
3664
3683
  const session = this._getSession(data.clientId);
3665
3684
  if (!session) {
3666
3685
  logger$4.warn("No RTCPeerConnection on SDP_OFFER", data);
3667
3686
  return;
3668
3687
  }
3669
3688
  const offer = this._transformIncomingSdp(data.message, session.pc);
3670
- session.handleOffer(offer).then((answer) => {
3689
+ (_b = (_a = session.handleOffer(offer).then((answer) => {
3671
3690
  this._emitServerEvent(RELAY_MESSAGES.SDP_ANSWER, {
3672
3691
  receiverId: data.clientId,
3673
3692
  message: this._transformOutgoingSdp(answer),
3674
3693
  });
3694
+ })).catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3695
+ this._emit(rtcManagerEvents.PC_ON_OFFER_FAILURE, e);
3675
3696
  });
3676
3697
  }),
3677
3698
  this._serverSocket.on(RELAY_MESSAGES.SDP_ANSWER, (data) => {
3699
+ var _a, _b;
3678
3700
  const session = this._getSession(data.clientId);
3679
3701
  if (!session) {
3680
3702
  logger$4.warn("No RTCPeerConnection on SDP_ANSWER", data);
3681
3703
  return;
3682
3704
  }
3683
3705
  const answer = this._transformIncomingSdp(data.message, session.pc);
3684
- session.handleAnswer(answer);
3706
+ (_b = (_a = session.handleAnswer(answer)) === null || _a === void 0 ? void 0 : _a.catch) === null || _b === void 0 ? void 0 : _b.call(_a, (e) => {
3707
+ this._emit(rtcManagerEvents.PC_ON_ANSWER_FAILURE, e);
3708
+ });
3685
3709
  }),
3686
3710
  this._serverSocket.on(PROTOCOL_RESPONSES.ROOM_JOINED, ({ room: { sfuServer: isSfu } }) => {
3687
3711
  if (isSfu || !this._wasScreenSharing)
@@ -4218,7 +4242,7 @@ class P2pRtcManager {
4218
4242
  return;
4219
4243
  }
4220
4244
  session.isOperationPending = true;
4221
- const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn } = this._features;
4245
+ const { vp9On, av1On, redOn, rtpAbsCaptureTimeOn, cleanSdpOn } = this._features;
4222
4246
  if (vp9On || av1On || redOn) {
4223
4247
  this._setCodecPreferences(pc, vp9On, av1On, redOn);
4224
4248
  }
@@ -4229,26 +4253,17 @@ class P2pRtcManager {
4229
4253
  if ((vp9On || redOn) && browserName$1 === "firefox") {
4230
4254
  offer.sdp = setCodecPreferenceSDP(offer.sdp, vp9On, redOn);
4231
4255
  }
4232
- this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4233
- receiverId: clientId,
4234
- message: this._transformOutgoingSdp(offer),
4235
- });
4236
- if (browserName$1 === "chrome" &&
4237
- pc.getSenders().filter((sender) => sender.track && sender.track.kind === "video").length >= 2) {
4238
- session.pendingOffer = offer;
4239
- return;
4240
- }
4256
+ if (cleanSdpOn)
4257
+ offer.sdp = cleanSdp(offer.sdp);
4241
4258
  pc.setLocalDescription(offer).catch((e) => {
4242
4259
  logger$4.warn("RTCPeerConnection.setLocalDescription() failed with local offer", e);
4243
- if (this._features.reverseOfferOnFailure) {
4244
- if (!this._lastReverseDirectionAttemptByClientId)
4245
- this._lastReverseDirectionAttemptByClientId = {};
4246
- if (!this._lastReverseDirectionAttemptByClientId[clientId] ||
4247
- this._lastReverseDirectionAttemptByClientId[clientId] < Date.now() - 10000) {
4248
- this.acceptNewStream({ clientId, streamId: clientId, shouldAddLocalVideo: true });
4249
- this._lastReverseDirectionAttemptByClientId[clientId] = Date.now();
4250
- }
4251
- }
4260
+ this._emit(rtcManagerEvents.PC_SLD_FAILURE, e);
4261
+ throw e;
4262
+ }).then(() => {
4263
+ this._emitServerEvent(RELAY_MESSAGES.SDP_OFFER, {
4264
+ receiverId: clientId,
4265
+ message: this._transformOutgoingSdp(offer),
4266
+ });
4252
4267
  });
4253
4268
  })
4254
4269
  .catch((e) => {
@@ -6858,5 +6873,5 @@ function fromLocation({ host = "whereby.com", protocol = "https:" } = {}) {
6858
6873
  }
6859
6874
  fromLocation(window && window.location);
6860
6875
 
6861
- export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6876
+ export { BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MAXIMUM_TURN_BANDWIDTH, MAXIMUM_TURN_BANDWIDTH_UNLIMITED, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getHandler, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getOptimalBitrate, getPeerConnectionIndex, getStats, getStream, getStream2, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, isRelayed, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, variance };
6862
6877
  //# sourceMappingURL=legacy-esm.js.map
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.15.0",
4
+ "version": "1.16.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {