@whereby.com/media 5.0.2 → 6.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.
- package/dist/index.cjs +105 -104
- package/dist/index.d.cts +50 -35
- package/dist/index.d.mts +50 -35
- package/dist/index.d.ts +50 -35
- package/dist/index.mjs +105 -104
- package/dist/legacy-esm.js +105 -104
- package/package.json +1 -1
package/dist/legacy-esm.js
CHANGED
|
@@ -2505,11 +2505,75 @@ 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;
|
|
2508
2572
|
const logger$6 = new Logger();
|
|
2509
2573
|
const ICE_PUBLIC_IP_GATHERING_TIMEOUT = 3 * 1000;
|
|
2510
2574
|
const ICE_RESTART_DELAY = 2 * 1000;
|
|
2511
|
-
const browserName$1 = (_b
|
|
2512
|
-
const browserVersion = adapter$
|
|
2575
|
+
const browserName$1 = (_b = adapter$1.browserDetails) === null || _b === void 0 ? void 0 : _b.browser;
|
|
2576
|
+
const browserVersion = adapter$1.browserDetails.version;
|
|
2513
2577
|
let unloading$1 = false;
|
|
2514
2578
|
if (browserName$1 === "chrome") {
|
|
2515
2579
|
window.document.addEventListener("beforeunload", () => {
|
|
@@ -3494,7 +3558,7 @@ class P2pRtcManager {
|
|
|
3494
3558
|
}
|
|
3495
3559
|
else {
|
|
3496
3560
|
if (localStream.getVideoTracks().length === 0) {
|
|
3497
|
-
const constraints = this._webrtcProvider.getMediaConstraints().video;
|
|
3561
|
+
const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
|
|
3498
3562
|
if (!constraints) {
|
|
3499
3563
|
return;
|
|
3500
3564
|
}
|
|
@@ -4363,10 +4427,10 @@ const STREAM_TYPES = {
|
|
|
4363
4427
|
screenshare: "screenshare",
|
|
4364
4428
|
};
|
|
4365
4429
|
|
|
4366
|
-
var _a
|
|
4367
|
-
const adapter
|
|
4430
|
+
var _a;
|
|
4431
|
+
const adapter = (_a = adapterRaw.default) !== null && _a !== void 0 ? _a : adapterRaw;
|
|
4368
4432
|
const logger$2 = new Logger();
|
|
4369
|
-
const browserName = adapter
|
|
4433
|
+
const browserName = adapter.browserDetails.browser;
|
|
4370
4434
|
let unloading = false;
|
|
4371
4435
|
const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
|
|
4372
4436
|
const RESTARTICE_ERROR_MAX_RETRY_COUNT = 5;
|
|
@@ -5450,7 +5514,7 @@ class VegaRtcManager {
|
|
|
5450
5514
|
}, stopCameraDelay);
|
|
5451
5515
|
}
|
|
5452
5516
|
else if (localStream.getVideoTracks().length === 0) {
|
|
5453
|
-
const constraints = this._webrtcProvider.getMediaConstraints().video;
|
|
5517
|
+
const constraints = getConstraints(this._webrtcProvider.getMediaConstraints()).video;
|
|
5454
5518
|
navigator.mediaDevices
|
|
5455
5519
|
.getUserMedia({ video: constraints })
|
|
5456
5520
|
.then((stream) => {
|
|
@@ -6975,73 +7039,6 @@ class BandwidthTester extends EventEmitter {
|
|
|
6975
7039
|
}
|
|
6976
7040
|
}
|
|
6977
7041
|
|
|
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
|
-
|
|
7045
7042
|
const logger = new Logger();
|
|
7046
7043
|
const isMobile = /mobi/i.test(navigator.userAgent);
|
|
7047
7044
|
class NoDevicesError extends Error {
|
|
@@ -7075,23 +7072,29 @@ function buildDeviceList({ busyDeviceIds, devices, kind }) {
|
|
|
7075
7072
|
label: `${busyDeviceIds.includes(d.deviceId) ? "(busy) " : ""}${d.label || d.deviceId.slice(0, 5)}`,
|
|
7076
7073
|
busy: busyDeviceIds.includes(d.deviceId),
|
|
7077
7074
|
}));
|
|
7078
|
-
return deviceList && deviceList.length !== 0
|
|
7079
|
-
? deviceList
|
|
7080
|
-
: [{ [idFieldsByKind[kind]]: "", label: "Default" }];
|
|
7075
|
+
return deviceList && deviceList.length !== 0 ? deviceList : [{ [idFieldsByKind[kind]]: "", label: "Default" }];
|
|
7081
7076
|
}
|
|
7082
7077
|
function getUserMedia(constraints) {
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
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
|
+
}
|
|
7090
7091
|
});
|
|
7091
7092
|
}
|
|
7092
7093
|
function getSettingsFromTrack(kind, track, devices, lastUsedId) {
|
|
7093
7094
|
var _a, _b, _c;
|
|
7094
|
-
let settings = {
|
|
7095
|
+
let settings = {
|
|
7096
|
+
deviceId: undefined,
|
|
7097
|
+
};
|
|
7095
7098
|
if (!track) {
|
|
7096
7099
|
if (lastUsedId && devices) {
|
|
7097
7100
|
settings.deviceId = (_a = devices.find((d) => d.deviceId === lastUsedId && d.kind === kind)) === null || _a === void 0 ? void 0 : _a.deviceId;
|
|
@@ -7115,11 +7118,10 @@ function getSettingsFromTrack(kind, track, devices, lastUsedId) {
|
|
|
7115
7118
|
if (settings.deviceId)
|
|
7116
7119
|
return settings;
|
|
7117
7120
|
settings.deviceId = (_c = track.getConstraints()) === null || _c === void 0 ? void 0 : _c.deviceId;
|
|
7118
|
-
settings.broken = 1;
|
|
7119
7121
|
return settings;
|
|
7120
7122
|
}
|
|
7121
7123
|
function getDeviceData({ audioTrack, videoTrack, devices, stoppedVideoTrack, lastAudioId, lastVideoId, }) {
|
|
7122
|
-
const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d :
|
|
7124
|
+
const usable = (d) => ((d === null || d === void 0 ? void 0 : d.readyState) === "live" ? d : undefined);
|
|
7123
7125
|
videoTrack = usable(videoTrack) || stoppedVideoTrack;
|
|
7124
7126
|
audioTrack = usable(audioTrack);
|
|
7125
7127
|
const video = getSettingsFromTrack("videoinput", videoTrack, devices, lastVideoId);
|
|
@@ -7152,7 +7154,7 @@ function getStream(constraintOpt_1) {
|
|
|
7152
7154
|
let newConstraints;
|
|
7153
7155
|
let retryConstraintOpt;
|
|
7154
7156
|
let stream = null;
|
|
7155
|
-
const only = (constraintOpt.audioId
|
|
7157
|
+
const only = (!constraintOpt.audioId && "video") || (!constraintOpt.videoId && "audio");
|
|
7156
7158
|
const stopTracks = isMobile || only !== "video";
|
|
7157
7159
|
const constraints = getConstraints(constraintOpt);
|
|
7158
7160
|
const addDetails = (err, orgErr) => {
|
|
@@ -7163,7 +7165,7 @@ function getStream(constraintOpt_1) {
|
|
|
7163
7165
|
return err;
|
|
7164
7166
|
}
|
|
7165
7167
|
else {
|
|
7166
|
-
return new Error("
|
|
7168
|
+
return new Error("GetStream: gUM rejected without error");
|
|
7167
7169
|
}
|
|
7168
7170
|
};
|
|
7169
7171
|
const getSingleStream = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -7197,12 +7199,18 @@ function getStream(constraintOpt_1) {
|
|
|
7197
7199
|
}
|
|
7198
7200
|
if ((e === null || e === void 0 ? void 0 : e.name) === "OverconstrainedError") {
|
|
7199
7201
|
const laxConstraints = {
|
|
7200
|
-
deviceId: { videoId:
|
|
7202
|
+
deviceId: { videoId: true, audioId: true },
|
|
7201
7203
|
width: { lax: true },
|
|
7202
7204
|
height: { lax: true },
|
|
7203
|
-
"": { audioId:
|
|
7205
|
+
"": { audioId: true, videoId: true, lax: true },
|
|
7204
7206
|
};
|
|
7205
7207
|
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
|
+
}
|
|
7206
7214
|
}
|
|
7207
7215
|
else if ((e === null || e === void 0 ? void 0 : e.name) === "NotFoundError") {
|
|
7208
7216
|
yield getSingleStream(e);
|
|
@@ -7226,7 +7234,7 @@ function getStream(constraintOpt_1) {
|
|
|
7226
7234
|
const problemWith = { audio: "audioId", video: "videoId" }[((_a = /(video|audio)/.exec(errMsg)) === null || _a === void 0 ? void 0 : _a[0]) || only || ""];
|
|
7227
7235
|
if (!stream && problemWith) {
|
|
7228
7236
|
try {
|
|
7229
|
-
stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]:
|
|
7237
|
+
stream = yield getUserMedia(getConstraints(Object.assign(Object.assign({}, constraintOpt), { [problemWith]: true })));
|
|
7230
7238
|
}
|
|
7231
7239
|
catch (e2) {
|
|
7232
7240
|
logger.warn(`Re-tried ${problemWith} with no constraints, but failed: ${"" + e2}`);
|
|
@@ -7286,8 +7294,9 @@ const defaultDisplayMediaConstraints = {
|
|
|
7286
7294
|
height: { max: window.screen.height },
|
|
7287
7295
|
},
|
|
7288
7296
|
};
|
|
7289
|
-
function getDisplayMedia(
|
|
7290
|
-
return
|
|
7297
|
+
function getDisplayMedia() {
|
|
7298
|
+
return __awaiter(this, arguments, void 0, function* (constraints = defaultDisplayMediaConstraints, contentHint = "detail") {
|
|
7299
|
+
const stream = yield navigator.mediaDevices.getDisplayMedia(constraints);
|
|
7291
7300
|
stream.getVideoTracks().forEach((t) => {
|
|
7292
7301
|
if ("contentHint" in t) {
|
|
7293
7302
|
t.contentHint = contentHint;
|
|
@@ -7345,14 +7354,10 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
|
|
|
7345
7354
|
}
|
|
7346
7355
|
if (currentDeviceId) {
|
|
7347
7356
|
if (changes.removed[currentDeviceId]) {
|
|
7348
|
-
|
|
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
|
-
}
|
|
7357
|
+
removedDevices[kind] = changes.removed[currentDeviceId];
|
|
7353
7358
|
}
|
|
7354
7359
|
if (changes.changed[currentDeviceId]) {
|
|
7355
|
-
changedDevices[kind] =
|
|
7360
|
+
changedDevices[kind] = changes.changed[currentDeviceId];
|
|
7356
7361
|
}
|
|
7357
7362
|
}
|
|
7358
7363
|
if (Object.keys(changes.added).length > 0) {
|
|
@@ -7360,10 +7365,6 @@ function getUpdatedDevices({ oldDevices, newDevices, currentAudioId, currentVide
|
|
|
7360
7365
|
const add = changes.added[deviceAdded];
|
|
7361
7366
|
addedDevices[kind] = { deviceId: add.deviceId, label: add.label, kind: add.kind };
|
|
7362
7367
|
}
|
|
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
|
-
}
|
|
7367
7368
|
});
|
|
7368
7369
|
return { addedDevices, changedDevices, removedDevices };
|
|
7369
7370
|
}
|