mediasfu-shared 1.2.2 → 1.2.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/CHANGELOG.md +5 -0
- package/dist/audioProcessing-0z5KlcmO.js +35 -0
- package/dist/audioProcessing-0z5KlcmO.js.map +1 -0
- package/dist/audioProcessing-BpbrdCk-.cjs +34 -0
- package/dist/audioProcessing-BpbrdCk-.cjs.map +1 -0
- package/dist/consumers/audioProcessing.d.ts +8 -0
- package/dist/consumers/audioProcessing.d.ts.map +1 -0
- package/dist/consumers/connectIps.d.ts.map +1 -1
- package/dist/consumers/createSendTransport.d.ts.map +1 -1
- package/dist/consumers/gridLayout/addVideosGrid.engine.d.ts +6 -0
- package/dist/consumers/gridLayout/addVideosGrid.engine.d.ts.map +1 -1
- package/dist/consumers/index.cjs +3 -2
- package/dist/consumers/index.cjs.map +1 -1
- package/dist/consumers/index.js +14 -13
- package/dist/consumers/signalNewConsumerTransport.d.ts.map +1 -1
- package/dist/consumers/switchUserAudio.d.ts +3 -1
- package/dist/consumers/switchUserAudio.d.ts.map +1 -1
- package/dist/consumers/transportRecovery.d.ts +8 -0
- package/dist/consumers/transportRecovery.d.ts.map +1 -0
- package/dist/{getParticipantMedia-BH3d_-Q1.cjs → getParticipantMedia-CP4hE5Rg.cjs} +9 -4
- package/dist/getParticipantMedia-CP4hE5Rg.cjs.map +1 -0
- package/dist/{getParticipantMedia-CGqnSb93.js → getParticipantMedia-CvXdDj03.js} +9 -4
- package/dist/getParticipantMedia-CvXdDj03.js.map +1 -0
- package/dist/index.cjs +138 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -92
- package/dist/index.js.map +1 -1
- package/dist/index.native.cjs +8 -7
- package/dist/index.native.cjs.map +1 -1
- package/dist/index.native.js +19 -18
- package/dist/{joinLocalRoom-7ibqv7zZ.js → joinLocalRoom-Cx1y3Ojj.js} +4 -4
- package/dist/{joinLocalRoom-7ibqv7zZ.js.map → joinLocalRoom-Cx1y3Ojj.js.map} +1 -1
- package/dist/{joinLocalRoom-BJBDvTYh.cjs → joinLocalRoom-DNJ2zb8W.cjs} +10 -10
- package/dist/{joinLocalRoom-BJBDvTYh.cjs.map → joinLocalRoom-DNJ2zb8W.cjs.map} +1 -1
- package/dist/{joinRoomOnMediaSFU-y6vJ1OBo.js → joinRoomOnMediaSFU-BnAWLciF.js} +9 -3
- package/dist/joinRoomOnMediaSFU-BnAWLciF.js.map +1 -0
- package/dist/{joinRoomOnMediaSFU-CC8RVJgr.cjs → joinRoomOnMediaSFU-D2C7q1GK.cjs} +9 -3
- package/dist/joinRoomOnMediaSFU-D2C7q1GK.cjs.map +1 -0
- package/dist/methods/index.cjs +3 -3
- package/dist/methods/index.js +3 -3
- package/dist/methods/stream/clickAudio.d.ts +3 -1
- package/dist/methods/stream/clickAudio.d.ts.map +1 -1
- package/dist/methods/stream/switchAudio.d.ts +3 -1
- package/dist/methods/stream/switchAudio.d.ts.map +1 -1
- package/dist/methods/utils/headless/virtualBackground.d.ts +15 -1
- package/dist/methods/utils/headless/virtualBackground.d.ts.map +1 -1
- package/dist/methods/utils/virtualBackgroundCompositor.d.ts +4 -0
- package/dist/methods/utils/virtualBackgroundCompositor.d.ts.map +1 -1
- package/dist/methods/utils/virtualBackgroundFrameLoop.d.ts +10 -0
- package/dist/methods/utils/virtualBackgroundFrameLoop.d.ts.map +1 -0
- package/dist/sockets/SocketManager.d.ts +0 -27
- package/dist/sockets/SocketManager.d.ts.map +1 -1
- package/dist/{translationConsumerSwitch-C20MfNNq.cjs → translationConsumerSwitch-BAsQUpH6.cjs} +9 -1
- package/dist/translationConsumerSwitch-BAsQUpH6.cjs.map +1 -0
- package/dist/{translationConsumerSwitch-zKuS5wgH.js → translationConsumerSwitch-BUODiT6o.js} +20 -12
- package/dist/translationConsumerSwitch-BUODiT6o.js.map +1 -0
- package/dist/types/index.cjs +3 -3
- package/dist/types/index.js +3 -3
- package/dist/types/shared-base-types.d.ts +12 -0
- package/dist/types/shared-base-types.d.ts.map +1 -1
- package/dist/{updateParticipantAudioDecibels-bZ6R8WHj.cjs → updateParticipantAudioDecibels-BJ2PxJJD.cjs} +287 -58
- package/dist/updateParticipantAudioDecibels-BJ2PxJJD.cjs.map +1 -0
- package/dist/{updateParticipantAudioDecibels-C_MygF6q.js → updateParticipantAudioDecibels-DiJ_LFfH.js} +284 -55
- package/dist/updateParticipantAudioDecibels-DiJ_LFfH.js.map +1 -0
- package/package.json +1 -1
- package/src/consumers/audioProcessing.ts +26 -0
- package/src/consumers/connectIps.ts +46 -7
- package/src/consumers/createSendTransport.ts +5 -20
- package/src/consumers/gridLayout/addVideosGrid.engine.ts +13 -0
- package/src/consumers/signalNewConsumerTransport.ts +7 -25
- package/src/consumers/switchUserAudio.ts +18 -5
- package/src/consumers/transportRecovery.ts +170 -0
- package/src/index.ts +2 -0
- package/src/methods/stream/clickAudio.ts +13 -5
- package/src/methods/stream/switchAudio.ts +10 -1
- package/src/methods/utils/headless/virtualBackground.ts +55 -15
- package/src/methods/utils/virtualBackgroundCompositor.ts +18 -1
- package/src/methods/utils/virtualBackgroundFrameLoop.ts +69 -0
- package/src/sockets/SocketManager.ts +54 -7
- package/src/types/shared-base-types.ts +3 -0
- package/dist/getParticipantMedia-BH3d_-Q1.cjs.map +0 -1
- package/dist/getParticipantMedia-CGqnSb93.js.map +0 -1
- package/dist/joinRoomOnMediaSFU-CC8RVJgr.cjs.map +0 -1
- package/dist/joinRoomOnMediaSFU-y6vJ1OBo.js.map +0 -1
- package/dist/translationConsumerSwitch-C20MfNNq.cjs.map +0 -1
- package/dist/translationConsumerSwitch-zKuS5wgH.js.map +0 -1
- package/dist/updateParticipantAudioDecibels-C_MygF6q.js.map +0 -1
- package/dist/updateParticipantAudioDecibels-bZ6R8WHj.cjs.map +0 -1
- package/dist/validateAlphanumeric-DKn5BsUP.cjs +0 -15
- package/dist/validateAlphanumeric-DKn5BsUP.cjs.map +0 -1
- package/dist/validateAlphanumeric-Dk1JB80W.js +0 -16
- package/dist/validateAlphanumeric-Dk1JB80W.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const joinLocalRoom = require("./joinLocalRoom-
|
|
4
|
-
const updateParticipantAudioDecibels = require("./updateParticipantAudioDecibels-
|
|
5
|
-
const joinRoomOnMediaSFU = require("./joinRoomOnMediaSFU-
|
|
6
|
-
const translationConsumerSwitch = require("./translationConsumerSwitch-
|
|
7
|
-
const getParticipantMedia = require("./getParticipantMedia-
|
|
3
|
+
const joinLocalRoom = require("./joinLocalRoom-DNJ2zb8W.cjs");
|
|
4
|
+
const updateParticipantAudioDecibels = require("./updateParticipantAudioDecibels-BJ2PxJJD.cjs");
|
|
5
|
+
const joinRoomOnMediaSFU = require("./joinRoomOnMediaSFU-D2C7q1GK.cjs");
|
|
6
|
+
const translationConsumerSwitch = require("./translationConsumerSwitch-BAsQUpH6.cjs");
|
|
7
|
+
const getParticipantMedia = require("./getParticipantMedia-CP4hE5Rg.cjs");
|
|
8
8
|
const methods_index = require("./methods/index.cjs");
|
|
9
|
-
const
|
|
9
|
+
const audioProcessing = require("./audioProcessing-BpbrdCk-.cjs");
|
|
10
10
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
11
11
|
var selfie_segmentation = {};
|
|
12
12
|
var hasRequiredSelfie_segmentation;
|
|
@@ -2284,6 +2284,11 @@ function requireSelfie_segmentation() {
|
|
|
2284
2284
|
return selfie_segmentation;
|
|
2285
2285
|
}
|
|
2286
2286
|
var selfie_segmentationExports = /* @__PURE__ */ requireSelfie_segmentation();
|
|
2287
|
+
const VIRTUAL_BACKGROUND_BLUR = "blur";
|
|
2288
|
+
const DEFAULT_BACKGROUND_BLUR_PIXELS = 16;
|
|
2289
|
+
function isVirtualBackgroundBlur(value) {
|
|
2290
|
+
return value === VIRTUAL_BACKGROUND_BLUR;
|
|
2291
|
+
}
|
|
2287
2292
|
function compositeVirtualBackgroundFrame({
|
|
2288
2293
|
ctx,
|
|
2289
2294
|
segmentationMask,
|
|
@@ -2309,7 +2314,14 @@ function compositeVirtualBackgroundFrame({
|
|
|
2309
2314
|
ctx.fillRect(0, 0, width, height);
|
|
2310
2315
|
} else if (blurFallbackPixels > 0) {
|
|
2311
2316
|
ctx.filter = `blur(${blurFallbackPixels}px)`;
|
|
2312
|
-
|
|
2317
|
+
const bleed = Math.max(2, blurFallbackPixels * 2);
|
|
2318
|
+
ctx.drawImage(
|
|
2319
|
+
sourceImage,
|
|
2320
|
+
-bleed,
|
|
2321
|
+
-bleed,
|
|
2322
|
+
width + bleed * 2,
|
|
2323
|
+
height + bleed * 2
|
|
2324
|
+
);
|
|
2313
2325
|
}
|
|
2314
2326
|
} finally {
|
|
2315
2327
|
ctx.filter = previousFilter || "none";
|
|
@@ -2317,6 +2329,86 @@ function compositeVirtualBackgroundFrame({
|
|
|
2317
2329
|
ctx.restore();
|
|
2318
2330
|
}
|
|
2319
2331
|
}
|
|
2332
|
+
const activeLoops = /* @__PURE__ */ new WeakMap();
|
|
2333
|
+
const activeFrames = /* @__PURE__ */ new WeakMap();
|
|
2334
|
+
function startVirtualBackgroundFrameLoop({
|
|
2335
|
+
owner,
|
|
2336
|
+
processFrame,
|
|
2337
|
+
shouldContinue,
|
|
2338
|
+
keepProcessingWhenHidden = true
|
|
2339
|
+
}) {
|
|
2340
|
+
activeLoops.get(owner)?.();
|
|
2341
|
+
let stopped = false;
|
|
2342
|
+
let inFlight = false;
|
|
2343
|
+
let animationFrameId = null;
|
|
2344
|
+
let timeoutId = null;
|
|
2345
|
+
const cancelScheduledFrame = () => {
|
|
2346
|
+
if (animationFrameId !== null) cancelAnimationFrame(animationFrameId);
|
|
2347
|
+
if (timeoutId !== null) clearTimeout(timeoutId);
|
|
2348
|
+
animationFrameId = null;
|
|
2349
|
+
timeoutId = null;
|
|
2350
|
+
};
|
|
2351
|
+
const stop = () => {
|
|
2352
|
+
if (stopped) return;
|
|
2353
|
+
stopped = true;
|
|
2354
|
+
cancelScheduledFrame();
|
|
2355
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
2356
|
+
if (activeLoops.get(owner) === stop) activeLoops.delete(owner);
|
|
2357
|
+
};
|
|
2358
|
+
const schedule = () => {
|
|
2359
|
+
if (stopped || inFlight) return;
|
|
2360
|
+
if (!shouldContinue()) {
|
|
2361
|
+
stop();
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
if (document.hidden && keepProcessingWhenHidden) {
|
|
2365
|
+
timeoutId = setTimeout(() => {
|
|
2366
|
+
void runFrame();
|
|
2367
|
+
}, 1e3);
|
|
2368
|
+
} else {
|
|
2369
|
+
animationFrameId = requestAnimationFrame(() => {
|
|
2370
|
+
void runFrame();
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
};
|
|
2374
|
+
const runFrame = async () => {
|
|
2375
|
+
animationFrameId = null;
|
|
2376
|
+
timeoutId = null;
|
|
2377
|
+
if (stopped || inFlight) return;
|
|
2378
|
+
if (!shouldContinue()) {
|
|
2379
|
+
stop();
|
|
2380
|
+
return;
|
|
2381
|
+
}
|
|
2382
|
+
inFlight = true;
|
|
2383
|
+
try {
|
|
2384
|
+
const previousFrame = activeFrames.get(owner);
|
|
2385
|
+
if (previousFrame) await previousFrame.catch(() => void 0);
|
|
2386
|
+
if (stopped || !shouldContinue()) {
|
|
2387
|
+
stop();
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
const currentFrame = Promise.resolve(processFrame());
|
|
2391
|
+
activeFrames.set(owner, currentFrame);
|
|
2392
|
+
try {
|
|
2393
|
+
await currentFrame;
|
|
2394
|
+
} finally {
|
|
2395
|
+
if (activeFrames.get(owner) === currentFrame) activeFrames.delete(owner);
|
|
2396
|
+
}
|
|
2397
|
+
} catch {
|
|
2398
|
+
} finally {
|
|
2399
|
+
inFlight = false;
|
|
2400
|
+
schedule();
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
const onVisibilityChange = () => {
|
|
2404
|
+
cancelScheduledFrame();
|
|
2405
|
+
schedule();
|
|
2406
|
+
};
|
|
2407
|
+
activeLoops.set(owner, stop);
|
|
2408
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
2409
|
+
void runFrame();
|
|
2410
|
+
return stop;
|
|
2411
|
+
}
|
|
2320
2412
|
const MEDIAPIPE_CDN = "https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation";
|
|
2321
2413
|
let session = null;
|
|
2322
2414
|
function loadImage(src) {
|
|
@@ -2334,7 +2426,9 @@ async function applyVirtualBackground({
|
|
|
2334
2426
|
frameRate = 30,
|
|
2335
2427
|
modelSelection = 1,
|
|
2336
2428
|
publish = true,
|
|
2337
|
-
assetPath = MEDIAPIPE_CDN
|
|
2429
|
+
assetPath = MEDIAPIPE_CDN,
|
|
2430
|
+
blurPixels = 0,
|
|
2431
|
+
keepProcessingWhenHidden = true
|
|
2338
2432
|
}) {
|
|
2339
2433
|
const live = getParticipantMedia.getCurrentParams({ parameters });
|
|
2340
2434
|
if (live.audioOnlyRoom) {
|
|
@@ -2354,7 +2448,8 @@ async function applyVirtualBackground({
|
|
|
2354
2448
|
const settings = sourceTrack.getSettings ? sourceTrack.getSettings() : {};
|
|
2355
2449
|
const width = Number(settings.width) || 640;
|
|
2356
2450
|
const height = Number(settings.height) || 360;
|
|
2357
|
-
const
|
|
2451
|
+
const resolvedBlurPixels = Math.max(0, Number(blurPixels) || 0);
|
|
2452
|
+
const backgroundImage = resolvedBlurPixels > 0 ? null : typeof image === "string" ? await loadImage(image) : image;
|
|
2358
2453
|
const producer = publish ? live.videoProducer || live.localVideoProducer : null;
|
|
2359
2454
|
const processingTrack = sourceTrack.clone?.();
|
|
2360
2455
|
if (!processingTrack) throw new Error("This camera cannot create the isolated track required for a virtual background.");
|
|
@@ -2390,32 +2485,34 @@ async function applyVirtualBackground({
|
|
|
2390
2485
|
sourceImage: results.image,
|
|
2391
2486
|
backgroundImage,
|
|
2392
2487
|
width: canvas.width,
|
|
2393
|
-
height: canvas.height
|
|
2488
|
+
height: canvas.height,
|
|
2489
|
+
blurFallbackPixels: resolvedBlurPixels
|
|
2394
2490
|
});
|
|
2395
2491
|
} catch {
|
|
2396
2492
|
}
|
|
2397
2493
|
});
|
|
2398
2494
|
let stopped = false;
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2495
|
+
const stopFrameLoop = startVirtualBackgroundFrameLoop({
|
|
2496
|
+
owner: segmentation,
|
|
2497
|
+
keepProcessingWhenHidden,
|
|
2498
|
+
shouldContinue: () => !stopped && processingTrack.readyState === "live",
|
|
2499
|
+
processFrame: () => video.readyState >= 2 ? segmentation.send({ image: video }) : void 0
|
|
2500
|
+
});
|
|
2501
|
+
let processed;
|
|
2502
|
+
try {
|
|
2503
|
+
processed = canvas.captureStream(frameRate);
|
|
2504
|
+
} catch (error) {
|
|
2505
|
+
stopFrameLoop();
|
|
2506
|
+
throw error;
|
|
2507
|
+
}
|
|
2412
2508
|
if (!processed?.getVideoTracks?.().length) {
|
|
2509
|
+
stopFrameLoop();
|
|
2413
2510
|
throw new Error("The processed background stream produced no video track.");
|
|
2414
2511
|
}
|
|
2415
2512
|
const stop = () => {
|
|
2416
2513
|
if (stopped) return;
|
|
2417
2514
|
stopped = true;
|
|
2418
|
-
|
|
2515
|
+
stopFrameLoop();
|
|
2419
2516
|
try {
|
|
2420
2517
|
segmentation.close();
|
|
2421
2518
|
} catch {
|
|
@@ -2452,6 +2549,16 @@ async function applyVirtualBackground({
|
|
|
2452
2549
|
};
|
|
2453
2550
|
}
|
|
2454
2551
|
}
|
|
2552
|
+
function applyBackgroundBlur({
|
|
2553
|
+
blurPixels = DEFAULT_BACKGROUND_BLUR_PIXELS,
|
|
2554
|
+
...options
|
|
2555
|
+
}) {
|
|
2556
|
+
return applyVirtualBackground({
|
|
2557
|
+
...options,
|
|
2558
|
+
image: null,
|
|
2559
|
+
blurPixels
|
|
2560
|
+
});
|
|
2561
|
+
}
|
|
2455
2562
|
async function clearVirtualBackground({
|
|
2456
2563
|
parameters
|
|
2457
2564
|
}) {
|
|
@@ -2600,6 +2707,7 @@ exports.isSpeakerInMyBreakoutRoom = translationConsumerSwitch.isSpeakerInMyBreak
|
|
|
2600
2707
|
exports.pauseOriginalProducer = translationConsumerSwitch.pauseOriginalProducer;
|
|
2601
2708
|
exports.resolveHostVideoStream = translationConsumerSwitch.resolveHostVideoStream;
|
|
2602
2709
|
exports.resolveMainHostRenderMode = translationConsumerSwitch.resolveMainHostRenderMode;
|
|
2710
|
+
exports.resolveSidePanelForceFullDisplay = translationConsumerSwitch.resolveSidePanelForceFullDisplay;
|
|
2603
2711
|
exports.resumeOriginalProducer = translationConsumerSwitch.resumeOriginalProducer;
|
|
2604
2712
|
exports.stopConsumingTranslation = translationConsumerSwitch.stopConsumingTranslation;
|
|
2605
2713
|
exports.syncTranslationStateAfterBreakoutChange = translationConsumerSwitch.syncTranslationStateAfterBreakoutChange;
|
|
@@ -2821,9 +2929,14 @@ exports.updatedCoHost = methods_index.updatedCoHost;
|
|
|
2821
2929
|
exports.userWaiting = methods_index.userWaiting;
|
|
2822
2930
|
exports.validateWelcomeAlphanumeric = methods_index.validateWelcomeAlphanumeric;
|
|
2823
2931
|
exports.validateWelcomeInputs = methods_index.validateWelcomeInputs;
|
|
2824
|
-
exports.validateAlphanumeric =
|
|
2932
|
+
exports.validateAlphanumeric = audioProcessing.validateAlphanumeric;
|
|
2933
|
+
exports.DEFAULT_BACKGROUND_BLUR_PIXELS = DEFAULT_BACKGROUND_BLUR_PIXELS;
|
|
2934
|
+
exports.VIRTUAL_BACKGROUND_BLUR = VIRTUAL_BACKGROUND_BLUR;
|
|
2935
|
+
exports.applyBackgroundBlur = applyBackgroundBlur;
|
|
2825
2936
|
exports.applyVirtualBackground = applyVirtualBackground;
|
|
2826
2937
|
exports.clearVirtualBackground = clearVirtualBackground;
|
|
2827
2938
|
exports.compositeVirtualBackgroundFrame = compositeVirtualBackgroundFrame;
|
|
2939
|
+
exports.isVirtualBackgroundBlur = isVirtualBackgroundBlur;
|
|
2828
2940
|
exports.isVirtualBackgroundRunning = isVirtualBackgroundRunning;
|
|
2941
|
+
exports.startVirtualBackgroundFrameLoop = startVirtualBackgroundFrameLoop;
|
|
2829
2942
|
//# sourceMappingURL=index.cjs.map
|