Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
test(virtual-background): add mute/unmute coverage for V2 effect lifecycle
Jaya Allamsettye2020a2c978f
diff --git a/tests/specs/misc/virtualBackgroundV2.spec.ts b/tests/specs/misc/virtualBackgroundV2.spec.tsindex f60e9ae818..a56adf7b02 100644--- a/tests/specs/misc/virtualBackgroundV2.spec.ts+++ b/tests/specs/misc/virtualBackgroundV2.spec.ts@@ -35,6 +35,77 @@ async function openVBDialog() {await ctx.p1.getVirtualBackgroundDialog().waitForDisplay();}+/**+ * Samples a 16x16 region from the local video element and returns the summed pixel variance+ * across the R, G, B channels. A solid-colour (e.g. all-black) frame returns ~0; a normal video+ * frame returns a large positive value. Returns -1 when the video element is not yet ready.+ *+ * Used to assert that the local video is rendering live content after a track or effect+ * restart, rather than a stuck/black surface — the exact failure mode caused by the V2+ * compositor not being re-initialised after dispose.+ *+ * @returns {Promise<number>} Sum of per-channel variance, or -1 if the video is not ready.+ */+async function getLocalVideoPixelVariance(): Promise<number> {+ return ctx.p1.execute(() => {+ const video = document.querySelector('#localVideoContainer video') as HTMLVideoElement | null;++ if (!video || video.readyState < 2 || video.videoWidth === 0) {+ return -1;+ }++ const w = 16;+ const h = 16;+ const canvas = document.createElement('canvas');++ canvas.width = w;+ canvas.height = h;++ const c2d = canvas.getContext('2d');++ if (!c2d) {+ return -1;+ }++ c2d.drawImage(video, 0, 0, w, h);+ const { data } = c2d.getImageData(0, 0, w, h);+ const n = data.length / 4;+ let sumR = 0, sumG = 0, sumB = 0;++ for (let i = 0; i < data.length; i += 4) {+ sumR += data[i];+ sumG += data[i + 1];+ sumB += data[i + 2];+ }+ const meanR = sumR / n;+ const meanG = sumG / n;+ const meanB = sumB / n;+ let varSum = 0;++ for (let i = 0; i < data.length; i += 4) {+ varSum += (data[i] - meanR) ** 2;+ varSum += (data[i + 1] - meanG) ** 2;+ varSum += (data[i + 2] - meanB) ** 2;+ }++ return varSum;+ });+}++/**+ * Polls {@link getLocalVideoPixelVariance} until it exceeds the threshold or the timeout fires.+ *+ * @param {number} timeout - How long to wait in ms.+ * @param {number} minVariance - Minimum acceptable variance. The default (100) is well above+ * the floor for a black frame (~0) and far below a typical fake-device frame (millions).+ */+async function waitForLocalVideoFrames(timeout = 15000, minVariance = 100): Promise<void> {+ await ctx.p1.driver.waitUntil(+ async () => (await getLocalVideoPixelVariance()) > minVariance,+ { timeout, timeoutMsg: `Local video did not produce non-black frames within ${timeout}ms` }+ );+}+/*** Waits until backgroundEffectEnabled settles to the expected value.* When expecting true, the value must remain stable for stabilityWindow ms to confirm the@@ -106,6 +177,33 @@ describe('Virtual backgrounds V2 engine', () => {expect(state.selectedThumbnail).toBe('blur');});+ it('mute and unmute camera while blur is active — effect resumes without black frames', async () => {+ // Blur was enabled by the prior test.+ let state = await getVBState();++ expect(state.backgroundEffectEnabled).toBe(true);+ expect(state.backgroundType).toBe('blur');++ // Baseline: local video is rendering non-uniform content with the effect applied.+ await waitForLocalVideoFrames();++ // Mute then unmute. This drives stopEffect -> startEffect on the effect, which in+ // turn calls compositor.dispose() then BackgroundFrameProcessor.init(). Before the+ // fix the compositor stayed disposed and the local video went black on unmute.+ await ctx.p1.getToolbar().clickVideoMuteButton();+ await ctx.p1.driver.pause(500);+ await ctx.p1.getToolbar().clickVideoUnmuteButton();++ // The compositor must be re-initialised — local video should resume rendering+ // non-black frames within a normal startup window.+ await waitForLocalVideoFrames();++ // Effect state should remain consistent.+ state = await getVBState();+ expect(state.backgroundEffectEnabled).toBe(true);+ expect(state.backgroundType).toBe('blur');+ });+it('select slight blur with V2 engine — redux state correct', async () => {await openVBDialog();const vbDialog = ctx.p1.getVirtualBackgroundDialog();