@whereby.com/media 2.6.3 → 2.6.4
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 +45 -30
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +45 -30
- package/dist/legacy-esm.js +45 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2352,15 +2352,15 @@ class Session {
|
|
|
2352
2352
|
return this.pc && this.pc.connectionState === "connected";
|
|
2353
2353
|
}
|
|
2354
2354
|
replaceTrack(oldTrack, newTrack) {
|
|
2355
|
+
var _a;
|
|
2355
2356
|
const pc = this.pc;
|
|
2356
2357
|
if (!pc)
|
|
2357
2358
|
return false;
|
|
2358
2359
|
const senders = pc.getSenders();
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
}
|
|
2360
|
+
const oldTrackFallback = (_a = senders.find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.kind) === newTrack.kind; })) === null || _a === void 0 ? void 0 : _a.track;
|
|
2361
|
+
const oldTrackToReplace = oldTrack || oldTrackFallback;
|
|
2362
2362
|
if (window.RTCRtpSender && window.RTCRtpSender.prototype.replaceTrack) {
|
|
2363
|
-
if (
|
|
2363
|
+
if (oldTrackToReplace) {
|
|
2364
2364
|
const process = () => {
|
|
2365
2365
|
for (let i = 0; i < senders.length; i++) {
|
|
2366
2366
|
const sender = senders[i];
|
|
@@ -2368,39 +2368,52 @@ class Session {
|
|
|
2368
2368
|
if ((track === null || track === void 0 ? void 0 : track.id) === newTrack.id) {
|
|
2369
2369
|
return Promise.resolve(newTrack);
|
|
2370
2370
|
}
|
|
2371
|
-
if ((track === null || track === void 0 ? void 0 : track.id) ===
|
|
2371
|
+
if ((track === null || track === void 0 ? void 0 : track.id) === oldTrackToReplace.id) {
|
|
2372
2372
|
return senders[i].replaceTrack(newTrack);
|
|
2373
2373
|
}
|
|
2374
2374
|
}
|
|
2375
2375
|
return null;
|
|
2376
2376
|
};
|
|
2377
|
-
|
|
2377
|
+
const result = process();
|
|
2378
2378
|
if (result) {
|
|
2379
2379
|
return result;
|
|
2380
2380
|
}
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2381
|
+
return new Promise((resolve, reject) => {
|
|
2382
|
+
let retried = 0;
|
|
2383
|
+
let timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
2384
|
+
const trackReplacedPromise = process();
|
|
2385
|
+
if (!trackReplacedPromise) {
|
|
2386
|
+
if (3 < ++retried) {
|
|
2387
|
+
clearInterval(timer);
|
|
2388
|
+
timer = null;
|
|
2389
|
+
const sendersAnalytics = senders.map((s) => {
|
|
2390
|
+
const track = s.track;
|
|
2391
|
+
if (track) {
|
|
2392
|
+
return {
|
|
2393
|
+
id: track.id,
|
|
2394
|
+
kind: track.kind,
|
|
2395
|
+
readyState: track.readyState,
|
|
2396
|
+
replaced: track.replaced,
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
rtcStats.sendEvent("P2PReplaceTrackFailed", {
|
|
2401
|
+
newTrackId: newTrack === null || newTrack === void 0 ? void 0 : newTrack.id,
|
|
2402
|
+
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2403
|
+
oldTrackFallbackId: oldTrackFallback === null || oldTrackFallback === void 0 ? void 0 : oldTrackFallback.id,
|
|
2404
|
+
sendersCount: senders === null || senders === void 0 ? void 0 : senders.length,
|
|
2405
|
+
sendersAnalytics,
|
|
2406
|
+
});
|
|
2407
|
+
reject("No sender track to replace");
|
|
2408
|
+
}
|
|
2409
|
+
return;
|
|
2395
2410
|
}
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
}), 1000);
|
|
2403
|
-
return result;
|
|
2411
|
+
clearInterval(timer);
|
|
2412
|
+
timer = null;
|
|
2413
|
+
const trackReplaced = yield trackReplacedPromise;
|
|
2414
|
+
resolve(trackReplaced);
|
|
2415
|
+
}), 1000);
|
|
2416
|
+
});
|
|
2404
2417
|
}
|
|
2405
2418
|
const stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id)) || this.streams[0];
|
|
2406
2419
|
if (!stream) {
|
|
@@ -2410,14 +2423,16 @@ class Session {
|
|
|
2410
2423
|
}
|
|
2411
2424
|
if (!this.canModifyPeerConnection()) {
|
|
2412
2425
|
this.pending.push(() => {
|
|
2413
|
-
this.replaceTrack(
|
|
2426
|
+
this.replaceTrack(oldTrackToReplace, newTrack);
|
|
2414
2427
|
});
|
|
2415
2428
|
return;
|
|
2416
2429
|
}
|
|
2417
2430
|
this.isOperationPending = true;
|
|
2418
2431
|
const onn = pc.onnegotiationneeded;
|
|
2419
2432
|
pc.onnegotiationneeded = null;
|
|
2420
|
-
|
|
2433
|
+
if (oldTrackToReplace) {
|
|
2434
|
+
this.removeTrack(oldTrackToReplace);
|
|
2435
|
+
}
|
|
2421
2436
|
this.addTrack(newTrack);
|
|
2422
2437
|
setTimeout(() => {
|
|
2423
2438
|
pc.onnegotiationneeded = onn;
|
package/dist/index.d.cts
CHANGED
|
@@ -447,6 +447,7 @@ type GetDeviceDataResult = {
|
|
|
447
447
|
};
|
|
448
448
|
interface CustomMediaStreamTrack extends MediaStreamTrack {
|
|
449
449
|
effectTrack?: boolean;
|
|
450
|
+
replaced?: boolean;
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
declare function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }: GetMediaConstraintsOptions): any;
|
|
@@ -1335,7 +1336,7 @@ declare class Session {
|
|
|
1335
1336
|
canModifyPeerConnection(): boolean;
|
|
1336
1337
|
close(): void;
|
|
1337
1338
|
hasConnectedPeerConnection(): any;
|
|
1338
|
-
replaceTrack(oldTrack:
|
|
1339
|
+
replaceTrack(oldTrack: CustomMediaStreamTrack | undefined | null, newTrack: MediaStreamTrack): any;
|
|
1339
1340
|
changeBandwidth(bandwidth: any): void;
|
|
1340
1341
|
setAudioOnly(enable: boolean, excludedTrackIds?: any[]): void;
|
|
1341
1342
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -447,6 +447,7 @@ type GetDeviceDataResult = {
|
|
|
447
447
|
};
|
|
448
448
|
interface CustomMediaStreamTrack extends MediaStreamTrack {
|
|
449
449
|
effectTrack?: boolean;
|
|
450
|
+
replaced?: boolean;
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
declare function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }: GetMediaConstraintsOptions): any;
|
|
@@ -1335,7 +1336,7 @@ declare class Session {
|
|
|
1335
1336
|
canModifyPeerConnection(): boolean;
|
|
1336
1337
|
close(): void;
|
|
1337
1338
|
hasConnectedPeerConnection(): any;
|
|
1338
|
-
replaceTrack(oldTrack:
|
|
1339
|
+
replaceTrack(oldTrack: CustomMediaStreamTrack | undefined | null, newTrack: MediaStreamTrack): any;
|
|
1339
1340
|
changeBandwidth(bandwidth: any): void;
|
|
1340
1341
|
setAudioOnly(enable: boolean, excludedTrackIds?: any[]): void;
|
|
1341
1342
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -447,6 +447,7 @@ type GetDeviceDataResult = {
|
|
|
447
447
|
};
|
|
448
448
|
interface CustomMediaStreamTrack extends MediaStreamTrack {
|
|
449
449
|
effectTrack?: boolean;
|
|
450
|
+
replaced?: boolean;
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
declare function getMediaConstraints({ disableAEC, disableAGC, hd, lax, lowDataMode, preferredDeviceIds, resolution, simulcast, widescreen, }: GetMediaConstraintsOptions): any;
|
|
@@ -1335,7 +1336,7 @@ declare class Session {
|
|
|
1335
1336
|
canModifyPeerConnection(): boolean;
|
|
1336
1337
|
close(): void;
|
|
1337
1338
|
hasConnectedPeerConnection(): any;
|
|
1338
|
-
replaceTrack(oldTrack:
|
|
1339
|
+
replaceTrack(oldTrack: CustomMediaStreamTrack | undefined | null, newTrack: MediaStreamTrack): any;
|
|
1339
1340
|
changeBandwidth(bandwidth: any): void;
|
|
1340
1341
|
setAudioOnly(enable: boolean, excludedTrackIds?: any[]): void;
|
|
1341
1342
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -2331,15 +2331,15 @@ class Session {
|
|
|
2331
2331
|
return this.pc && this.pc.connectionState === "connected";
|
|
2332
2332
|
}
|
|
2333
2333
|
replaceTrack(oldTrack, newTrack) {
|
|
2334
|
+
var _a;
|
|
2334
2335
|
const pc = this.pc;
|
|
2335
2336
|
if (!pc)
|
|
2336
2337
|
return false;
|
|
2337
2338
|
const senders = pc.getSenders();
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
}
|
|
2339
|
+
const oldTrackFallback = (_a = senders.find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.kind) === newTrack.kind; })) === null || _a === void 0 ? void 0 : _a.track;
|
|
2340
|
+
const oldTrackToReplace = oldTrack || oldTrackFallback;
|
|
2341
2341
|
if (window.RTCRtpSender && window.RTCRtpSender.prototype.replaceTrack) {
|
|
2342
|
-
if (
|
|
2342
|
+
if (oldTrackToReplace) {
|
|
2343
2343
|
const process = () => {
|
|
2344
2344
|
for (let i = 0; i < senders.length; i++) {
|
|
2345
2345
|
const sender = senders[i];
|
|
@@ -2347,39 +2347,52 @@ class Session {
|
|
|
2347
2347
|
if ((track === null || track === void 0 ? void 0 : track.id) === newTrack.id) {
|
|
2348
2348
|
return Promise.resolve(newTrack);
|
|
2349
2349
|
}
|
|
2350
|
-
if ((track === null || track === void 0 ? void 0 : track.id) ===
|
|
2350
|
+
if ((track === null || track === void 0 ? void 0 : track.id) === oldTrackToReplace.id) {
|
|
2351
2351
|
return senders[i].replaceTrack(newTrack);
|
|
2352
2352
|
}
|
|
2353
2353
|
}
|
|
2354
2354
|
return null;
|
|
2355
2355
|
};
|
|
2356
|
-
|
|
2356
|
+
const result = process();
|
|
2357
2357
|
if (result) {
|
|
2358
2358
|
return result;
|
|
2359
2359
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2360
|
+
return new Promise((resolve, reject) => {
|
|
2361
|
+
let retried = 0;
|
|
2362
|
+
let timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
2363
|
+
const trackReplacedPromise = process();
|
|
2364
|
+
if (!trackReplacedPromise) {
|
|
2365
|
+
if (3 < ++retried) {
|
|
2366
|
+
clearInterval(timer);
|
|
2367
|
+
timer = null;
|
|
2368
|
+
const sendersAnalytics = senders.map((s) => {
|
|
2369
|
+
const track = s.track;
|
|
2370
|
+
if (track) {
|
|
2371
|
+
return {
|
|
2372
|
+
id: track.id,
|
|
2373
|
+
kind: track.kind,
|
|
2374
|
+
readyState: track.readyState,
|
|
2375
|
+
replaced: track.replaced,
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
rtcStats.sendEvent("P2PReplaceTrackFailed", {
|
|
2380
|
+
newTrackId: newTrack === null || newTrack === void 0 ? void 0 : newTrack.id,
|
|
2381
|
+
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2382
|
+
oldTrackFallbackId: oldTrackFallback === null || oldTrackFallback === void 0 ? void 0 : oldTrackFallback.id,
|
|
2383
|
+
sendersCount: senders === null || senders === void 0 ? void 0 : senders.length,
|
|
2384
|
+
sendersAnalytics,
|
|
2385
|
+
});
|
|
2386
|
+
reject("No sender track to replace");
|
|
2387
|
+
}
|
|
2388
|
+
return;
|
|
2374
2389
|
}
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
}), 1000);
|
|
2382
|
-
return result;
|
|
2390
|
+
clearInterval(timer);
|
|
2391
|
+
timer = null;
|
|
2392
|
+
const trackReplaced = yield trackReplacedPromise;
|
|
2393
|
+
resolve(trackReplaced);
|
|
2394
|
+
}), 1000);
|
|
2395
|
+
});
|
|
2383
2396
|
}
|
|
2384
2397
|
const stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id)) || this.streams[0];
|
|
2385
2398
|
if (!stream) {
|
|
@@ -2389,14 +2402,16 @@ class Session {
|
|
|
2389
2402
|
}
|
|
2390
2403
|
if (!this.canModifyPeerConnection()) {
|
|
2391
2404
|
this.pending.push(() => {
|
|
2392
|
-
this.replaceTrack(
|
|
2405
|
+
this.replaceTrack(oldTrackToReplace, newTrack);
|
|
2393
2406
|
});
|
|
2394
2407
|
return;
|
|
2395
2408
|
}
|
|
2396
2409
|
this.isOperationPending = true;
|
|
2397
2410
|
const onn = pc.onnegotiationneeded;
|
|
2398
2411
|
pc.onnegotiationneeded = null;
|
|
2399
|
-
|
|
2412
|
+
if (oldTrackToReplace) {
|
|
2413
|
+
this.removeTrack(oldTrackToReplace);
|
|
2414
|
+
}
|
|
2400
2415
|
this.addTrack(newTrack);
|
|
2401
2416
|
setTimeout(() => {
|
|
2402
2417
|
pc.onnegotiationneeded = onn;
|
package/dist/legacy-esm.js
CHANGED
|
@@ -2331,15 +2331,15 @@ class Session {
|
|
|
2331
2331
|
return this.pc && this.pc.connectionState === "connected";
|
|
2332
2332
|
}
|
|
2333
2333
|
replaceTrack(oldTrack, newTrack) {
|
|
2334
|
+
var _a;
|
|
2334
2335
|
const pc = this.pc;
|
|
2335
2336
|
if (!pc)
|
|
2336
2337
|
return false;
|
|
2337
2338
|
const senders = pc.getSenders();
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
}
|
|
2339
|
+
const oldTrackFallback = (_a = senders.find((s) => { var _a; return ((_a = s.track) === null || _a === void 0 ? void 0 : _a.kind) === newTrack.kind; })) === null || _a === void 0 ? void 0 : _a.track;
|
|
2340
|
+
const oldTrackToReplace = oldTrack || oldTrackFallback;
|
|
2341
2341
|
if (window.RTCRtpSender && window.RTCRtpSender.prototype.replaceTrack) {
|
|
2342
|
-
if (
|
|
2342
|
+
if (oldTrackToReplace) {
|
|
2343
2343
|
const process = () => {
|
|
2344
2344
|
for (let i = 0; i < senders.length; i++) {
|
|
2345
2345
|
const sender = senders[i];
|
|
@@ -2347,39 +2347,52 @@ class Session {
|
|
|
2347
2347
|
if ((track === null || track === void 0 ? void 0 : track.id) === newTrack.id) {
|
|
2348
2348
|
return Promise.resolve(newTrack);
|
|
2349
2349
|
}
|
|
2350
|
-
if ((track === null || track === void 0 ? void 0 : track.id) ===
|
|
2350
|
+
if ((track === null || track === void 0 ? void 0 : track.id) === oldTrackToReplace.id) {
|
|
2351
2351
|
return senders[i].replaceTrack(newTrack);
|
|
2352
2352
|
}
|
|
2353
2353
|
}
|
|
2354
2354
|
return null;
|
|
2355
2355
|
};
|
|
2356
|
-
|
|
2356
|
+
const result = process();
|
|
2357
2357
|
if (result) {
|
|
2358
2358
|
return result;
|
|
2359
2359
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2360
|
+
return new Promise((resolve, reject) => {
|
|
2361
|
+
let retried = 0;
|
|
2362
|
+
let timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
2363
|
+
const trackReplacedPromise = process();
|
|
2364
|
+
if (!trackReplacedPromise) {
|
|
2365
|
+
if (3 < ++retried) {
|
|
2366
|
+
clearInterval(timer);
|
|
2367
|
+
timer = null;
|
|
2368
|
+
const sendersAnalytics = senders.map((s) => {
|
|
2369
|
+
const track = s.track;
|
|
2370
|
+
if (track) {
|
|
2371
|
+
return {
|
|
2372
|
+
id: track.id,
|
|
2373
|
+
kind: track.kind,
|
|
2374
|
+
readyState: track.readyState,
|
|
2375
|
+
replaced: track.replaced,
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
2378
|
+
});
|
|
2379
|
+
rtcStats.sendEvent("P2PReplaceTrackFailed", {
|
|
2380
|
+
newTrackId: newTrack === null || newTrack === void 0 ? void 0 : newTrack.id,
|
|
2381
|
+
oldTrackId: oldTrack === null || oldTrack === void 0 ? void 0 : oldTrack.id,
|
|
2382
|
+
oldTrackFallbackId: oldTrackFallback === null || oldTrackFallback === void 0 ? void 0 : oldTrackFallback.id,
|
|
2383
|
+
sendersCount: senders === null || senders === void 0 ? void 0 : senders.length,
|
|
2384
|
+
sendersAnalytics,
|
|
2385
|
+
});
|
|
2386
|
+
reject("No sender track to replace");
|
|
2387
|
+
}
|
|
2388
|
+
return;
|
|
2374
2389
|
}
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
}), 1000);
|
|
2382
|
-
return result;
|
|
2390
|
+
clearInterval(timer);
|
|
2391
|
+
timer = null;
|
|
2392
|
+
const trackReplaced = yield trackReplacedPromise;
|
|
2393
|
+
resolve(trackReplaced);
|
|
2394
|
+
}), 1000);
|
|
2395
|
+
});
|
|
2383
2396
|
}
|
|
2384
2397
|
const stream = this.streams.find((s) => s.getTracks().find((t) => t.id === newTrack.id)) || this.streams[0];
|
|
2385
2398
|
if (!stream) {
|
|
@@ -2389,14 +2402,16 @@ class Session {
|
|
|
2389
2402
|
}
|
|
2390
2403
|
if (!this.canModifyPeerConnection()) {
|
|
2391
2404
|
this.pending.push(() => {
|
|
2392
|
-
this.replaceTrack(
|
|
2405
|
+
this.replaceTrack(oldTrackToReplace, newTrack);
|
|
2393
2406
|
});
|
|
2394
2407
|
return;
|
|
2395
2408
|
}
|
|
2396
2409
|
this.isOperationPending = true;
|
|
2397
2410
|
const onn = pc.onnegotiationneeded;
|
|
2398
2411
|
pc.onnegotiationneeded = null;
|
|
2399
|
-
|
|
2412
|
+
if (oldTrackToReplace) {
|
|
2413
|
+
this.removeTrack(oldTrackToReplace);
|
|
2414
|
+
}
|
|
2400
2415
|
this.addTrack(newTrack);
|
|
2401
2416
|
setTimeout(() => {
|
|
2402
2417
|
pc.onnegotiationneeded = onn;
|