@whereby.com/media 2.7.0 → 2.7.2

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
@@ -1566,6 +1566,7 @@ var _a$6;
1566
1566
  const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
1567
1567
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1568
1568
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1569
+ const DISCONNECT_DURATION_LIMIT_MS = 60000;
1569
1570
  class ServerSocket {
1570
1571
  constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1571
1572
  this._wasConnectedUsingWebsocket = false;
@@ -1573,21 +1574,22 @@ class ServerSocket {
1573
1574
  this.disconnectDurationLimitExceeded = false;
1574
1575
  this._reconnectManager = null;
1575
1576
  this._socket = socket_ioClient.io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1577
+ this._disconnectDurationLimitEnabled = false;
1576
1578
  this.joinRoomFinished = false;
1577
1579
  this._socket.io.on("reconnect", () => {
1578
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1580
+ if (this._disconnectDurationLimitOn &&
1581
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1579
1582
  this._socket.close();
1580
1583
  this.disconnectDurationLimitExceeded = true;
1581
- return;
1582
1584
  }
1583
1585
  this._socket.sendBuffer = [];
1584
1586
  });
1585
1587
  this._socket.io.on("reconnect_attempt", () => {
1586
1588
  var _a;
1587
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1589
+ if (this._disconnectDurationLimitOn &&
1590
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1588
1591
  this._socket.close();
1589
1592
  this.disconnectDurationLimitExceeded = true;
1590
- return;
1591
1593
  }
1592
1594
  if (this._wasConnectedUsingWebsocket) {
1593
1595
  this._socket.io.opts.transports = ["websocket"];
@@ -1611,25 +1613,30 @@ class ServerSocket {
1611
1613
  const transport = this.getTransport();
1612
1614
  if (transport === "websocket") {
1613
1615
  this._wasConnectedUsingWebsocket = true;
1614
- if (!this.noopKeepaliveInterval)
1616
+ if (!this.noopKeepaliveInterval) {
1617
+ let disconnectDurationLimitTimestampCandidate = Date.now();
1615
1618
  this.noopKeepaliveInterval = setInterval(() => {
1616
1619
  try {
1617
1620
  if (this._socket.connected) {
1618
- if (this._disconnectDurationLimitOn) {
1619
- this._noopKeepaliveTimestamp = Date.now();
1621
+ if (this._disconnectDurationLimitOn &&
1622
+ !this._didExceedDisconnectDurationLimit(disconnectDurationLimitTimestampCandidate)) {
1623
+ this._disconnectDurationLimitLatestTimestamp =
1624
+ disconnectDurationLimitTimestampCandidate;
1625
+ disconnectDurationLimitTimestampCandidate = Date.now();
1620
1626
  }
1621
1627
  this._socket.io.engine.sendPacket("noop");
1622
1628
  }
1623
1629
  }
1624
1630
  catch (ex) { }
1625
1631
  }, NOOP_KEEPALIVE_INTERVAL);
1632
+ }
1626
1633
  }
1627
1634
  });
1628
1635
  this._socket.on("disconnect", () => {
1629
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1636
+ if (this._disconnectDurationLimitOn &&
1637
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1630
1638
  this._socket.close();
1631
1639
  this.disconnectDurationLimitExceeded = true;
1632
- return;
1633
1640
  }
1634
1641
  this.joinRoomFinished = false;
1635
1642
  this.disconnectTimestamp = Date.now();
@@ -1639,20 +1646,18 @@ class ServerSocket {
1639
1646
  }
1640
1647
  });
1641
1648
  }
1642
- _didExceedDisconnectDurationLimit() {
1643
- if (!this._disconnectDurationLimitOn)
1644
- return false;
1645
- if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1646
- const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1647
- if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1648
- return true;
1649
- }
1649
+ _didExceedDisconnectDurationLimit(timestamp) {
1650
+ if (!timestamp || !this._disconnectDurationLimitOn || !this._disconnectDurationLimitEnabled)
1650
1651
  return false;
1652
+ const disconnectedDuration = Date.now() - timestamp;
1653
+ if (disconnectedDuration > DISCONNECT_DURATION_LIMIT_MS) {
1654
+ return true;
1651
1655
  }
1656
+ return false;
1652
1657
  }
1653
- setDisconnectDurationLimit(limitInMs) {
1658
+ enableDisconnectDurationLimit() {
1654
1659
  if (this._disconnectDurationLimitOn) {
1655
- this._disconnectDurationLimitInMs = limitInMs;
1660
+ this._disconnectDurationLimitEnabled = true;
1656
1661
  }
1657
1662
  }
1658
1663
  setRtcManager(rtcManager) {
@@ -2066,18 +2071,6 @@ function deprioritizeH264(sdp) {
2066
2071
  })
2067
2072
  .join("");
2068
2073
  }
2069
- function replaceSSRCs(currentDescription, newDescription) {
2070
- let ssrcs = currentDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2071
- let newssrcs = newDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2072
- if (!ssrcs) {
2073
- ssrcs = currentDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2074
- newssrcs = newDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2075
- }
2076
- for (let i = 1; i < ssrcs.length; i++) {
2077
- newDescription = newDescription.replace(new RegExp(newssrcs[i], "g"), ssrcs[i]);
2078
- }
2079
- return newDescription;
2080
- }
2081
2074
  function filterMidExtension(sdp) {
2082
2075
  if (browserName$2 !== "safari" &&
2083
2076
  (browserName$2 !== "firefox" || (browserVersion$1 && browserVersion$1 >= 63) || browserVersion$1 === 60)) {
@@ -2362,7 +2355,6 @@ class Session {
2362
2355
  return this.pc && this.pc.connectionState === "connected";
2363
2356
  }
2364
2357
  replaceTrack(oldTrack, newTrack) {
2365
- var _a, _b, _c;
2366
2358
  logger$7.info("replacetrack() [oldTrackId: %s, newTrackId: %s]", oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack === null || newTrack === void 0 ? void 0 : newTrack.id);
2367
2359
  if (!newTrack) {
2368
2360
  rtcStats.sendEvent("P2PReplaceTrackNoNewTrack", {
@@ -2383,55 +2375,38 @@ class Session {
2383
2375
  return false;
2384
2376
  }
2385
2377
  const pc = this.pc;
2386
- if ((_b = (_a = window.RTCRtpSender) === null || _a === void 0 ? void 0 : _a.prototype) === null || _b === void 0 ? void 0 : _b.replaceTrack) {
2387
- if (oldTrack) {
2388
- const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2389
- if (sender) {
2390
- sender.replaceTrack(newTrack);
2391
- return Promise.resolve(newTrack);
2392
- }
2393
- }
2394
- const sender = pc.getSenders().find((s) => {
2395
- const track = s.track;
2396
- return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2397
- });
2378
+ if (oldTrack) {
2379
+ const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2398
2380
  if (sender) {
2399
- this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2400
- const track = sender.track;
2401
- rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2402
- targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2403
- targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2404
- targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2405
- targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2406
- newTrackId: newTrack.id,
2407
- newTrackKind: newTrack.kind,
2408
- newTrackIsEffect: newTrack.effectTrack,
2409
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2410
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2411
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2412
- });
2413
2381
  sender.replaceTrack(newTrack);
2414
2382
  return Promise.resolve(newTrack);
2415
2383
  }
2416
- let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2417
- if (!stream) {
2418
- rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2419
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2420
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2421
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2422
- newTrackId: newTrack.id,
2423
- newTrackKind: newTrack.kind,
2424
- newTrackIsEffect: newTrack.effectTrack,
2425
- });
2426
- this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2427
- }
2428
- stream = this.streams[0];
2429
- if (!stream) {
2430
- rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2431
- this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2432
- return Promise.reject(new Error("replaceTrack: No stream?"));
2433
- }
2434
- rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2384
+ }
2385
+ const sender = pc.getSenders().find((s) => {
2386
+ const track = s.track;
2387
+ return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2388
+ });
2389
+ if (sender) {
2390
+ this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2391
+ const track = sender.track;
2392
+ rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2393
+ targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2394
+ targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2395
+ targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2396
+ targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2397
+ newTrackId: newTrack.id,
2398
+ newTrackKind: newTrack.kind,
2399
+ newTrackIsEffect: newTrack.effectTrack,
2400
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2401
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2402
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2403
+ });
2404
+ sender.replaceTrack(newTrack);
2405
+ return Promise.resolve(newTrack);
2406
+ }
2407
+ let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2408
+ if (!stream) {
2409
+ rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2435
2410
  oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2436
2411
  oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2437
2412
  oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
@@ -2439,49 +2414,24 @@ class Session {
2439
2414
  newTrackKind: newTrack.kind,
2440
2415
  newTrackIsEffect: newTrack.effectTrack,
2441
2416
  });
2442
- this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2443
- return pc.addTrack(newTrack, stream);
2444
- }
2445
- rtcStats.sendEvent("P2PNoReplaceTrackSupport", {});
2446
- if (!this.canModifyPeerConnection()) {
2447
- this.pending.push(() => {
2448
- this.replaceTrack(oldTrack, newTrack);
2449
- });
2450
- return;
2451
- }
2452
- this.isOperationPending = true;
2453
- const onn = pc.onnegotiationneeded;
2454
- pc.onnegotiationneeded = null;
2455
- if (oldTrack) {
2456
- this.removeTrack(oldTrack);
2457
- }
2458
- this.addTrack(newTrack);
2459
- setTimeout(() => {
2460
- pc.onnegotiationneeded = onn;
2461
- }, 0);
2462
- if (((_c = pc.localDescription) === null || _c === void 0 ? void 0 : _c.type) === "offer") {
2463
- return pc
2464
- .createOffer()
2465
- .then((offer) => {
2466
- var _a;
2467
- offer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, offer.sdp);
2468
- return pc.setLocalDescription(offer);
2469
- })
2470
- .then(() => {
2471
- return this._setRemoteDescription(pc.remoteDescription);
2472
- });
2473
- }
2474
- else {
2475
- return this._setRemoteDescription(pc.remoteDescription)
2476
- .then(() => {
2477
- return pc.createAnswer();
2478
- })
2479
- .then((answer) => {
2480
- var _a;
2481
- answer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, answer.sdp);
2482
- return pc.setLocalDescription(answer);
2483
- });
2417
+ this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2484
2418
  }
2419
+ stream = this.streams[0];
2420
+ if (!stream) {
2421
+ rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2422
+ this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2423
+ return Promise.reject(new Error("replaceTrack: No stream?"));
2424
+ }
2425
+ rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2426
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2427
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2428
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2429
+ newTrackId: newTrack.id,
2430
+ newTrackKind: newTrack.kind,
2431
+ newTrackIsEffect: newTrack.effectTrack,
2432
+ });
2433
+ this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2434
+ return pc.addTrack(newTrack, stream);
2485
2435
  }
2486
2436
  changeBandwidth(bandwidth) {
2487
2437
  var _a;
@@ -7647,7 +7597,6 @@ exports.maybeRejectNoH264 = maybeRejectNoH264;
7647
7597
  exports.maybeTurnOnly = maybeTurnOnly;
7648
7598
  exports.modifyMediaCapabilities = modifyMediaCapabilities;
7649
7599
  exports.removePeerConnection = removePeerConnection;
7650
- exports.replaceSSRCs = replaceSSRCs;
7651
7600
  exports.replaceTracksInStream = replaceTracksInStream;
7652
7601
  exports.rtcManagerEvents = rtcManagerEvents;
7653
7602
  exports.rtcStats = rtcStats;
package/dist/index.d.cts CHANGED
@@ -555,7 +555,7 @@ declare class Session {
555
555
  canModifyPeerConnection(): boolean;
556
556
  close(): void;
557
557
  hasConnectedPeerConnection(): boolean;
558
- replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): any;
558
+ replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): false | RTCRtpSender | Promise<CustomMediaStreamTrack>;
559
559
  changeBandwidth(bandwidth: any): void;
560
560
  setAudioOnly(enable: boolean, excludedTrackIds?: string[]): void;
561
561
  }
@@ -708,16 +708,17 @@ declare class ServerSocket {
708
708
  _socket: any;
709
709
  _reconnectManager?: ReconnectManager | null;
710
710
  noopKeepaliveInterval: any;
711
- _noopKeepaliveTimestamp: number | undefined;
712
711
  _wasConnectedUsingWebsocket?: boolean;
713
712
  disconnectTimestamp: number | undefined;
714
713
  disconnectDurationLimitExceeded: boolean;
715
714
  joinRoomFinished: boolean;
716
715
  _disconnectDurationLimitOn: boolean;
716
+ _disconnectDurationLimitEnabled: boolean;
717
717
  _disconnectDurationLimitInMs: number | undefined;
718
+ _disconnectDurationLimitLatestTimestamp: number | undefined;
718
719
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
719
- _didExceedDisconnectDurationLimit(): boolean | undefined;
720
- setDisconnectDurationLimit(limitInMs: number): void;
720
+ _didExceedDisconnectDurationLimit(timestamp: number | undefined): boolean;
721
+ enableDisconnectDurationLimit(): void;
721
722
  setRtcManager(rtcManager?: RtcManager): void;
722
723
  connect(): void;
723
724
  disconnect(): void;
@@ -1369,7 +1370,6 @@ declare function setCodecPreferenceSDP(sdp: any, redOn?: boolean): string | unde
1369
1370
  declare function cleanSdp(sdp: string): string;
1370
1371
  declare function maybeRejectNoH264(sdp: any): any;
1371
1372
  declare function deprioritizeH264(sdp: any): string;
1372
- declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
1373
1373
  declare function filterMidExtension(sdp: any): any;
1374
1374
  declare function filterMsidSemantic(sdp: any): any;
1375
1375
  declare function changeMediaDirection(sdp: any, active: any): string;
@@ -1902,5 +1902,5 @@ declare class RtcStream {
1902
1902
  static getCameraId(): string;
1903
1903
  }
1904
1904
 
1905
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1905
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1906
1906
  export type { AddSpotlightRequest, AudioEnableRequest, AudioEnableRequestedEvent, AudioEnabledEvent, BreakoutConfig, BreakoutGroupJoinedEvent, BreakoutSessionUpdatedEvent, CannotJoinUnclaimedRoomError, ChatMessage, ClientKickedEvent, ClientLeftEvent, ClientMetadataPayload, ClientMetadataReceivedEvent, ClientRole, ClientUnableToJoinEvent, CloudRecordingStartedEvent, Codec, Credentials, CustomMediaStreamTrack, ForbiddenError, ForbiddenErrorNames, GetConstraintsOptions, GetDeviceDataResult, GetMediaConstraintsOptions, GetStreamOptions, GetStreamResult, GetUpdatedDevicesResult, HostPresenceControlsError, IdentifyDeviceRequest, InternalServerError, InvalidAssistantKeyError, IssuesAndMetricsByView, JoinRoomRequest, KnockAcceptedEvent, KnockRejectedEvent, KnockRoomRequest, KnockerLeftEvent, LiveTranscriptionStartedEvent, LiveTranscriptionStoppedEvent, MaxViewerLimitReachedError, Metric, NewClientEvent, OrganizationAssistantNotEnabledError, OrganizationAssistantNotFoundError, OrganizationPlanExhaustedError, RemoveSpotlightRequest, RoleName, RoomConcurrencyControlsError, RoomFullError, RoomJoinedErrors, RoomJoinedEvent, RoomJoinedSuccess, RoomKnockedEvent, RoomLockedError, RoomLockedEvent, RoomMeetingTimeExhaustedError, RoomMode, RoomSessionEndedEvent, RtcClientConnectionStatusChangedPayload, RtcEvents, RtcLocalStreamTrackAddedPayload, RtcLocalStreamTrackRemovedPayload, RtcManager, RtcManagerCreatedPayload, RtcStreamAddedPayload, SDPRelayMessage, ScreenshareStartedEvent, ScreenshareStoppedEvent, SendClientMetadataRequest, SignalClient, SignalEvents, SignalKnocker, SignalRequests, SocketConf, SocketManager, Spotlight, SpotlightAddedEvent, SpotlightRemovedEvent, StatsMonitorOptions, StatsMonitorState, StatsSubscription, TurnTransportProtocol, UnifiedPlanSDP, UpdatedDeviceInfo, UpdatedDevicesInfo, VideoEnableRequest, VideoEnableRequestedEvent, VideoEnabledEvent };
package/dist/index.d.mts CHANGED
@@ -555,7 +555,7 @@ declare class Session {
555
555
  canModifyPeerConnection(): boolean;
556
556
  close(): void;
557
557
  hasConnectedPeerConnection(): boolean;
558
- replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): any;
558
+ replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): false | RTCRtpSender | Promise<CustomMediaStreamTrack>;
559
559
  changeBandwidth(bandwidth: any): void;
560
560
  setAudioOnly(enable: boolean, excludedTrackIds?: string[]): void;
561
561
  }
@@ -708,16 +708,17 @@ declare class ServerSocket {
708
708
  _socket: any;
709
709
  _reconnectManager?: ReconnectManager | null;
710
710
  noopKeepaliveInterval: any;
711
- _noopKeepaliveTimestamp: number | undefined;
712
711
  _wasConnectedUsingWebsocket?: boolean;
713
712
  disconnectTimestamp: number | undefined;
714
713
  disconnectDurationLimitExceeded: boolean;
715
714
  joinRoomFinished: boolean;
716
715
  _disconnectDurationLimitOn: boolean;
716
+ _disconnectDurationLimitEnabled: boolean;
717
717
  _disconnectDurationLimitInMs: number | undefined;
718
+ _disconnectDurationLimitLatestTimestamp: number | undefined;
718
719
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
719
- _didExceedDisconnectDurationLimit(): boolean | undefined;
720
- setDisconnectDurationLimit(limitInMs: number): void;
720
+ _didExceedDisconnectDurationLimit(timestamp: number | undefined): boolean;
721
+ enableDisconnectDurationLimit(): void;
721
722
  setRtcManager(rtcManager?: RtcManager): void;
722
723
  connect(): void;
723
724
  disconnect(): void;
@@ -1369,7 +1370,6 @@ declare function setCodecPreferenceSDP(sdp: any, redOn?: boolean): string | unde
1369
1370
  declare function cleanSdp(sdp: string): string;
1370
1371
  declare function maybeRejectNoH264(sdp: any): any;
1371
1372
  declare function deprioritizeH264(sdp: any): string;
1372
- declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
1373
1373
  declare function filterMidExtension(sdp: any): any;
1374
1374
  declare function filterMsidSemantic(sdp: any): any;
1375
1375
  declare function changeMediaDirection(sdp: any, active: any): string;
@@ -1902,5 +1902,5 @@ declare class RtcStream {
1902
1902
  static getCameraId(): string;
1903
1903
  }
1904
1904
 
1905
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1905
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1906
1906
  export type { AddSpotlightRequest, AudioEnableRequest, AudioEnableRequestedEvent, AudioEnabledEvent, BreakoutConfig, BreakoutGroupJoinedEvent, BreakoutSessionUpdatedEvent, CannotJoinUnclaimedRoomError, ChatMessage, ClientKickedEvent, ClientLeftEvent, ClientMetadataPayload, ClientMetadataReceivedEvent, ClientRole, ClientUnableToJoinEvent, CloudRecordingStartedEvent, Codec, Credentials, CustomMediaStreamTrack, ForbiddenError, ForbiddenErrorNames, GetConstraintsOptions, GetDeviceDataResult, GetMediaConstraintsOptions, GetStreamOptions, GetStreamResult, GetUpdatedDevicesResult, HostPresenceControlsError, IdentifyDeviceRequest, InternalServerError, InvalidAssistantKeyError, IssuesAndMetricsByView, JoinRoomRequest, KnockAcceptedEvent, KnockRejectedEvent, KnockRoomRequest, KnockerLeftEvent, LiveTranscriptionStartedEvent, LiveTranscriptionStoppedEvent, MaxViewerLimitReachedError, Metric, NewClientEvent, OrganizationAssistantNotEnabledError, OrganizationAssistantNotFoundError, OrganizationPlanExhaustedError, RemoveSpotlightRequest, RoleName, RoomConcurrencyControlsError, RoomFullError, RoomJoinedErrors, RoomJoinedEvent, RoomJoinedSuccess, RoomKnockedEvent, RoomLockedError, RoomLockedEvent, RoomMeetingTimeExhaustedError, RoomMode, RoomSessionEndedEvent, RtcClientConnectionStatusChangedPayload, RtcEvents, RtcLocalStreamTrackAddedPayload, RtcLocalStreamTrackRemovedPayload, RtcManager, RtcManagerCreatedPayload, RtcStreamAddedPayload, SDPRelayMessage, ScreenshareStartedEvent, ScreenshareStoppedEvent, SendClientMetadataRequest, SignalClient, SignalEvents, SignalKnocker, SignalRequests, SocketConf, SocketManager, Spotlight, SpotlightAddedEvent, SpotlightRemovedEvent, StatsMonitorOptions, StatsMonitorState, StatsSubscription, TurnTransportProtocol, UnifiedPlanSDP, UpdatedDeviceInfo, UpdatedDevicesInfo, VideoEnableRequest, VideoEnableRequestedEvent, VideoEnabledEvent };
package/dist/index.d.ts CHANGED
@@ -555,7 +555,7 @@ declare class Session {
555
555
  canModifyPeerConnection(): boolean;
556
556
  close(): void;
557
557
  hasConnectedPeerConnection(): boolean;
558
- replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): any;
558
+ replaceTrack(oldTrack: CustomMediaStreamTrack | undefined, newTrack: CustomMediaStreamTrack | undefined): false | RTCRtpSender | Promise<CustomMediaStreamTrack>;
559
559
  changeBandwidth(bandwidth: any): void;
560
560
  setAudioOnly(enable: boolean, excludedTrackIds?: string[]): void;
561
561
  }
@@ -708,16 +708,17 @@ declare class ServerSocket {
708
708
  _socket: any;
709
709
  _reconnectManager?: ReconnectManager | null;
710
710
  noopKeepaliveInterval: any;
711
- _noopKeepaliveTimestamp: number | undefined;
712
711
  _wasConnectedUsingWebsocket?: boolean;
713
712
  disconnectTimestamp: number | undefined;
714
713
  disconnectDurationLimitExceeded: boolean;
715
714
  joinRoomFinished: boolean;
716
715
  _disconnectDurationLimitOn: boolean;
716
+ _disconnectDurationLimitEnabled: boolean;
717
717
  _disconnectDurationLimitInMs: number | undefined;
718
+ _disconnectDurationLimitLatestTimestamp: number | undefined;
718
719
  constructor(hostName: string, optionsOverrides?: any, glitchFree?: boolean, disconnectDurationLimitOn?: boolean);
719
- _didExceedDisconnectDurationLimit(): boolean | undefined;
720
- setDisconnectDurationLimit(limitInMs: number): void;
720
+ _didExceedDisconnectDurationLimit(timestamp: number | undefined): boolean;
721
+ enableDisconnectDurationLimit(): void;
721
722
  setRtcManager(rtcManager?: RtcManager): void;
722
723
  connect(): void;
723
724
  disconnect(): void;
@@ -1369,7 +1370,6 @@ declare function setCodecPreferenceSDP(sdp: any, redOn?: boolean): string | unde
1369
1370
  declare function cleanSdp(sdp: string): string;
1370
1371
  declare function maybeRejectNoH264(sdp: any): any;
1371
1372
  declare function deprioritizeH264(sdp: any): string;
1372
- declare function replaceSSRCs(currentDescription: any, newDescription: any): any;
1373
1373
  declare function filterMidExtension(sdp: any): any;
1374
1374
  declare function filterMsidSemantic(sdp: any): any;
1375
1375
  declare function changeMediaDirection(sdp: any, active: any): string;
@@ -1902,5 +1902,5 @@ declare class RtcStream {
1902
1902
  static getCameraId(): string;
1903
1903
  }
1904
1904
 
1905
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1905
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, _default as rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
1906
1906
  export type { AddSpotlightRequest, AudioEnableRequest, AudioEnableRequestedEvent, AudioEnabledEvent, BreakoutConfig, BreakoutGroupJoinedEvent, BreakoutSessionUpdatedEvent, CannotJoinUnclaimedRoomError, ChatMessage, ClientKickedEvent, ClientLeftEvent, ClientMetadataPayload, ClientMetadataReceivedEvent, ClientRole, ClientUnableToJoinEvent, CloudRecordingStartedEvent, Codec, Credentials, CustomMediaStreamTrack, ForbiddenError, ForbiddenErrorNames, GetConstraintsOptions, GetDeviceDataResult, GetMediaConstraintsOptions, GetStreamOptions, GetStreamResult, GetUpdatedDevicesResult, HostPresenceControlsError, IdentifyDeviceRequest, InternalServerError, InvalidAssistantKeyError, IssuesAndMetricsByView, JoinRoomRequest, KnockAcceptedEvent, KnockRejectedEvent, KnockRoomRequest, KnockerLeftEvent, LiveTranscriptionStartedEvent, LiveTranscriptionStoppedEvent, MaxViewerLimitReachedError, Metric, NewClientEvent, OrganizationAssistantNotEnabledError, OrganizationAssistantNotFoundError, OrganizationPlanExhaustedError, RemoveSpotlightRequest, RoleName, RoomConcurrencyControlsError, RoomFullError, RoomJoinedErrors, RoomJoinedEvent, RoomJoinedSuccess, RoomKnockedEvent, RoomLockedError, RoomLockedEvent, RoomMeetingTimeExhaustedError, RoomMode, RoomSessionEndedEvent, RtcClientConnectionStatusChangedPayload, RtcEvents, RtcLocalStreamTrackAddedPayload, RtcLocalStreamTrackRemovedPayload, RtcManager, RtcManagerCreatedPayload, RtcStreamAddedPayload, SDPRelayMessage, ScreenshareStartedEvent, ScreenshareStoppedEvent, SendClientMetadataRequest, SignalClient, SignalEvents, SignalKnocker, SignalRequests, SocketConf, SocketManager, Spotlight, SpotlightAddedEvent, SpotlightRemovedEvent, StatsMonitorOptions, StatsMonitorState, StatsSubscription, TurnTransportProtocol, UnifiedPlanSDP, UpdatedDeviceInfo, UpdatedDevicesInfo, VideoEnableRequest, VideoEnableRequestedEvent, VideoEnabledEvent };
package/dist/index.mjs CHANGED
@@ -1545,6 +1545,7 @@ var _a$6;
1545
1545
  const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
1546
1546
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1547
1547
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1548
+ const DISCONNECT_DURATION_LIMIT_MS = 60000;
1548
1549
  class ServerSocket {
1549
1550
  constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1550
1551
  this._wasConnectedUsingWebsocket = false;
@@ -1552,21 +1553,22 @@ class ServerSocket {
1552
1553
  this.disconnectDurationLimitExceeded = false;
1553
1554
  this._reconnectManager = null;
1554
1555
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1556
+ this._disconnectDurationLimitEnabled = false;
1555
1557
  this.joinRoomFinished = false;
1556
1558
  this._socket.io.on("reconnect", () => {
1557
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1559
+ if (this._disconnectDurationLimitOn &&
1560
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1558
1561
  this._socket.close();
1559
1562
  this.disconnectDurationLimitExceeded = true;
1560
- return;
1561
1563
  }
1562
1564
  this._socket.sendBuffer = [];
1563
1565
  });
1564
1566
  this._socket.io.on("reconnect_attempt", () => {
1565
1567
  var _a;
1566
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1568
+ if (this._disconnectDurationLimitOn &&
1569
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1567
1570
  this._socket.close();
1568
1571
  this.disconnectDurationLimitExceeded = true;
1569
- return;
1570
1572
  }
1571
1573
  if (this._wasConnectedUsingWebsocket) {
1572
1574
  this._socket.io.opts.transports = ["websocket"];
@@ -1590,25 +1592,30 @@ class ServerSocket {
1590
1592
  const transport = this.getTransport();
1591
1593
  if (transport === "websocket") {
1592
1594
  this._wasConnectedUsingWebsocket = true;
1593
- if (!this.noopKeepaliveInterval)
1595
+ if (!this.noopKeepaliveInterval) {
1596
+ let disconnectDurationLimitTimestampCandidate = Date.now();
1594
1597
  this.noopKeepaliveInterval = setInterval(() => {
1595
1598
  try {
1596
1599
  if (this._socket.connected) {
1597
- if (this._disconnectDurationLimitOn) {
1598
- this._noopKeepaliveTimestamp = Date.now();
1600
+ if (this._disconnectDurationLimitOn &&
1601
+ !this._didExceedDisconnectDurationLimit(disconnectDurationLimitTimestampCandidate)) {
1602
+ this._disconnectDurationLimitLatestTimestamp =
1603
+ disconnectDurationLimitTimestampCandidate;
1604
+ disconnectDurationLimitTimestampCandidate = Date.now();
1599
1605
  }
1600
1606
  this._socket.io.engine.sendPacket("noop");
1601
1607
  }
1602
1608
  }
1603
1609
  catch (ex) { }
1604
1610
  }, NOOP_KEEPALIVE_INTERVAL);
1611
+ }
1605
1612
  }
1606
1613
  });
1607
1614
  this._socket.on("disconnect", () => {
1608
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1615
+ if (this._disconnectDurationLimitOn &&
1616
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1609
1617
  this._socket.close();
1610
1618
  this.disconnectDurationLimitExceeded = true;
1611
- return;
1612
1619
  }
1613
1620
  this.joinRoomFinished = false;
1614
1621
  this.disconnectTimestamp = Date.now();
@@ -1618,20 +1625,18 @@ class ServerSocket {
1618
1625
  }
1619
1626
  });
1620
1627
  }
1621
- _didExceedDisconnectDurationLimit() {
1622
- if (!this._disconnectDurationLimitOn)
1623
- return false;
1624
- if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1625
- const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1626
- if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1627
- return true;
1628
- }
1628
+ _didExceedDisconnectDurationLimit(timestamp) {
1629
+ if (!timestamp || !this._disconnectDurationLimitOn || !this._disconnectDurationLimitEnabled)
1629
1630
  return false;
1631
+ const disconnectedDuration = Date.now() - timestamp;
1632
+ if (disconnectedDuration > DISCONNECT_DURATION_LIMIT_MS) {
1633
+ return true;
1630
1634
  }
1635
+ return false;
1631
1636
  }
1632
- setDisconnectDurationLimit(limitInMs) {
1637
+ enableDisconnectDurationLimit() {
1633
1638
  if (this._disconnectDurationLimitOn) {
1634
- this._disconnectDurationLimitInMs = limitInMs;
1639
+ this._disconnectDurationLimitEnabled = true;
1635
1640
  }
1636
1641
  }
1637
1642
  setRtcManager(rtcManager) {
@@ -2045,18 +2050,6 @@ function deprioritizeH264(sdp) {
2045
2050
  })
2046
2051
  .join("");
2047
2052
  }
2048
- function replaceSSRCs(currentDescription, newDescription) {
2049
- let ssrcs = currentDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2050
- let newssrcs = newDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2051
- if (!ssrcs) {
2052
- ssrcs = currentDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2053
- newssrcs = newDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2054
- }
2055
- for (let i = 1; i < ssrcs.length; i++) {
2056
- newDescription = newDescription.replace(new RegExp(newssrcs[i], "g"), ssrcs[i]);
2057
- }
2058
- return newDescription;
2059
- }
2060
2053
  function filterMidExtension(sdp) {
2061
2054
  if (browserName$2 !== "safari" &&
2062
2055
  (browserName$2 !== "firefox" || (browserVersion$1 && browserVersion$1 >= 63) || browserVersion$1 === 60)) {
@@ -2341,7 +2334,6 @@ class Session {
2341
2334
  return this.pc && this.pc.connectionState === "connected";
2342
2335
  }
2343
2336
  replaceTrack(oldTrack, newTrack) {
2344
- var _a, _b, _c;
2345
2337
  logger$7.info("replacetrack() [oldTrackId: %s, newTrackId: %s]", oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack === null || newTrack === void 0 ? void 0 : newTrack.id);
2346
2338
  if (!newTrack) {
2347
2339
  rtcStats.sendEvent("P2PReplaceTrackNoNewTrack", {
@@ -2362,55 +2354,38 @@ class Session {
2362
2354
  return false;
2363
2355
  }
2364
2356
  const pc = this.pc;
2365
- if ((_b = (_a = window.RTCRtpSender) === null || _a === void 0 ? void 0 : _a.prototype) === null || _b === void 0 ? void 0 : _b.replaceTrack) {
2366
- if (oldTrack) {
2367
- const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2368
- if (sender) {
2369
- sender.replaceTrack(newTrack);
2370
- return Promise.resolve(newTrack);
2371
- }
2372
- }
2373
- const sender = pc.getSenders().find((s) => {
2374
- const track = s.track;
2375
- return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2376
- });
2357
+ if (oldTrack) {
2358
+ const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2377
2359
  if (sender) {
2378
- this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2379
- const track = sender.track;
2380
- rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2381
- targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2382
- targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2383
- targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2384
- targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2385
- newTrackId: newTrack.id,
2386
- newTrackKind: newTrack.kind,
2387
- newTrackIsEffect: newTrack.effectTrack,
2388
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2389
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2390
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2391
- });
2392
2360
  sender.replaceTrack(newTrack);
2393
2361
  return Promise.resolve(newTrack);
2394
2362
  }
2395
- let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2396
- if (!stream) {
2397
- rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2398
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2399
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2400
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2401
- newTrackId: newTrack.id,
2402
- newTrackKind: newTrack.kind,
2403
- newTrackIsEffect: newTrack.effectTrack,
2404
- });
2405
- this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2406
- }
2407
- stream = this.streams[0];
2408
- if (!stream) {
2409
- rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2410
- this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2411
- return Promise.reject(new Error("replaceTrack: No stream?"));
2412
- }
2413
- rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2363
+ }
2364
+ const sender = pc.getSenders().find((s) => {
2365
+ const track = s.track;
2366
+ return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2367
+ });
2368
+ if (sender) {
2369
+ this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2370
+ const track = sender.track;
2371
+ rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2372
+ targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2373
+ targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2374
+ targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2375
+ targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2376
+ newTrackId: newTrack.id,
2377
+ newTrackKind: newTrack.kind,
2378
+ newTrackIsEffect: newTrack.effectTrack,
2379
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2380
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2381
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2382
+ });
2383
+ sender.replaceTrack(newTrack);
2384
+ return Promise.resolve(newTrack);
2385
+ }
2386
+ let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2387
+ if (!stream) {
2388
+ rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2414
2389
  oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2415
2390
  oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2416
2391
  oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
@@ -2418,49 +2393,24 @@ class Session {
2418
2393
  newTrackKind: newTrack.kind,
2419
2394
  newTrackIsEffect: newTrack.effectTrack,
2420
2395
  });
2421
- this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2422
- return pc.addTrack(newTrack, stream);
2423
- }
2424
- rtcStats.sendEvent("P2PNoReplaceTrackSupport", {});
2425
- if (!this.canModifyPeerConnection()) {
2426
- this.pending.push(() => {
2427
- this.replaceTrack(oldTrack, newTrack);
2428
- });
2429
- return;
2430
- }
2431
- this.isOperationPending = true;
2432
- const onn = pc.onnegotiationneeded;
2433
- pc.onnegotiationneeded = null;
2434
- if (oldTrack) {
2435
- this.removeTrack(oldTrack);
2436
- }
2437
- this.addTrack(newTrack);
2438
- setTimeout(() => {
2439
- pc.onnegotiationneeded = onn;
2440
- }, 0);
2441
- if (((_c = pc.localDescription) === null || _c === void 0 ? void 0 : _c.type) === "offer") {
2442
- return pc
2443
- .createOffer()
2444
- .then((offer) => {
2445
- var _a;
2446
- offer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, offer.sdp);
2447
- return pc.setLocalDescription(offer);
2448
- })
2449
- .then(() => {
2450
- return this._setRemoteDescription(pc.remoteDescription);
2451
- });
2452
- }
2453
- else {
2454
- return this._setRemoteDescription(pc.remoteDescription)
2455
- .then(() => {
2456
- return pc.createAnswer();
2457
- })
2458
- .then((answer) => {
2459
- var _a;
2460
- answer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, answer.sdp);
2461
- return pc.setLocalDescription(answer);
2462
- });
2396
+ this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2463
2397
  }
2398
+ stream = this.streams[0];
2399
+ if (!stream) {
2400
+ rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2401
+ this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2402
+ return Promise.reject(new Error("replaceTrack: No stream?"));
2403
+ }
2404
+ rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2405
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2406
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2407
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2408
+ newTrackId: newTrack.id,
2409
+ newTrackKind: newTrack.kind,
2410
+ newTrackIsEffect: newTrack.effectTrack,
2411
+ });
2412
+ this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2413
+ return pc.addTrack(newTrack, stream);
2464
2414
  }
2465
2415
  changeBandwidth(bandwidth) {
2466
2416
  var _a;
@@ -7545,4 +7495,4 @@ var RtcEventNames;
7545
7495
  RtcEventNames["stream_added"] = "stream_added";
7546
7496
  })(RtcEventNames || (RtcEventNames = {}));
7547
7497
 
7548
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
7498
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
@@ -1545,6 +1545,7 @@ var _a$6;
1545
1545
  const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
1546
1546
  const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";
1547
1547
  const NOOP_KEEPALIVE_INTERVAL = 2000;
1548
+ const DISCONNECT_DURATION_LIMIT_MS = 60000;
1548
1549
  class ServerSocket {
1549
1550
  constructor(hostName, optionsOverrides, glitchFree = false, disconnectDurationLimitOn = false) {
1550
1551
  this._wasConnectedUsingWebsocket = false;
@@ -1552,21 +1553,22 @@ class ServerSocket {
1552
1553
  this.disconnectDurationLimitExceeded = false;
1553
1554
  this._reconnectManager = null;
1554
1555
  this._socket = io(hostName, Object.assign({ path: DEFAULT_SOCKET_PATH, randomizationFactor: 0.5, reconnectionDelay: 250, reconnectionDelayMax: 5000, timeout: 5000, transports: ["websocket"], withCredentials: true }, optionsOverrides));
1556
+ this._disconnectDurationLimitEnabled = false;
1555
1557
  this.joinRoomFinished = false;
1556
1558
  this._socket.io.on("reconnect", () => {
1557
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1559
+ if (this._disconnectDurationLimitOn &&
1560
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1558
1561
  this._socket.close();
1559
1562
  this.disconnectDurationLimitExceeded = true;
1560
- return;
1561
1563
  }
1562
1564
  this._socket.sendBuffer = [];
1563
1565
  });
1564
1566
  this._socket.io.on("reconnect_attempt", () => {
1565
1567
  var _a;
1566
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1568
+ if (this._disconnectDurationLimitOn &&
1569
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1567
1570
  this._socket.close();
1568
1571
  this.disconnectDurationLimitExceeded = true;
1569
- return;
1570
1572
  }
1571
1573
  if (this._wasConnectedUsingWebsocket) {
1572
1574
  this._socket.io.opts.transports = ["websocket"];
@@ -1590,25 +1592,30 @@ class ServerSocket {
1590
1592
  const transport = this.getTransport();
1591
1593
  if (transport === "websocket") {
1592
1594
  this._wasConnectedUsingWebsocket = true;
1593
- if (!this.noopKeepaliveInterval)
1595
+ if (!this.noopKeepaliveInterval) {
1596
+ let disconnectDurationLimitTimestampCandidate = Date.now();
1594
1597
  this.noopKeepaliveInterval = setInterval(() => {
1595
1598
  try {
1596
1599
  if (this._socket.connected) {
1597
- if (this._disconnectDurationLimitOn) {
1598
- this._noopKeepaliveTimestamp = Date.now();
1600
+ if (this._disconnectDurationLimitOn &&
1601
+ !this._didExceedDisconnectDurationLimit(disconnectDurationLimitTimestampCandidate)) {
1602
+ this._disconnectDurationLimitLatestTimestamp =
1603
+ disconnectDurationLimitTimestampCandidate;
1604
+ disconnectDurationLimitTimestampCandidate = Date.now();
1599
1605
  }
1600
1606
  this._socket.io.engine.sendPacket("noop");
1601
1607
  }
1602
1608
  }
1603
1609
  catch (ex) { }
1604
1610
  }, NOOP_KEEPALIVE_INTERVAL);
1611
+ }
1605
1612
  }
1606
1613
  });
1607
1614
  this._socket.on("disconnect", () => {
1608
- if (this._disconnectDurationLimitOn && this._didExceedDisconnectDurationLimit()) {
1615
+ if (this._disconnectDurationLimitOn &&
1616
+ this._didExceedDisconnectDurationLimit(this._disconnectDurationLimitLatestTimestamp)) {
1609
1617
  this._socket.close();
1610
1618
  this.disconnectDurationLimitExceeded = true;
1611
- return;
1612
1619
  }
1613
1620
  this.joinRoomFinished = false;
1614
1621
  this.disconnectTimestamp = Date.now();
@@ -1618,20 +1625,18 @@ class ServerSocket {
1618
1625
  }
1619
1626
  });
1620
1627
  }
1621
- _didExceedDisconnectDurationLimit() {
1622
- if (!this._disconnectDurationLimitOn)
1623
- return false;
1624
- if (this._disconnectDurationLimitInMs && this._noopKeepaliveTimestamp) {
1625
- const disconnectedDuration = Date.now() - this._noopKeepaliveTimestamp;
1626
- if (disconnectedDuration > this._disconnectDurationLimitInMs) {
1627
- return true;
1628
- }
1628
+ _didExceedDisconnectDurationLimit(timestamp) {
1629
+ if (!timestamp || !this._disconnectDurationLimitOn || !this._disconnectDurationLimitEnabled)
1629
1630
  return false;
1631
+ const disconnectedDuration = Date.now() - timestamp;
1632
+ if (disconnectedDuration > DISCONNECT_DURATION_LIMIT_MS) {
1633
+ return true;
1630
1634
  }
1635
+ return false;
1631
1636
  }
1632
- setDisconnectDurationLimit(limitInMs) {
1637
+ enableDisconnectDurationLimit() {
1633
1638
  if (this._disconnectDurationLimitOn) {
1634
- this._disconnectDurationLimitInMs = limitInMs;
1639
+ this._disconnectDurationLimitEnabled = true;
1635
1640
  }
1636
1641
  }
1637
1642
  setRtcManager(rtcManager) {
@@ -2045,18 +2050,6 @@ function deprioritizeH264(sdp) {
2045
2050
  })
2046
2051
  .join("");
2047
2052
  }
2048
- function replaceSSRCs(currentDescription, newDescription) {
2049
- let ssrcs = currentDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2050
- let newssrcs = newDescription.match(/a=ssrc-group:FID (\d+) (\d+)\r\n/);
2051
- if (!ssrcs) {
2052
- ssrcs = currentDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2053
- newssrcs = newDescription.match(/a=ssrc:(\d+) cname:(.*)\r\n/g)[1].match(/a=ssrc:(\d+)/);
2054
- }
2055
- for (let i = 1; i < ssrcs.length; i++) {
2056
- newDescription = newDescription.replace(new RegExp(newssrcs[i], "g"), ssrcs[i]);
2057
- }
2058
- return newDescription;
2059
- }
2060
2053
  function filterMidExtension(sdp) {
2061
2054
  if (browserName$2 !== "safari" &&
2062
2055
  (browserName$2 !== "firefox" || (browserVersion$1 && browserVersion$1 >= 63) || browserVersion$1 === 60)) {
@@ -2341,7 +2334,6 @@ class Session {
2341
2334
  return this.pc && this.pc.connectionState === "connected";
2342
2335
  }
2343
2336
  replaceTrack(oldTrack, newTrack) {
2344
- var _a, _b, _c;
2345
2337
  logger$7.info("replacetrack() [oldTrackId: %s, newTrackId: %s]", oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id, newTrack === null || newTrack === void 0 ? void 0 : newTrack.id);
2346
2338
  if (!newTrack) {
2347
2339
  rtcStats.sendEvent("P2PReplaceTrackNoNewTrack", {
@@ -2362,55 +2354,38 @@ class Session {
2362
2354
  return false;
2363
2355
  }
2364
2356
  const pc = this.pc;
2365
- if ((_b = (_a = window.RTCRtpSender) === null || _a === void 0 ? void 0 : _a.prototype) === null || _b === void 0 ? void 0 : _b.replaceTrack) {
2366
- if (oldTrack) {
2367
- const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2368
- if (sender) {
2369
- sender.replaceTrack(newTrack);
2370
- return Promise.resolve(newTrack);
2371
- }
2372
- }
2373
- const sender = pc.getSenders().find((s) => {
2374
- const track = s.track;
2375
- return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2376
- });
2357
+ if (oldTrack) {
2358
+ const sender = pc.getSenders().find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.id) === oldTrack.id; });
2377
2359
  if (sender) {
2378
- this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2379
- const track = sender.track;
2380
- rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2381
- targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2382
- targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2383
- targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2384
- targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2385
- newTrackId: newTrack.id,
2386
- newTrackKind: newTrack.kind,
2387
- newTrackIsEffect: newTrack.effectTrack,
2388
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2389
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2390
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2391
- });
2392
2360
  sender.replaceTrack(newTrack);
2393
2361
  return Promise.resolve(newTrack);
2394
2362
  }
2395
- let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2396
- if (!stream) {
2397
- rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2398
- oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2399
- oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2400
- oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2401
- newTrackId: newTrack.id,
2402
- newTrackKind: newTrack.kind,
2403
- newTrackIsEffect: newTrack.effectTrack,
2404
- });
2405
- this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2406
- }
2407
- stream = this.streams[0];
2408
- if (!stream) {
2409
- rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2410
- this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2411
- return Promise.reject(new Error("replaceTrack: No stream?"));
2412
- }
2413
- rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2363
+ }
2364
+ const sender = pc.getSenders().find((s) => {
2365
+ const track = s.track;
2366
+ return (track === null || track === void 0 ? void 0 : track.kind) === newTrack.kind && !trackAnnotations(track).fromGetDisplayMedia;
2367
+ });
2368
+ if (sender) {
2369
+ this._incrementAnalyticMetric("P2PReplaceTrackOldTrackNotFound");
2370
+ const track = sender.track;
2371
+ rtcStats.sendEvent("P2PReplaceTrackOldTrackNotFound", {
2372
+ targetTrackId: track === null || track === void 0 ? void 0 : track.id,
2373
+ targetTrackKind: track === null || track === void 0 ? void 0 : track.kind,
2374
+ targetTrackIsEffect: track === null || track === void 0 ? void 0 : track.effectTrack,
2375
+ targetTrackReadyState: track === null || track === void 0 ? void 0 : track.readyState,
2376
+ newTrackId: newTrack.id,
2377
+ newTrackKind: newTrack.kind,
2378
+ newTrackIsEffect: newTrack.effectTrack,
2379
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2380
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2381
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2382
+ });
2383
+ sender.replaceTrack(newTrack);
2384
+ return Promise.resolve(newTrack);
2385
+ }
2386
+ let stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id));
2387
+ if (!stream) {
2388
+ rtcStats.sendEvent("P2PReplaceTrackNewTrackNotInStream", {
2414
2389
  oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2415
2390
  oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2416
2391
  oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
@@ -2418,49 +2393,24 @@ class Session {
2418
2393
  newTrackKind: newTrack.kind,
2419
2394
  newTrackIsEffect: newTrack.effectTrack,
2420
2395
  });
2421
- this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2422
- return pc.addTrack(newTrack, stream);
2423
- }
2424
- rtcStats.sendEvent("P2PNoReplaceTrackSupport", {});
2425
- if (!this.canModifyPeerConnection()) {
2426
- this.pending.push(() => {
2427
- this.replaceTrack(oldTrack, newTrack);
2428
- });
2429
- return;
2430
- }
2431
- this.isOperationPending = true;
2432
- const onn = pc.onnegotiationneeded;
2433
- pc.onnegotiationneeded = null;
2434
- if (oldTrack) {
2435
- this.removeTrack(oldTrack);
2436
- }
2437
- this.addTrack(newTrack);
2438
- setTimeout(() => {
2439
- pc.onnegotiationneeded = onn;
2440
- }, 0);
2441
- if (((_c = pc.localDescription) === null || _c === void 0 ? void 0 : _c.type) === "offer") {
2442
- return pc
2443
- .createOffer()
2444
- .then((offer) => {
2445
- var _a;
2446
- offer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, offer.sdp);
2447
- return pc.setLocalDescription(offer);
2448
- })
2449
- .then(() => {
2450
- return this._setRemoteDescription(pc.remoteDescription);
2451
- });
2452
- }
2453
- else {
2454
- return this._setRemoteDescription(pc.remoteDescription)
2455
- .then(() => {
2456
- return pc.createAnswer();
2457
- })
2458
- .then((answer) => {
2459
- var _a;
2460
- answer.sdp = replaceSSRCs((_a = pc.localDescription) === null || _a === void 0 ? void 0 : _a.sdp, answer.sdp);
2461
- return pc.setLocalDescription(answer);
2462
- });
2396
+ this._incrementAnalyticMetric("P2PReplaceTrackNewTrackNotInStream");
2463
2397
  }
2398
+ stream = this.streams[0];
2399
+ if (!stream) {
2400
+ rtcStats.sendEvent("P2PReplaceTrackNoStream", {});
2401
+ this._incrementAnalyticMetric("P2PReplaceTrackNoStream");
2402
+ return Promise.reject(new Error("replaceTrack: No stream?"));
2403
+ }
2404
+ rtcStats.sendEvent("P2PReplaceTrackSourceKindNotFound", {
2405
+ oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
2406
+ oldTrackKind: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.kind,
2407
+ oldTrackIsEffect: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.effectTrack,
2408
+ newTrackId: newTrack.id,
2409
+ newTrackKind: newTrack.kind,
2410
+ newTrackIsEffect: newTrack.effectTrack,
2411
+ });
2412
+ this._incrementAnalyticMetric("P2PReplaceTrackSourceKindNotFound");
2413
+ return pc.addTrack(newTrack, stream);
2464
2414
  }
2465
2415
  changeBandwidth(bandwidth) {
2466
2416
  var _a;
@@ -7545,5 +7495,5 @@ var RtcEventNames;
7545
7495
  RtcEventNames["stream_added"] = "stream_added";
7546
7496
  })(RtcEventNames || (RtcEventNames = {}));
7547
7497
 
7548
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceSSRCs, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
7498
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, EVENTS, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, RtcStream, SCREEN_SHARE_SETTINGS, SCREEN_SHARE_SIMULCAST_SETTINGS, STREAM_TYPES, ServerSocket, Session, SfuV2Parser, TYPES, VIDEO_SETTINGS_HD, VIDEO_SETTINGS_SD, VIDEO_SETTINGS_VP9, VIDEO_SETTINGS_VP9_LOW_BANDWIDTH, VegaConnection, VegaMediaQualityMonitor, VegaRtcManager, addAbsCaptureTimeExtMap, addExtMap, assert, buildDeviceList, calculateStd, captureAudioSsrcMetrics, captureCandidatePairInfoMetrics, captureCommonSsrcMetrics, captureSsrcInfo, captureVideoSsrcMetrics, changeMediaDirection, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isMobile, issueDetectorOrMetricEnabled, maybeRejectNoH264, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, variance };
7549
7499
  //# 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": "2.7.0",
4
+ "version": "2.7.2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {
@@ -62,9 +62,9 @@
62
62
  "process": "^0.11.10",
63
63
  "typescript": "^5.8.3",
64
64
  "@whereby.com/eslint-config": "0.1.0",
65
- "@whereby.com/jest-config": "0.1.0",
66
65
  "@whereby.com/prettier-config": "0.1.0",
67
66
  "@whereby.com/rollup-config": "0.1.1",
67
+ "@whereby.com/jest-config": "0.1.0",
68
68
  "@whereby.com/tsconfig": "0.1.0"
69
69
  },
70
70
  "engines": {