@whereby.com/media 6.0.0 → 7.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.
@@ -2505,75 +2505,11 @@ var rtcManagerEvents = {
2505
2505
 
2506
2506
  var _a$2, _b$1;
2507
2507
  const adapter$2 = (_a$2 = adapterRaw.default) !== null && _a$2 !== void 0 ? _a$2 : adapterRaw;
2508
- const isSafari = ((_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser) === "safari";
2509
- const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
2510
- function getMediaConstraints({ audioWanted, videoWanted, disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
2511
- let HIGH_HEIGHT = 480;
2512
- let LOW_HEIGHT = 240;
2513
- if (hd) {
2514
- HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
2515
- }
2516
- if (simulcast) {
2517
- if (hd === false) {
2518
- HIGH_HEIGHT = 360;
2519
- LOW_HEIGHT = 270;
2520
- }
2521
- else {
2522
- LOW_HEIGHT = 360;
2523
- }
2524
- }
2525
- const { audioId, videoId } = preferredDeviceIds;
2526
- const constraints = Object.assign(Object.assign({}, (audioWanted && {
2527
- audio: Object.assign(Object.assign(Object.assign({}, (audioId ? { deviceId: audioId } : {})), (disableAGC ? { autoGainControl: false } : {})), (disableAEC ? { echoCancellation: false } : {})),
2528
- })), (videoWanted && {
2529
- video: Object.assign({ height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }, (videoId ? { deviceId: videoId } : { facingMode: "user" })),
2530
- }));
2531
- if (lax) {
2532
- if (audioWanted && !audioId)
2533
- constraints.audio = true;
2534
- if (videoWanted && !videoId && typeof constraints.video === "object") {
2535
- delete constraints.video.facingMode;
2536
- }
2537
- return constraints;
2538
- }
2539
- if (videoWanted && typeof constraints.video === "object") {
2540
- if (resolution) {
2541
- const [w, h, fps] = parseResolution(resolution);
2542
- if (w)
2543
- constraints.video.width = { exact: w };
2544
- if (h)
2545
- constraints.video.height = { exact: h };
2546
- if (fps)
2547
- constraints.video.frameRate = { exact: fps };
2548
- delete constraints.video.facingMode;
2549
- }
2550
- else {
2551
- constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
2552
- }
2553
- }
2554
- return constraints;
2555
- }
2556
- function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
2557
- const audioDevices = devices.filter((d) => d.kind === "audioinput");
2558
- const videoDevices = devices.filter((d) => d.kind === "videoinput");
2559
- const preferredDeviceIds = {};
2560
- if (typeof audioId === "string" && audioDevices.some((d) => d.deviceId === audioId)) {
2561
- preferredDeviceIds.audioId = { [type]: audioId };
2562
- }
2563
- if (typeof videoId === "string" && videoDevices.some((d) => d.deviceId === videoId)) {
2564
- preferredDeviceIds.videoId = { [type]: videoId };
2565
- }
2566
- const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds, audioWanted: Boolean(audioId) && audioDevices.length > 0, videoWanted: Boolean(videoId) && videoDevices.length > 0 }, options));
2567
- return constraints;
2568
- }
2569
-
2570
- var _a$1, _b;
2571
- const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
2572
2508
  const logger$6 = new Logger();
2573
2509
  const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
2574
2510
  const ICE_RESTART_DELAY = 2 * 1000;
2575
- const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
2576
- const browserVersion = adapter$1.browserDetails.version;
2511
+ const browserName$1 = (_b$1 = adapter$2.browserDetails) === null || _b$1 === void 0 ? void 0 : _b$1.browser;
2512
+ const browserVersion = adapter$2.browserDetails.version;
2577
2513
  let unloading$1 = false;
2578
2514
  if (browserName$1 === "chrome") {
2579
2515
  window.document.addEventListener("beforeunload", () => {
@@ -3558,7 +3494,7 @@ class P2pRtcManager {
3558
3494
  }
3559
3495
  else {
3560
3496
  if (localStream.getVideoTracks().length === 0) {
3561
- const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
3497
+ const constraints = this._webrtcProvider.getMediaConstraints().video;
3562
3498
  if (!constraints) {
3563
3499
  return;
3564
3500
  }
@@ -4427,10 +4363,10 @@ const STREAM_TYPES = {
4427
4363
  screenshare: "screenshare",
4428
4364
  };
4429
4365
 
4430
- var _a;
4431
- const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
4366
+ var _a$1;
4367
+ const adapter$1 = (_a$1 = adapterRaw.default) !== null && _a$1 !== void 0 ? _a$1 : adapterRaw;
4432
4368
  const logger$2 = new Logger();
4433
- const browserName = adapter.browserDetails.browser;
4369
+ const browserName = adapter$1.browserDetails.browser;
4434
4370
  let unloading = false;
4435
4371
  const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
4436
4372
  const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
@@ -5514,7 +5450,7 @@ class VegaRtcManager {
5514
5450
  }, stopCameraDelay);
5515
5451
  }
5516
5452
  else if (localStream.getVideoTracks().length === 0) {
5517
- const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
5453
+ const constraints = this._webrtcProvider.getMediaConstraints().video;
5518
5454
  navigator.mediaDevices
5519
5455
  .getUserMedia({ video: constraints })
5520
5456
  .then((stream) => {
@@ -7039,6 +6975,73 @@ class BandwidthTester extends EventEmitter {
7039
6975
  }
7040
6976
  }
7041
6977
 
6978
+ var _a, _b;
6979
+ const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
6980
+ const isSafari = ((_b = adapter.browserDetails) === null || _b === void 0 ? void 0 : _b.browser) === "safari";
6981
+ const parseResolution = (res) => res.split(/[^\d]/g).map((n) => parseInt(n, 10));
6982
+ function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }) {
6983
+ var _a, _b;
6984
+ let HIGH_HEIGHT = 480;
6985
+ let LOW_HEIGHT = 240;
6986
+ if (hd) {
6987
+ HIGH_HEIGHT = lax || isSafari ? 720 : { min: 360, ideal: 720 };
6988
+ }
6989
+ if (simulcast) {
6990
+ if (hd === false) {
6991
+ HIGH_HEIGHT = 360;
6992
+ LOW_HEIGHT = 270;
6993
+ }
6994
+ else {
6995
+ LOW_HEIGHT = 360;
6996
+ }
6997
+ }
6998
+ const constraints = {
6999
+ audio: Object.assign({}, (preferredDeviceIds.audioId && { deviceId: preferredDeviceIds.audioId })),
7000
+ video: Object.assign(Object.assign({}, (preferredDeviceIds.videoId ? { deviceId: preferredDeviceIds.videoId } : { facingMode: "user" })), { height: lowDataMode ? LOW_HEIGHT : HIGH_HEIGHT, frameRate: lowDataMode && !simulcast ? 15 : 24 }),
7001
+ };
7002
+ if (lax) {
7003
+ if (!((_a = constraints.audio) === null || _a === void 0 ? void 0 : _a.deviceId))
7004
+ constraints.audio = true;
7005
+ (_b = constraints.video) === null || _b === void 0 ? true : delete _b.facingMode;
7006
+ return constraints;
7007
+ }
7008
+ if (resolution) {
7009
+ const [w, h, fps] = parseResolution(resolution);
7010
+ if (w)
7011
+ constraints.video.width = { exact: w };
7012
+ if (h)
7013
+ constraints.video.height = { exact: h };
7014
+ if (fps)
7015
+ constraints.video.frameRate = { exact: fps };
7016
+ delete constraints.video.facingMode;
7017
+ }
7018
+ else {
7019
+ constraints.video.aspectRatio = widescreen ? 16 / 9 : 4 / 3;
7020
+ }
7021
+ if (disableAGC)
7022
+ constraints.audio.autoGainControl = false;
7023
+ if (disableAEC)
7024
+ constraints.audio.echoCancellation = false;
7025
+ return constraints;
7026
+ }
7027
+ function getConstraints({ devices, videoId, audioId, options, type = "ideal" }) {
7028
+ const audioDevices = devices.filter((d) => d.kind === "audioinput");
7029
+ const videoDevices = devices.filter((d) => d.kind === "videoinput");
7030
+ const useDefaultAudio = !audioId || !audioDevices.some((d) => d.deviceId === audioId);
7031
+ const useDefaultVideo = !videoId || !videoDevices.some((d) => d.deviceId === videoId);
7032
+ const constraints = getMediaConstraints(Object.assign({ preferredDeviceIds: {
7033
+ audioId: useDefaultAudio ? null : { [type]: audioId },
7034
+ videoId: useDefaultVideo ? null : { [type]: videoId },
7035
+ } }, options));
7036
+ if (audioId === false || !audioDevices.length) {
7037
+ delete constraints.audio;
7038
+ }
7039
+ if (videoId === false || !videoDevices.length) {
7040
+ delete constraints.video;
7041
+ }
7042
+ return constraints;
7043
+ }
7044
+
7042
7045
  const logger = new Logger();
7043
7046
  const isMobile = /mobi/i.test(navigator.userAgent);
7044
7047
  class NoDevicesError extends Error {
@@ -7072,29 +7075,23 @@ function buildDeviceList({ busyDeviceIds, devices, kind }) {
7072
7075
  label: `${busyDeviceIds.includes(d.deviceId) ? "(busy) " : ""}${d.label || d.deviceId.slice(0, 5)}`,
7073
7076
  busy: busyDeviceIds.includes(d.deviceId),
7074
7077
  }));
7075
- return deviceList && deviceList.length !== 0 ? deviceList : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7078
+ return deviceList && deviceList.length !== 0
7079
+ ? deviceList
7080
+ : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
7076
7081
  }
7077
7082
  function getUserMedia(constraints) {
7078
- return __awaiter(this, void 0, void 0, function* () {
7079
- if (!constraints.audio && !constraints.video) {
7080
- throw new NoDevicesError("No provided devices");
7081
- }
7082
- try {
7083
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
7084
- return stream;
7085
- }
7086
- catch (error) {
7087
- const message = `${error}, ${JSON.stringify(constraints, null, 2)}`;
7088
- logger.error(`getUserMedia ${message}`);
7089
- throw error;
7090
- }
7083
+ if (!constraints.audio && !constraints.video) {
7084
+ return Promise.reject(new NoDevicesError("No provided devices"));
7085
+ }
7086
+ return navigator.mediaDevices.getUserMedia(constraints).catch((error) => {
7087
+ const message = `${error}, ${JSON.stringify(constraints, null, 2)}`;
7088
+ logger.error(`getUserMedia ${message}`);
7089
+ throw error;
7091
7090
  });
7092
7091
  }
7093
7092
  function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7094
7093
  var _a, _b, _c;
7095
- let settings = {
7096
- deviceId: undefined,
7097
- };
7094
+ let settings = { deviceId: null };
7098
7095
  if (!track) {
7099
7096
  if (lastUsedId && devices) {
7100
7097
  settings.deviceId = (_a = devices.find((d) => d.deviceId === lastUsedId && d.kind === kind)) === null || _a === void 0 ? void 0 : _a.deviceId;
@@ -7118,10 +7115,11 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
7118
7115
  if (settings.deviceId)
7119
7116
  return settings;
7120
7117
  settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
7118
+ settings.broken = 1;
7121
7119
  return settings;
7122
7120
  }
7123
7121
  function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
7124
- const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : undefined);
7122
+ const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : null);
7125
7123
  videoTrack = usable(videoTrack) || stoppedVideoTrack;
7126
7124
  audioTrack = usable(audioTrack);
7127
7125
  const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
@@ -7154,7 +7152,7 @@ function getStream(constraintOpt_1) {
7154
7152
  let newConstraints;
7155
7153
  let retryConstraintOpt;
7156
7154
  let stream = null;
7157
- const only = (!constraintOpt.audioId && "video") || (!constraintOpt.videoId && "audio");
7155
+ const only = (constraintOpt.audioId === false && "video") || (constraintOpt.videoId === false && "audio");
7158
7156
  const stopTracks = isMobile || only !== "video";
7159
7157
  const constraints = getConstraints(constraintOpt);
7160
7158
  const addDetails = (err, orgErr) => {
@@ -7165,7 +7163,7 @@ function getStream(constraintOpt_1) {
7165
7163
  return err;
7166
7164
  }
7167
7165
  else {
7168
- return new Error("GetStream: gUM rejected without error");
7166
+ return new Error("Unknown error");
7169
7167
  }
7170
7168
  };
7171
7169
  const getSingleStream = (e) => __awaiter(this, void 0, void 0, function* () {
@@ -7199,18 +7197,12 @@ function getStream(constraintOpt_1) {
7199
7197
  }
7200
7198
  if ((e === null || e === void 0 ? void 0 : e.name) === "OverconstrainedError") {
7201
7199
  const laxConstraints = {
7202
- deviceId: { videoId: true, audioId: true },
7200
+ deviceId: { videoId: null, audioId: null },
7203
7201
  width: { lax: true },
7204
7202
  height: { lax: true },
7205
- "": { audioId: true, videoId: true, lax: true },
7203
+ "": { audioId: null, videoId: null, lax: true },
7206
7204
  };
7207
7205
  retryConstraintOpt = laxConstraints[e.constraint || ""];
7208
- if (!constraintOpt.audioId || only === "video") {
7209
- delete retryConstraintOpt.audioId;
7210
- }
7211
- if (!constraintOpt.videoId || only === "audio") {
7212
- delete retryConstraintOpt.videoId;
7213
- }
7214
7206
  }
7215
7207
  else if ((e === null || e === void 0 ? void 0 : e.name) === "NotFoundError") {
7216
7208
  yield getSingleStream(e);
@@ -7234,7 +7226,7 @@ function getStream(constraintOpt_1) {
7234
7226
  const problemWith = { audio: "audioId", video: "videoId" }[((_a = /(video|audio)/.exec(errMsg)) === null || _a === void 0 ? void 0 : _a[0]) || only || ""];
7235
7227
  if (!stream && problemWith) {
7236
7228
  try {
7237
- stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: true })));
7229
+ stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: null })));
7238
7230
  }
7239
7231
  catch (e2) {
7240
7232
  logger.warn(`Re-tried ${problemWith} with no constraints, but failed: ${"" + e2}`);
@@ -7294,9 +7286,8 @@ const defaultDisplayMediaConstraints = {
7294
7286
  height: { max: window.screen.height },
7295
7287
  },
7296
7288
  };
7297
- function getDisplayMedia() {
7298
- return __awaiter(this, arguments, void 0, function* (constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7299
- const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
7289
+ function getDisplayMedia(constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
7290
+ return navigator.mediaDevices.getDisplayMedia(constraints).then((stream) => {
7300
7291
  stream.getVideoTracks().forEach((t) => {
7301
7292
  if ("contentHint" in t) {
7302
7293
  t.contentHint = contentHint;
@@ -7354,10 +7345,14 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7354
7345
  }
7355
7346
  if (currentDeviceId) {
7356
7347
  if (changes.removed[currentDeviceId]) {
7357
- removedDevices[kind] = changes.removed[currentDeviceId];
7348
+ changedDevices[kind] = { deviceId: null };
7349
+ if (kind === "audiooutput") {
7350
+ const fallbackSpeakerDevice = newDevices.find((d) => d.kind === "audiooutput");
7351
+ changedDevices[kind] = { deviceId: fallbackSpeakerDevice === null || fallbackSpeakerDevice === void 0 ? void 0 : fallbackSpeakerDevice.deviceId };
7352
+ }
7358
7353
  }
7359
7354
  if (changes.changed[currentDeviceId]) {
7360
- changedDevices[kind] = changes.changed[currentDeviceId];
7355
+ changedDevices[kind] = { deviceId: currentDeviceId };
7361
7356
  }
7362
7357
  }
7363
7358
  if (Object.keys(changes.added).length > 0) {
@@ -7365,6 +7360,10 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
7365
7360
  const add = changes.added[deviceAdded];
7366
7361
  addedDevices[kind] = { deviceId: add.deviceId, label: add.label, kind: add.kind };
7367
7362
  }
7363
+ if (Object.keys(changes.removed).length > 0) {
7364
+ const [deviceRemoved] = Object.keys(changes.removed).slice(0, 1);
7365
+ removedDevices[kind] = changes.removed[deviceRemoved];
7366
+ }
7368
7367
  });
7369
7368
  return { addedDevices, changedDevices, removedDevices };
7370
7369
  }
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": "6.0.0",
4
+ "version": "7.0.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/whereby/sdk",
7
7
  "repository": {