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.
Files changed (94) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/audioProcessing-0z5KlcmO.js +35 -0
  3. package/dist/audioProcessing-0z5KlcmO.js.map +1 -0
  4. package/dist/audioProcessing-BpbrdCk-.cjs +34 -0
  5. package/dist/audioProcessing-BpbrdCk-.cjs.map +1 -0
  6. package/dist/consumers/audioProcessing.d.ts +8 -0
  7. package/dist/consumers/audioProcessing.d.ts.map +1 -0
  8. package/dist/consumers/connectIps.d.ts.map +1 -1
  9. package/dist/consumers/createSendTransport.d.ts.map +1 -1
  10. package/dist/consumers/gridLayout/addVideosGrid.engine.d.ts +6 -0
  11. package/dist/consumers/gridLayout/addVideosGrid.engine.d.ts.map +1 -1
  12. package/dist/consumers/index.cjs +3 -2
  13. package/dist/consumers/index.cjs.map +1 -1
  14. package/dist/consumers/index.js +14 -13
  15. package/dist/consumers/signalNewConsumerTransport.d.ts.map +1 -1
  16. package/dist/consumers/switchUserAudio.d.ts +3 -1
  17. package/dist/consumers/switchUserAudio.d.ts.map +1 -1
  18. package/dist/consumers/transportRecovery.d.ts +8 -0
  19. package/dist/consumers/transportRecovery.d.ts.map +1 -0
  20. package/dist/{getParticipantMedia-BH3d_-Q1.cjs → getParticipantMedia-CP4hE5Rg.cjs} +9 -4
  21. package/dist/getParticipantMedia-CP4hE5Rg.cjs.map +1 -0
  22. package/dist/{getParticipantMedia-CGqnSb93.js → getParticipantMedia-CvXdDj03.js} +9 -4
  23. package/dist/getParticipantMedia-CvXdDj03.js.map +1 -0
  24. package/dist/index.cjs +138 -25
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +205 -92
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.native.cjs +8 -7
  31. package/dist/index.native.cjs.map +1 -1
  32. package/dist/index.native.js +19 -18
  33. package/dist/{joinLocalRoom-7ibqv7zZ.js → joinLocalRoom-Cx1y3Ojj.js} +4 -4
  34. package/dist/{joinLocalRoom-7ibqv7zZ.js.map → joinLocalRoom-Cx1y3Ojj.js.map} +1 -1
  35. package/dist/{joinLocalRoom-BJBDvTYh.cjs → joinLocalRoom-DNJ2zb8W.cjs} +10 -10
  36. package/dist/{joinLocalRoom-BJBDvTYh.cjs.map → joinLocalRoom-DNJ2zb8W.cjs.map} +1 -1
  37. package/dist/{joinRoomOnMediaSFU-y6vJ1OBo.js → joinRoomOnMediaSFU-BnAWLciF.js} +9 -3
  38. package/dist/joinRoomOnMediaSFU-BnAWLciF.js.map +1 -0
  39. package/dist/{joinRoomOnMediaSFU-CC8RVJgr.cjs → joinRoomOnMediaSFU-D2C7q1GK.cjs} +9 -3
  40. package/dist/joinRoomOnMediaSFU-D2C7q1GK.cjs.map +1 -0
  41. package/dist/methods/index.cjs +3 -3
  42. package/dist/methods/index.js +3 -3
  43. package/dist/methods/stream/clickAudio.d.ts +3 -1
  44. package/dist/methods/stream/clickAudio.d.ts.map +1 -1
  45. package/dist/methods/stream/switchAudio.d.ts +3 -1
  46. package/dist/methods/stream/switchAudio.d.ts.map +1 -1
  47. package/dist/methods/utils/headless/virtualBackground.d.ts +15 -1
  48. package/dist/methods/utils/headless/virtualBackground.d.ts.map +1 -1
  49. package/dist/methods/utils/virtualBackgroundCompositor.d.ts +4 -0
  50. package/dist/methods/utils/virtualBackgroundCompositor.d.ts.map +1 -1
  51. package/dist/methods/utils/virtualBackgroundFrameLoop.d.ts +10 -0
  52. package/dist/methods/utils/virtualBackgroundFrameLoop.d.ts.map +1 -0
  53. package/dist/sockets/SocketManager.d.ts +0 -27
  54. package/dist/sockets/SocketManager.d.ts.map +1 -1
  55. package/dist/{translationConsumerSwitch-C20MfNNq.cjs → translationConsumerSwitch-BAsQUpH6.cjs} +9 -1
  56. package/dist/translationConsumerSwitch-BAsQUpH6.cjs.map +1 -0
  57. package/dist/{translationConsumerSwitch-zKuS5wgH.js → translationConsumerSwitch-BUODiT6o.js} +20 -12
  58. package/dist/translationConsumerSwitch-BUODiT6o.js.map +1 -0
  59. package/dist/types/index.cjs +3 -3
  60. package/dist/types/index.js +3 -3
  61. package/dist/types/shared-base-types.d.ts +12 -0
  62. package/dist/types/shared-base-types.d.ts.map +1 -1
  63. package/dist/{updateParticipantAudioDecibels-bZ6R8WHj.cjs → updateParticipantAudioDecibels-BJ2PxJJD.cjs} +287 -58
  64. package/dist/updateParticipantAudioDecibels-BJ2PxJJD.cjs.map +1 -0
  65. package/dist/{updateParticipantAudioDecibels-C_MygF6q.js → updateParticipantAudioDecibels-DiJ_LFfH.js} +284 -55
  66. package/dist/updateParticipantAudioDecibels-DiJ_LFfH.js.map +1 -0
  67. package/package.json +1 -1
  68. package/src/consumers/audioProcessing.ts +26 -0
  69. package/src/consumers/connectIps.ts +46 -7
  70. package/src/consumers/createSendTransport.ts +5 -20
  71. package/src/consumers/gridLayout/addVideosGrid.engine.ts +13 -0
  72. package/src/consumers/signalNewConsumerTransport.ts +7 -25
  73. package/src/consumers/switchUserAudio.ts +18 -5
  74. package/src/consumers/transportRecovery.ts +170 -0
  75. package/src/index.ts +2 -0
  76. package/src/methods/stream/clickAudio.ts +13 -5
  77. package/src/methods/stream/switchAudio.ts +10 -1
  78. package/src/methods/utils/headless/virtualBackground.ts +55 -15
  79. package/src/methods/utils/virtualBackgroundCompositor.ts +18 -1
  80. package/src/methods/utils/virtualBackgroundFrameLoop.ts +69 -0
  81. package/src/sockets/SocketManager.ts +54 -7
  82. package/src/types/shared-base-types.ts +3 -0
  83. package/dist/getParticipantMedia-BH3d_-Q1.cjs.map +0 -1
  84. package/dist/getParticipantMedia-CGqnSb93.js.map +0 -1
  85. package/dist/joinRoomOnMediaSFU-CC8RVJgr.cjs.map +0 -1
  86. package/dist/joinRoomOnMediaSFU-y6vJ1OBo.js.map +0 -1
  87. package/dist/translationConsumerSwitch-C20MfNNq.cjs.map +0 -1
  88. package/dist/translationConsumerSwitch-zKuS5wgH.js.map +0 -1
  89. package/dist/updateParticipantAudioDecibels-C_MygF6q.js.map +0 -1
  90. package/dist/updateParticipantAudioDecibels-bZ6R8WHj.cjs.map +0 -1
  91. package/dist/validateAlphanumeric-DKn5BsUP.cjs +0 -15
  92. package/dist/validateAlphanumeric-DKn5BsUP.cjs.map +0 -1
  93. package/dist/validateAlphanumeric-Dk1JB80W.js +0 -16
  94. 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-BJBDvTYh.cjs");
4
- const updateParticipantAudioDecibels = require("./updateParticipantAudioDecibels-bZ6R8WHj.cjs");
5
- const joinRoomOnMediaSFU = require("./joinRoomOnMediaSFU-CC8RVJgr.cjs");
6
- const translationConsumerSwitch = require("./translationConsumerSwitch-C20MfNNq.cjs");
7
- const getParticipantMedia = require("./getParticipantMedia-BH3d_-Q1.cjs");
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 validateAlphanumeric = require("./validateAlphanumeric-DKn5BsUP.cjs");
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
- ctx.drawImage(sourceImage, 0, 0, width, height);
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 backgroundImage = typeof image === "string" ? await loadImage(image) : image;
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
- let frameHandle = 0;
2400
- const pump = async () => {
2401
- if (stopped) return;
2402
- try {
2403
- if (video.readyState >= 2) await segmentation.send({ image: video });
2404
- } catch {
2405
- }
2406
- frameHandle = window.requestAnimationFrame(() => {
2407
- void pump();
2408
- });
2409
- };
2410
- void pump();
2411
- const processed = canvas.captureStream(frameRate);
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
- window.cancelAnimationFrame(frameHandle);
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 = validateAlphanumeric.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