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
feat(virtual-background): report V2 startup config and init failures to analytics
Jaya Allamsetty36d4c1c79450
diff --git a/react/features/analytics/AnalyticsEvents.ts b/react/features/analytics/AnalyticsEvents.tsindex 7a780d3424..ac007534c8 100644--- a/react/features/analytics/AnalyticsEvents.ts+++ b/react/features/analytics/AnalyticsEvents.ts@@ -956,3 +956,32 @@ export function createRestrictWhiteboardEvent() {action: 'whiteboard.restrict'};}++/**+ * Creates an event with the startup configuration the V2 virtual background engine is running with.+ *+ * @param {Object} attributes - The detected and applied tier, backend, pipeline, compositor and+ * segmentation size.+ * @returns {Object} The event in a format suitable for sending via sendAnalytics.+ */+export function createVirtualBackgroundV2StartedEvent(attributes: Object) {+ return {+ action: 'started',+ actionSubject: 'virtual.background.v2',+ attributes+ };+}++/**+ * Creates an event which indicates that the V2 virtual background engine failed to start.+ *+ * @param {Object} attributes - The requested startup configuration and the error.+ * @returns {Object} The event in a format suitable for sending via sendAnalytics.+ */+export function createVirtualBackgroundV2FailedEvent(attributes: Object) {+ return {+ action: 'failed',+ actionSubject: 'virtual.background.v2',+ attributes+ };+}diff --git a/react/features/stream-effects/virtual-background/DeviceTierDetector.ts b/react/features/stream-effects/virtual-background/DeviceTierDetector.tsindex b5617ea035..8e8d1d4d42 100644--- a/react/features/stream-effects/virtual-background/DeviceTierDetector.ts+++ b/react/features/stream-effects/virtual-background/DeviceTierDetector.ts@@ -15,6 +15,7 @@ export enum DeviceTier {export interface IDeviceCapabilities {backend: BackendType;+ hardwareTier: DeviceTier;segHeight: number;segWidth: number;targetFps: number;@@ -115,6 +116,7 @@ export async function detectDeviceTier(const profile = TIER_PROFILES[hardwareTier];const caps: IDeviceCapabilities = {...profile,+ hardwareTier,tier: hardwareTier};diff --git a/react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.ts b/react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.tsindex 7f5d37e65b..3c6f1b6c1a 100644--- a/react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.ts+++ b/react/features/stream-effects/virtual-background/JitsiStreamBackgroundEffect.ts@@ -4,7 +4,7 @@ import logger from '../../virtual-background/logger';import { IVirtualBackground } from '../../virtual-background/reducer';import BackgroundFrameProcessor from './BackgroundFrameProcessor';-import { IDeviceCapabilities } from './DeviceTierDetector';+import { BackendType, DeviceTier, IDeviceCapabilities } from './DeviceTierDetector';import WorkerSegmentationBackend from './backend/WorkerSegmentationBackend';import Canvas2DCompositor from './compositor/Canvas2DCompositor';import { ICompositor } from './compositor/ICompositor';@@ -34,6 +34,19 @@ export interface IV2EffectInit {vbConfig?: IVirtualBackgroundAdvancedConfig;}+/**+ * The startup configuration a V2 effect actually runs with, for analytics.+ */+export interface IV2StartupConfig {+ backend: BackendType;+ compositor: string;+ hardwareTier: DeviceTier;+ pipeline: string;+ segHeight: number;+ segWidth: number;+ tier: DeviceTier;+}+/*** Virtual background stream effect.@@ -48,6 +61,7 @@ export interface IV2EffectInit {*/export default class JitsiStreamBackgroundEffect {_backend: WorkerSegmentationBackend | null = null;+ _compositorName: string | null = null;_enableV2: boolean;_inputVideoElement: HTMLVideoElement;_maskFrameTimerWorker: Worker | null = null;@@ -81,6 +95,29 @@ export default class JitsiStreamBackgroundEffect {}}+ /**+ * The V2 startup configuration in use, including any worker fallback once {@code init} has resolved.+ *+ * @returns {IV2StartupConfig|undefined} Undefined for V1.+ */+ get v2StartupConfig(): IV2StartupConfig | undefined {+ if (!this._backend || !this._compositorName) {+ return undefined;+ }++ const { backend, hardwareTier, segHeight, segWidth, tier } = this._backend.capabilities;++ return {+ backend,+ compositor: this._compositorName,+ hardwareTier,+ pipeline: this._pipeline ? 'insertable-streams' : 'capture-stream',+ segHeight,+ segWidth,+ tier+ };+ }+/*** Creates a new background effect instance.*@@ -112,9 +149,11 @@ export default class JitsiStreamBackgroundEffect {if (webglCompositor.isAvailable) {compositor = webglCompositor;+ this._compositorName = 'webgl';} else {logger.debug('[VirtualBackground] WebGL unavailable — using Canvas 2D fallback');compositor = new Canvas2DCompositor();+ this._compositorName = 'canvas-2d';}this._processor = new BackgroundFrameProcessor({@@ -137,7 +176,7 @@ export default class JitsiStreamBackgroundEffect {logger.debug(`[VirtualBackground] V2 effect created — backend: ${this._backend.capabilities.backend}`+ `, pipeline: ${useIS ? 'insertable-streams' : 'capture-stream'}`- + `, compositor: ${compositor instanceof WebGLCompositor ? 'webgl' : 'canvas-2d'}`+ + `, compositor: ${this._compositorName}`);return;diff --git a/react/features/stream-effects/virtual-background/index.ts b/react/features/stream-effects/virtual-background/index.tsindex 9cb1347ad8..906cb74993 100644--- a/react/features/stream-effects/virtual-background/index.ts+++ b/react/features/stream-effects/virtual-background/index.ts@@ -1,4 +1,9 @@/* eslint-disable lines-around-comment */+import {+ createVirtualBackgroundV2FailedEvent,+ createVirtualBackgroundV2StartedEvent+} from '../../analytics/AnalyticsEvents';+import { sendAnalytics } from '../../analytics/functions';import { showWarningNotification } from '../../notifications/actions';import { NOTIFICATION_TIMEOUT_TYPE } from '../../notifications/constants';import { timeout } from '../../virtual-background/functions';@@ -21,6 +26,23 @@ let modelBuffer: ArrayBuffer;let tflite: any;let wasmCheck: any;let isWasmDisabled = false;+const reportedV2Events = new Set<string>();++/**+ * Sends a V2 startup analytics event once per distinct payload, since an effect is created for every+ * preview and track (re)creation.+ *+ * @param {Object} event - The analytics event.+ * @returns {void}+ */+function sendV2StartupEvent(event: Object) {+ const key = JSON.stringify(event);++ if (!reportedV2Events.has(key)) {+ reportedV2Events.add(key);+ sendAnalytics(event);+ }+}/*** Creates a new instance of the virtual background stream effect.@@ -57,7 +79,25 @@ export async function createVirtualBackgroundEffect(virtualBackground: IVirtualBvbConfig});- await effect.init();+ try {+ await effect.init();+ } catch (error: any) {+ sendV2StartupEvent(createVirtualBackgroundV2FailedEvent({+ ...effect.v2StartupConfig,+ error: String(error?.message ?? error)+ }));++ throw error;+ }++ const startup = effect.v2StartupConfig;++ if (startup) {+ sendV2StartupEvent(createVirtualBackgroundV2StartedEvent({+ ...startup,+ workerFallback: startup.backend !== capabilities.backend+ }));+ }return effect;}