From 41f53b9895871402d08306c0a57d638a62cde4ff Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 6 Apr 2022 19:54:31 +0200 Subject: [PATCH] Support Virtual Background image --- openvidu-browser/src/OpenVidu/Stream.ts | 19 ++++++++++++++++--- .../Public/VirtualBackgroundImageOptions.ts | 2 +- .../Public/VirtualBackgroundOptions.ts | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index e6db1789..fcd25e79 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -336,7 +336,7 @@ export class Stream { } } - if (type === 'VB:blur') { + if (type.startsWith('VB:')) { // Client filters @@ -353,7 +353,7 @@ export class Stream { return reject(new OpenViduError(OpenViduErrorName.STREAM_MANAGER_HAS_NO_VIDEO_ELEMENT, 'The StreamManager requires some video element to be attached to it in order to apply a Virtual Background filter')); } - logger.info('Applying client filter to stream ' + this.streamId); + logger.info('Applying Virtual Background to stream ' + this.streamId); const afterScriptLoaded = async () => { try { @@ -382,7 +382,20 @@ export class Stream { const optionsVB = options as VirtualBackgroundOptions; - const response: { video: HTMLVideoElement, canvas: HTMLCanvasElement } = await VB.backgroundBlur(optionsVB); + let response: { video: HTMLVideoElement, canvas: HTMLCanvasElement }; + switch (type) { + case 'VB:blur': { + response = await VB.backgroundBlur(optionsVB); + break; + } + case 'VB:image': { + response = await VB.backgroundImage(optionsVB); + break; + } + default: + throw new Error('Unknown Virtual Background filter: ' + type); + } + this.virtualBackgroundSinkElements = { VB, ...response }; videoClone.style.display = 'none'; diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions.ts index 597cb463..4924b617 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions.ts @@ -18,7 +18,7 @@ import { VirtualBackgroundOptions } from './VirtualBackgroundOptions'; /** - * See [[Stream.applyFilter]] + * Options to apply to a Virtual Background Image filter. See [[Stream.applyFilter]] */ export interface VirtualBackgroundImageOptions extends VirtualBackgroundOptions { /** diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts index 8056dce4..7efa5759 100644 --- a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts @@ -16,7 +16,7 @@ */ /** - * See [[Stream.applyFilter]] + * Options to apply to a Virtual Background filter. See [[Stream.applyFilter]] */ export interface VirtualBackgroundOptions { /**