@whereby.com/media 9.7.4 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2430,79 +2430,11 @@ fromLocation(typeof window !== "undefined" ? window.location : undefined);
2430
2430
 
2431
2431
  var _a$2, _b$1;
2432
2432
  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
2433
  const logger$6 = new Logger();
2502
2434
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2503
2435
  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;
2436
+ const browserName$1 = (_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser;
2437
+ const browserVersion = adapter$2.browserDetails.version;
2506
2438
  let unloading$1 = false;
2507
2439
  if (browserName$1 === "chrome") {
2508
2440
  window.document.addEventListener("beforeunload", () => {
@@ -2528,7 +2460,6 @@ class P2pRtcManager {
2528
2460
  this._closed = false;
2529
2461
  this._videoTrackIdByStreamId = {};
2530
2462
  this._fetchMediaServersTimer = null;
2531
- this._stopCameraTimeout = null;
2532
2463
  this._icePublicIPGatheringTimeoutID = null;
2533
2464
  this.offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };
2534
2465
  this._audioTrackOnEnded = () => {
@@ -2548,7 +2479,6 @@ class P2pRtcManager {
2548
2479
  });
2549
2480
  this.analytics = {
2550
2481
  P2POffendingInitialOffer: 0,
2551
- P2PNonErrorRejectionValueGUMError: 0,
2552
2482
  numNewPc: 0,
2553
2483
  numIceConnected: 0,
2554
2484
  numIceDisconnected: 0,
@@ -2581,9 +2511,8 @@ class P2pRtcManager {
2581
2511
  isInitializedWith({ selfId, roomName, isSfu }) {
2582
2512
  return this._selfId === selfId && this._roomName === roomName && !isSfu;
2583
2513
  }
2584
- addCameraStream(stream, { videoPaused, beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
2514
+ addCameraStream(stream, { beforeEffectTracks = [] } = { beforeEffectTracks: [] }) {
2585
2515
  logger$6.info("addCameraStream: [stream.id: %s]", stream.id);
2586
- this._webcamPaused = videoPaused;
2587
2516
  if (stream === this._localCameraStream) {
2588
2517
  return;
2589
2518
  }
@@ -3460,65 +3389,7 @@ class P2pRtcManager {
3460
3389
  }
3461
3390
  }
3462
3391
  }
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
- }
3392
+ stopOrResumeVideo() {
3522
3393
  }
3523
3394
  removeScreenshareStream(stream, { requestedByClientId } = {}) {
3524
3395
  logger$6.info("removeScreenshareStream() [stream.id: %s, requestedByClientId: %s]", stream.id, requestedByClientId);
@@ -4386,10 +4257,10 @@ const STREAM_TYPES = {
4386
4257
  screenshare: "screenshare",
4387
4258
  };
4388
4259
 
4389
- var _a;
4390
- const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4260
+ var _a$1;
4261
+ const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4391
4262
  const logger$2 = new Logger();
4392
- const browserName = adapter.browserDetails.browser;
4263
+ const browserName = adapter$1.browserDetails.browser;
4393
4264
  let unloading = false;
4394
4265
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4395
4266
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -4440,7 +4311,6 @@ class VegaRtcManager {
4440
4311
  this._sndTransportIceRestartPromise = null;
4441
4312
  this._rcvTransportIceRestartPromise = null;
4442
4313
  this._colocation = null;
4443
- this._stopCameraTimeout = null;
4444
4314
  this._audioTrackOnEnded = () => {
4445
4315
  rtcStats.sendEvent("audio_ended", { unloading });
4446
4316
  this._emitToPWA(rtcManagerEvents.MICROPHONE_STOPPED_WORKING, {});
@@ -4483,7 +4353,6 @@ class VegaRtcManager {
4483
4353
  vegaIceRestarts: 0,
4484
4354
  vegaIceRestartMissingTransport: 0,
4485
4355
  vegaIceRestartWrongTransportId: 0,
4486
- vegaNonErrorRejectionValueGUMError: 0,
4487
4356
  vegaReplaceTrackNoProducerNoEnabledTrack: 0,
4488
4357
  vegaMicProducerFailed: 0,
4489
4358
  vegaWebcamProducerFailed: 0,
@@ -5533,9 +5402,9 @@ class VegaRtcManager {
5533
5402
  return;
5534
5403
  }
5535
5404
  }
5536
- stopOrResumeAudio(stream, enabled) {
5537
- logger$2.info("stopOrResumeAudio() [enabled:%s]", enabled);
5538
- this._micPaused = !enabled;
5405
+ stopOrResumeAudio({ enable }) {
5406
+ logger$2.info("stopOrResumeAudio() [enable:%s]", enable);
5407
+ this._micPaused = !enable;
5539
5408
  this._pauseResumeMic();
5540
5409
  }
5541
5410
  _handleStopOrResumeVideo({ enable, track }) {
@@ -5550,61 +5419,10 @@ class VegaRtcManager {
5550
5419
  this._sendWebcam(track);
5551
5420
  }
5552
5421
  }
5553
- stopOrResumeVideo(localStream, enable) {
5554
- var _a;
5422
+ stopOrResumeVideo({ enable }) {
5555
5423
  logger$2.info("stopOrResumeVideo() [enable:%s]", enable);
5556
5424
  this._webcamPaused = !enable;
5557
5425
  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
5426
  }
5609
5427
  acceptNewStream({ streamId, clientId }) {
5610
5428
  logger$2.info("acceptNewStream()", { streamId, clientId });
@@ -7213,6 +7031,74 @@ class BandwidthTester extends EventEmitter {
7213
7031
  }
7214
7032
  }
7215
7033
 
7034
+ var _a, _b;
7035
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
7036
+ const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
7037
+ const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
7038
+ function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
7039
+ var _a, _b;
7040
+ let HIGH_HEIGHT = 480;
7041
+ let LOW_HEIGHT = 240;
7042
+ if (hd) {
7043
+ HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
7044
+ }
7045
+ if (simulcast) {
7046
+ if (hd === false) {
7047
+ HIGH_HEIGHT = 360;
7048
+ LOW_HEIGHT = 270;
7049
+ }
7050
+ else {
7051
+ LOW_HEIGHT = 360;
7052
+ }
7053
+ }
7054
+ const constraints = {
7055
+ audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
7056
+ video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
7057
+ };
7058
+ if (lax) {
7059
+ if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
7060
+ constraints.audio = true;
7061
+ (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
7062
+ return constraints;
7063
+ }
7064
+ if (resolution) {
7065
+ const [w, h, fps] = parseResolution(resolution);
7066
+ if (w)
7067
+ constraints.video.width = { exact: w };
7068
+ if (h)
7069
+ constraints.video.height = { exact: h };
7070
+ if (fps)
7071
+ constraints.video.frameRate = { exact: fps };
7072
+ delete constraints.video.facingMode;
7073
+ }
7074
+ else {
7075
+ constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
7076
+ }
7077
+ if (disableAGC)
7078
+ constraints.audio.autoGainControl = false;
7079
+ if (disableAEC)
7080
+ constraints.audio.echoCancellation = false;
7081
+ return constraints;
7082
+ }
7083
+ function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
7084
+ const strict = !!devices;
7085
+ const audioDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "audioinput");
7086
+ const videoDevices = devices === null || devices === void 0 ? void 0 : devices.filter((d) => d.kind === "videoinput");
7087
+ const useDefaultAudio = !audioId || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.some((d) => d.deviceId === audioId)));
7088
+ const useDefaultVideo = !videoId || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.some((d) => d.deviceId === videoId)));
7089
+ const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
7090
+ audioId: useDefaultAudio ? null : { [type]: audioId },
7091
+ videoId: useDefaultVideo ? null : { [type]: videoId },
7092
+ } }, options));
7093
+ if (audioId === false || (strict && !(audioDevices === null || audioDevices === void 0 ? void 0 : audioDevices.length))) {
7094
+ delete constraints.audio;
7095
+ }
7096
+ if (videoId === false || (strict && !(videoDevices === null || videoDevices === void 0 ? void 0 : videoDevices.length))) {
7097
+ delete constraints.video;
7098
+ }
7099
+ return constraints;
7100
+ }
7101
+
7216
7102
  const logger = new Logger();
7217
7103
  const isMobile = typeof navigator !== "undefined" && /mobi/i.test(navigator.userAgent);
7218
7104
  class NoDevicesError extends Error {
@@ -7286,9 +7172,9 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7286
7172
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7287
7173
  return settings;
7288
7174
  }
7289
- function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
7175
+ function getDeviceData({ audioTrack, videoTrack, devices, lastAudioId, lastVideoId, }) {
7290
7176
  const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : null);
7291
- videoTrack = usable(videoTrack) || stoppedVideoTrack;
7177
+ videoTrack = usable(videoTrack);
7292
7178
  audioTrack = usable(audioTrack);
7293
7179
  const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
7294
7180
  const audio = getSettingsFromTrack("audioinput", audioTrack, devices, lastAudioId);
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": "9.7.4",
4
+ "version": "10.0.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {