mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-21 15:47:09 +00:00
f3626a2dc6
The MediaPipe assets were served under /assets, where the cache behavior differs between wasm and js files. As a result, clients could end up with a fresh js loader paired with a stale wasm binary (or vice versa), leaving MediaPipe out of sync. Copy the assets under a versioned route so the URL changes whenever the dependency version bumps. Clients then reload both the js and the wasm together, keeping them in sync.
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { ProcessorWrapper } from '@livekit/track-processors'
|
|
import type { Track, TrackProcessor } from 'livekit-client'
|
|
import { BackgroundCustomProcessor } from './BackgroundCustomProcessor'
|
|
import { UnifiedBackgroundTrackProcessor } from './UnifiedBackgroundTrackProcessor'
|
|
import { FaceLandmarksOptions } from './FaceLandmarksProcessor'
|
|
|
|
export const SELFIE_SEGMENTER_MODEL_PATH =
|
|
'/assets/mediapipe/models/selfie_segmenter_landscape.tflite'
|
|
|
|
export const FACE_LANDMARKS_MODEL_PATH =
|
|
'/assets/mediapipe/models/face_landmarker.task'
|
|
|
|
export const MEDIAPIPE_PATH_WASM = `/assets/mediapipe/wasm/${__MEDIAPIPE_VERSION__}`
|
|
|
|
export enum ProcessorType {
|
|
BLUR = 'blur',
|
|
VIRTUAL = 'virtual',
|
|
FACE_LANDMARKS = 'faceLandmarks',
|
|
}
|
|
|
|
export type ProcessorConfig =
|
|
| { type: ProcessorType.BLUR; blurRadius: number }
|
|
| { type: ProcessorType.VIRTUAL; imagePath: string; fileId?: string }
|
|
| ({ type: ProcessorType.FACE_LANDMARKS } & FaceLandmarksOptions)
|
|
|
|
export interface BackgroundProcessorInterface extends TrackProcessor<Track.Kind> {
|
|
update(opts: ProcessorConfig): Promise<void>
|
|
options: ProcessorConfig
|
|
}
|
|
|
|
export class BackgroundProcessorFactory {
|
|
static hasModernApiSupport() {
|
|
return ProcessorWrapper.hasModernApiSupport
|
|
}
|
|
|
|
static isSupported() {
|
|
return ProcessorWrapper.isSupported || BackgroundCustomProcessor.isSupported
|
|
}
|
|
|
|
static getProcessor(
|
|
config: ProcessorConfig
|
|
): BackgroundProcessorInterface | undefined {
|
|
const isBlur = config.type === ProcessorType.BLUR
|
|
const isVirtual = config.type === ProcessorType.VIRTUAL
|
|
|
|
if (!isBlur && !isVirtual) return undefined
|
|
|
|
if (ProcessorWrapper.isSupported) {
|
|
return new UnifiedBackgroundTrackProcessor(config)
|
|
}
|
|
|
|
if (BackgroundCustomProcessor.isSupported) {
|
|
return new BackgroundCustomProcessor(config)
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
static fromProcessorConfig(data?: ProcessorConfig) {
|
|
if (data) {
|
|
return BackgroundProcessorFactory.getProcessor(data)
|
|
}
|
|
return undefined
|
|
}
|
|
}
|