@whereby.com/media 9.7.4 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -44,8 +44,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
44
44
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
45
  };
46
46
 
47
- var _a$7;
48
- (_a$7 = adapterRaw.default) !== null && _a$7 !== void 0 ? _a$7 : adapterRaw;
47
+ var _a$6;
48
+ (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
49
49
  const RTCSTATS_PROTOCOL_VERSION = "1.0";
50
50
  const GETSTATS_BUFFER_SIZE = 20;
51
51
  const clientInfo = {
@@ -288,11 +288,11 @@ class Logger {
288
288
  }
289
289
  }
290
290
 
291
- var _a$6, _b$2;
292
- const adapter$6 = (_a$6 = adapterRaw.default) !== null && _a$6 !== void 0 ? _a$6 : adapterRaw;
291
+ var _a$5, _b$2;
292
+ const adapter$5 = (_a$5 = adapterRaw.default) !== null && _a$5 !== void 0 ? _a$5 : adapterRaw;
293
293
  const logger$b = new Logger();
294
- const browserName$2 = (_b$2 = adapter$6.browserDetails) === null || _b$2 === void 0 ? void 0 : _b$2.browser;
295
- const browserVersion$1 = adapter$6.browserDetails.version;
294
+ const browserName$2 = (_b$2 = adapter$5.browserDetails) === null || _b$2 === void 0 ? void 0 : _b$2.browser;
295
+ const browserVersion$1 = adapter$5.browserDetails.version;
296
296
  function setCodecPreferenceSDP({ sdp, redOn }) {
297
297
  var _a, _b;
298
298
  try {
@@ -480,8 +480,8 @@ function trackAnnotations(o) {
480
480
  return props;
481
481
  }
482
482
 
483
- var _a$5;
484
- const adapter$5 = (_a$5 = adapterRaw.default) !== null && _a$5 !== void 0 ? _a$5 : adapterRaw;
483
+ var _a$4;
484
+ const adapter$4 = (_a$4 = adapterRaw.default) !== null && _a$4 !== void 0 ? _a$4 : adapterRaw;
485
485
  const logger$a = new Logger();
486
486
  class Session {
487
487
  constructor({ clientId, bandwidth, peerConnectionConfig, deprioritizeH264Encoding, incrementAnalyticMetric, mediaPrefs, }) {
@@ -638,7 +638,7 @@ class Session {
638
638
  if (this.pc.signalingState === "closed") {
639
639
  return;
640
640
  }
641
- if (((_a = adapter$5.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) === "safari" && candidate && candidate.candidate === "") {
641
+ if (((_a = adapter$4.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) === "safari" && candidate && candidate.candidate === "") {
642
642
  return;
643
643
  }
644
644
  this.pc.addIceCandidate(candidate).catch((e) => {
@@ -751,39 +751,6 @@ class Session {
751
751
 
752
752
  const MEDIA_JITTER_BUFFER_TARGET = 400;
753
753
 
754
- var _a$4;
755
- const adapter$4 = (_a$4 = adapterRaw.default) !== null && _a$4 !== void 0 ? _a$4 : adapterRaw;
756
- function detectMicrophoneNotWorking(pc) {
757
- var _a, _b;
758
- if (((_a = adapter$4.browserDetails) === null || _a === void 0 ? void 0 : _a.browser) !== "chrome" ||
759
- ((_b = adapter$4.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) < 58 ||
760
- pc.signalingState === "closed") {
761
- return Promise.resolve("");
762
- }
763
- const sendingAudio = pc.getSenders().some((sender) => { var _a; return ((_a = sender.track) === null || _a === void 0 ? void 0 : _a.kind) === "audio"; });
764
- const receivingAudio = pc.getReceivers().some((receiver) => { var _a; return ((_a = receiver.track) === null || _a === void 0 ? void 0 : _a.kind) === "audio"; });
765
- return pc.getStats(null).then((result) => {
766
- let microphoneFailed = "";
767
- result.forEach((report) => {
768
- if (report.type === "outbound-rtp" &&
769
- (report.kind === "audio" || report.mediaType === "audio") &&
770
- sendingAudio) {
771
- if (report.bytesSent === 0) {
772
- microphoneFailed = "outbound";
773
- }
774
- }
775
- else if (report.type === "inbound-rtp" &&
776
- (report.kind === "audio" || report.mediaType === "audio") &&
777
- receivingAudio) {
778
- if (report.bytesReceived === 0) {
779
- microphoneFailed = "inbound";
780
- }
781
- }
782
- });
783
- return microphoneFailed;
784
- });
785
- }
786
-
787
754
  const PROTOCOL_REQUESTS = {
788
755
  BLOCK_CLIENT: "block_client",
789
756
  CANCEL_ROOM_KNOCK: "cancel_room_knock",
@@ -972,9 +939,7 @@ ipRegex.v4 = (options) => options && options.exact ? v4exact : new RegExp(`${bou
972
939
  ipRegex.v6 = (options) => options && options.exact ? v6exact : new RegExp(`${boundry(options)}${v6}${boundry(options)}`, "g");
973
940
 
974
941
  var rtcManagerEvents = {
975
- CAMERA_NOT_WORKING: "camera_not_working",
976
942
  CONNECTION_BLOCKED_BY_NETWORK: "connection_blocked_by_network",
977
- MICROPHONE_NOT_WORKING: "microphone_not_working",
978
943
  MICROPHONE_STOPPED_WORKING: "microphone_stopped_working",
979
944
  CAMERA_STOPPED_WORKING: "camera_stopped_working",
980
945
  NEW_PC: "new_pc",
@@ -2430,79 +2395,11 @@ fromLocation(typeof window !== "undefined" ? window.location : undefined);
2430
2395
 
2431
2396
  var _a$2, _b$1;
2432
2397
  const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
2433
- const isSafari = ((_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser) === "safari";
2434
- const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
2435
- function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
2436
- var _a, _b;
2437
- let HIGH_HEIGHT = 480;
2438
- let LOW_HEIGHT = 240;
2439
- if (hd) {
2440
- HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
2441
- }
2442
- if (simulcast) {
2443
- if (hd === false) {
2444
- HIGH_HEIGHT = 360;
2445
- LOW_HEIGHT = 270;
2446
- }
2447
- else {
2448
- LOW_HEIGHT = 360;
2449
- }
2450
- }
2451
- const constraints = {
2452
- audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
2453
- video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
2454
- };
2455
- if (lax) {
2456
- if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
2457
- constraints.audio = true;
2458
- (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
2459
- return constraints;
2460
- }
2461
- if (resolution) {
2462
- const [w, h, fps] = parseResolution(resolution);
2463
- if (w)
2464
- constraints.video.width = { exact: w };
2465
- if (h)
2466
- constraints.video.height = { exact: h };
2467
- if (fps)
2468
- constraints.video.frameRate = { exact: fps };
2469
- delete constraints.video.facingMode;
2470
- }
2471
- else {
2472
- constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
2473
- }
2474
- if (disableAGC)
2475
- constraints.audio.autoGainControl = false;
2476
- if (disableAEC)
2477
- constraints.audio.echoCancellation = false;
2478
- return constraints;
2479
- }
2480
- function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
2481
- const strict = !!devices;
2482
- const audioDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "audioinput");
2483
- const videoDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "videoinput");
2484
- const useDefaultAudio = !audioId || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.some((d) => d.deviceId === audioId)));
2485
- const useDefaultVideo = !videoId || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.some((d) => d.deviceId === videoId)));
2486
- const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
2487
- audioId: useDefaultAudio ? null : { [type]: audioId },
2488
- videoId: useDefaultVideo ? null : { [type]: videoId },
2489
- } }, options));
2490
- if (audioId === false || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.length))) {
2491
- delete constraints.audio;
2492
- }
2493
- if (videoId === false || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.length))) {
2494
- delete constraints.video;
2495
- }
2496
- return constraints;
2497
- }
2498
-
2499
- var _a$1, _b;
2500
- const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
2501
2398
  const logger$6 = new Logger();
2502
2399
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2503
2400
  const ICE_RESTART_DELAY = 2 * 1000;
2504
- const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
2505
- const browserVersion = adapter$1.browserDetails.version;
2401
+ const browserName$1 = (_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser;
2402
+ const browserVersion = adapter$2.browserDetails.version;
2506
2403
  let unloading$1 = false;
2507
2404
  if (browserName$1 === "chrome") {
2508
2405
  window.document.addEventListener("beforeunload", () => {
@@ -2528,7 +2425,6 @@ class P2pRtcManager {
2528
2425
  this._closed = false;
2529
2426
  this._videoTrackIdByStreamId = {};
2530
2427
  this._fetchMediaServersTimer = null;
2531
- this._stopCameraTimeout = null;
2532
2428
  this._icePublicIPGatheringTimeoutID = null;
2533
2429
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
2534
2430
  this._audioTrackOnEnded = () => {
@@ -2548,7 +2444,6 @@ class P2pRtcManager {
2548
2444
  });
2549
2445
  this.analytics = {
2550
2446
  P2POffendingInitialOffer: 0,
2551
- P2PNonErrorRejectionValueGUMError: 0,
2552
2447
  numNewPc: 0,
2553
2448
  numIceConnected: 0,
2554
2449
  numIceDisconnected: 0,
@@ -2569,7 +2464,6 @@ class P2pRtcManager {
2569
2464
  P2PReplaceTrackNoStream: 0,
2570
2465
  P2PReplaceTrackNewTrackNotInStream: 0,
2571
2466
  P2POnTrackNoStream: 0,
2572
- P2PMicNotWorking: 0,
2573
2467
  P2PLocalNetworkFailed: 0,
2574
2468
  P2PRelayedIceCandidate: 0,
2575
2469
  P2PAddIceCandidateFailure: 0,
@@ -2581,9 +2475,8 @@ class P2pRtcManager {
2581
2475
  isInitializedWith({ selfId, roomName, isSfu }) {
2582
2476
  return this._selfId === selfId && this._roomName === roomName && !isSfu;
2583
2477
  }
2584
- addCameraStream(stream, { videoPaused, beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
2478
+ addCameraStream(stream, { beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
2585
2479
  logger$6.info("addCameraStream: [stream.id: %s]", stream.id);
2586
- this._webcamPaused = videoPaused;
2587
2480
  if (stream === this._localCameraStream) {
2588
2481
  return;
2589
2482
  }
@@ -3077,14 +2970,6 @@ class P2pRtcManager {
3077
2970
  logger$6.info(`connectionState changed to ${pc.connectionState} for session ${session.clientId}`);
3078
2971
  switch (pc.connectionState) {
3079
2972
  case "connected":
3080
- setTimeout(() => {
3081
- detectMicrophoneNotWorking(session.pc).then((failureDirection) => {
3082
- if (failureDirection) {
3083
- this.analytics.P2PMicNotWorking++;
3084
- rtcStats.sendEvent("P2PMicNotWorking", { clientId, failureDirection });
3085
- }
3086
- });
3087
- }, 3000);
3088
2973
  (_a = session.registerConnected) === null || _a === void 0 ? void 0 : _a.call(session, {});
3089
2974
  break;
3090
2975
  case "failed":
@@ -3460,65 +3345,7 @@ class P2pRtcManager {
3460
3345
  }
3461
3346
  }
3462
3347
  }
3463
- stopOrResumeVideo(localStream, enable) {
3464
- var _a;
3465
- logger$6.info("stopOrResumeVideo() [enable: %s]", enable);
3466
- this._webcamPaused = !enable;
3467
- if (!["chrome", "safari"].includes(browserName$1)) {
3468
- return;
3469
- }
3470
- if (this._stopCameraTimeout) {
3471
- clearTimeout(this._stopCameraTimeout);
3472
- this._stopCameraTimeout = null;
3473
- }
3474
- if (enable === false) {
3475
- const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended" ? 0 : 5000;
3476
- this._stopCameraTimeout = setTimeout(() => {
3477
- localStream.getVideoTracks().forEach((track) => {
3478
- if (track.enabled === false) {
3479
- track.stop();
3480
- localStream.removeTrack(track);
3481
- this._emit(EVENTS.LOCAL_STREAM_TRACK_REMOVED, {
3482
- stream: localStream,
3483
- track,
3484
- });
3485
- this._handleStopOrResumeVideo({ enable, track });
3486
- }
3487
- });
3488
- }, stopCameraDelay);
3489
- }
3490
- else {
3491
- if (localStream.getVideoTracks().length === 0) {
3492
- const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
3493
- if (!constraints) {
3494
- return;
3495
- }
3496
- navigator.mediaDevices
3497
- .getUserMedia({ video: constraints })
3498
- .then((stream) => {
3499
- const track = stream.getVideoTracks()[0];
3500
- if (this._webcamPaused) {
3501
- track.stop();
3502
- return;
3503
- }
3504
- localStream.addTrack(track);
3505
- this._monitorVideoTrack(track);
3506
- this._emit(EVENTS.LOCAL_STREAM_TRACK_ADDED, {
3507
- streamId: localStream.id,
3508
- tracks: [track],
3509
- screenShare: false,
3510
- });
3511
- this._handleStopOrResumeVideo({ enable, track });
3512
- })
3513
- .catch((e) => {
3514
- if (!(e instanceof Error)) {
3515
- this.analytics.P2PNonErrorRejectionValueGUMError++;
3516
- e = new Error(`non-error gUM rejection value: ${JSON.stringify(e)}`);
3517
- }
3518
- throw e;
3519
- });
3520
- }
3521
- }
3348
+ stopOrResumeVideo() {
3522
3349
  }
3523
3350
  removeScreenshareStream(stream, { requestedByClientId } = {}) {
3524
3351
  logger$6.info("removeScreenshareStream() [stream.id: %s, requestedByClientId: %s]", stream.id, requestedByClientId);
@@ -4386,10 +4213,10 @@ const STREAM_TYPES = {
4386
4213
  screenshare: "screenshare",
4387
4214
  };
4388
4215
 
4389
- var _a;
4390
- const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4216
+ var _a$1;
4217
+ const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4391
4218
  const logger$2 = new Logger();
4392
- const browserName = adapter.browserDetails.browser;
4219
+ const browserName = adapter$1.browserDetails.browser;
4393
4220
  let unloading = false;
4394
4221
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4395
4222
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -4440,7 +4267,6 @@ class VegaRtcManager {
4440
4267
  this._sndTransportIceRestartPromise = null;
4441
4268
  this._rcvTransportIceRestartPromise = null;
4442
4269
  this._colocation = null;
4443
- this._stopCameraTimeout = null;
4444
4270
  this._audioTrackOnEnded = () => {
4445
4271
  rtcStats.sendEvent("audio_ended", { unloading });
4446
4272
  this._emitToPWA(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -4483,7 +4309,6 @@ class VegaRtcManager {
4483
4309
  vegaIceRestarts: 0,
4484
4310
  vegaIceRestartMissingTransport: 0,
4485
4311
  vegaIceRestartWrongTransportId: 0,
4486
- vegaNonErrorRejectionValueGUMError: 0,
4487
4312
  vegaReplaceTrackNoProducerNoEnabledTrack: 0,
4488
4313
  vegaMicProducerFailed: 0,
4489
4314
  vegaWebcamProducerFailed: 0,
@@ -5533,9 +5358,9 @@ class VegaRtcManager {
5533
5358
  return;
5534
5359
  }
5535
5360
  }
5536
- stopOrResumeAudio(stream, enabled) {
5537
- logger$2.info("stopOrResumeAudio() [enabled:%s]", enabled);
5538
- this._micPaused = !enabled;
5361
+ stopOrResumeAudio({ enable }) {
5362
+ logger$2.info("stopOrResumeAudio() [enable:%s]", enable);
5363
+ this._micPaused = !enable;
5539
5364
  this._pauseResumeMic();
5540
5365
  }
5541
5366
  _handleStopOrResumeVideo({ enable, track }) {
@@ -5550,61 +5375,10 @@ class VegaRtcManager {
5550
5375
  this._sendWebcam(track);
5551
5376
  }
5552
5377
  }
5553
- stopOrResumeVideo(localStream, enable) {
5554
- var _a;
5378
+ stopOrResumeVideo({ enable }) {
5555
5379
  logger$2.info("stopOrResumeVideo() [enable:%s]", enable);
5556
5380
  this._webcamPaused = !enable;
5557
5381
  this._pauseResumeWebcam();
5558
- if (!["chrome", "safari"].includes(browserName)) {
5559
- return;
5560
- }
5561
- if (this._stopCameraTimeout) {
5562
- clearTimeout(this._stopCameraTimeout);
5563
- this._stopCameraTimeout = null;
5564
- }
5565
- if (!enable) {
5566
- const stopCameraDelay = ((_a = localStream.getVideoTracks().find((t) => !t.enabled)) === null || _a === void 0 ? void 0 : _a.readyState) === "ended" ? 0 : 5000;
5567
- this._stopCameraTimeout = setTimeout(() => {
5568
- localStream.getVideoTracks().forEach((track) => {
5569
- if (track.enabled === false) {
5570
- track.stop();
5571
- localStream.removeTrack(track);
5572
- this._emitToPWA(EVENTS.LOCAL_STREAM_TRACK_REMOVED, {
5573
- stream: localStream,
5574
- track,
5575
- });
5576
- this._handleStopOrResumeVideo({ enable, track });
5577
- }
5578
- });
5579
- }, stopCameraDelay);
5580
- }
5581
- else if (localStream.getVideoTracks().length === 0) {
5582
- const constraints = getConstraints(this._webrtcProvider.getMediaOptions()).video;
5583
- navigator.mediaDevices
5584
- .getUserMedia({ video: constraints })
5585
- .then((stream) => {
5586
- const track = stream.getVideoTracks()[0];
5587
- if (this._webcamPaused) {
5588
- track.stop();
5589
- return;
5590
- }
5591
- localStream.addTrack(track);
5592
- this._monitorVideoTrack(track);
5593
- this._emitToPWA(EVENTS.LOCAL_STREAM_TRACK_ADDED, {
5594
- streamId: localStream.id,
5595
- tracks: [track],
5596
- screenShare: false,
5597
- });
5598
- this._handleStopOrResumeVideo({ enable, track });
5599
- })
5600
- .catch((e) => {
5601
- if (!(e instanceof Error)) {
5602
- this.analytics.vegaNonErrorRejectionValueGUMError++;
5603
- e = new Error(`non-error gUM rejection value: ${JSON.stringify(e)}`);
5604
- }
5605
- throw e;
5606
- });
5607
- }
5608
5382
  }
5609
5383
  acceptNewStream({ streamId, clientId }) {
5610
5384
  logger$2.info("acceptNewStream()", { streamId, clientId });
@@ -7213,6 +6987,74 @@ class BandwidthTester extends EventEmitter {
7213
6987
  }
7214
6988
  }
7215
6989
 
6990
+ var _a, _b;
6991
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
6992
+ const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
6993
+ const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
6994
+ function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
6995
+ var _a, _b;
6996
+ let HIGH_HEIGHT = 480;
6997
+ let LOW_HEIGHT = 240;
6998
+ if (hd) {
6999
+ HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
7000
+ }
7001
+ if (simulcast) {
7002
+ if (hd === false) {
7003
+ HIGH_HEIGHT = 360;
7004
+ LOW_HEIGHT = 270;
7005
+ }
7006
+ else {
7007
+ LOW_HEIGHT = 360;
7008
+ }
7009
+ }
7010
+ const constraints = {
7011
+ audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
7012
+ video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
7013
+ };
7014
+ if (lax) {
7015
+ if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
7016
+ constraints.audio = true;
7017
+ (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
7018
+ return constraints;
7019
+ }
7020
+ if (resolution) {
7021
+ const [w, h, fps] = parseResolution(resolution);
7022
+ if (w)
7023
+ constraints.video.width = { exact: w };
7024
+ if (h)
7025
+ constraints.video.height = { exact: h };
7026
+ if (fps)
7027
+ constraints.video.frameRate = { exact: fps };
7028
+ delete constraints.video.facingMode;
7029
+ }
7030
+ else {
7031
+ constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
7032
+ }
7033
+ if (disableAGC)
7034
+ constraints.audio.autoGainControl = false;
7035
+ if (disableAEC)
7036
+ constraints.audio.echoCancellation = false;
7037
+ return constraints;
7038
+ }
7039
+ function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
7040
+ const strict = !!devices;
7041
+ const audioDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "audioinput");
7042
+ const videoDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "videoinput");
7043
+ const useDefaultAudio = !audioId || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.some((d) => d.deviceId === audioId)));
7044
+ const useDefaultVideo = !videoId || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.some((d) => d.deviceId === videoId)));
7045
+ const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
7046
+ audioId: useDefaultAudio ? null : { [type]: audioId },
7047
+ videoId: useDefaultVideo ? null : { [type]: videoId },
7048
+ } }, options));
7049
+ if (audioId === false || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.length))) {
7050
+ delete constraints.audio;
7051
+ }
7052
+ if (videoId === false || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.length))) {
7053
+ delete constraints.video;
7054
+ }
7055
+ return constraints;
7056
+ }
7057
+
7216
7058
  const logger = new Logger();
7217
7059
  const isMobile = typeof navigator !== "undefined" && /mobi/i.test(navigator.userAgent);
7218
7060
  class NoDevicesError extends Error {
@@ -7286,9 +7128,9 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7286
7128
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7287
7129
  return settings;
7288
7130
  }
7289
- function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
7131
+ function getDeviceData({ audioTrack, videoTrack, devices, lastAudioId, lastVideoId, }) {
7290
7132
  const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : null);
7291
- videoTrack = usable(videoTrack) || stoppedVideoTrack;
7133
+ videoTrack = usable(videoTrack);
7292
7134
  audioTrack = usable(audioTrack);
7293
7135
  const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
7294
7136
  const audio = getSettingsFromTrack("audioinput", audioTrack, devices, lastAudioId);
@@ -7634,4 +7476,4 @@ var RtcEventNames;
7634
7476
  RtcEventNames["stream_added"] = "stream_added";
7635
7477
  })(RtcEventNames || (RtcEventNames = {}));
7636
7478
 
7637
- export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, CAMERA_STREAM_ID, EVENTS, FILE_SHARE_ERROR_CODES, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, 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, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, detectMicrophoneNotWorking, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getInitialStream, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isFileShareError, isMobile, issueDetectorOrMetricEnabled, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, updateRenderedDimensions, variance };
7479
+ export { ADDITIONAL_SCREEN_SHARE_SETTINGS, AUDIO_SETTINGS, BandwidthTester, CAMERA_STREAM_ID, EVENTS, FILE_SHARE_ERROR_CODES, KNOCK_MESSAGES, KalmanFilter, Logger, MEDIA_JITTER_BUFFER_TARGET, NoDevicesError, P2pRtcManager, PROTOCOL_ERRORS, PROTOCOL_EVENTS, PROTOCOL_REQUESTS, PROTOCOL_RESPONSES, RELAY_MESSAGES, ReconnectManager, RtcEventNames, RtcManagerDispatcher, 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, cleanSdp, compareLocalDevices, createACFCalculator, createMicAnalyser, createWorker, deprioritizeH264, enumerate, external_stun_servers, filterMidExtension, filterMsidSemantic, fromLocation, generateByteString, getConstraints, getCurrentPeerConnections, getDeviceData, getDisplayMedia, getInitialStream, getIssuesAndMetrics, getMediaConstraints, getMediaSettings, getMediasoupDeviceAsync, getNumFailedStatsReports, getNumFailedTrackSsrcLookups, getNumMissingTrackSsrcLookups, getPeerConnectionIndex, getStats, getStream, getUpdatedDevices, getUpdatedStats, getUserMedia, hasGetDisplayMedia, ipRegex, isFileShareError, isMobile, issueDetectorOrMetricEnabled, maybeTurnOnly, modifyMediaCapabilities, removePeerConnection, replaceTracksInStream, rtcManagerEvents, rtcStats, setClientProvider, setCodecPreferenceSDP, setPeerConnectionsForTests, setVideoBandwidthUsingSetParameters, sortCodecs, standardDeviation, startPerformanceMonitor, stopStreamTracks, subscribeIssues, subscribeStats, trackAnnotations, turnServerOverride, updateRenderedDimensions, variance };