diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index 139578e5..e6db1789 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -21,6 +21,7 @@ import { Publisher } from './Publisher'; import { Session } from './Session'; import { StreamManager } from './StreamManager'; import { Subscriber } from './Subscriber'; +import { VirtualBackgroundOptions } from '../OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions'; import { InboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/InboundStreamOptions'; import { OutboundStreamOptions } from '../OpenViduInternal/Interfaces/Private/OutboundStreamOptions'; import { WebRtcPeer, WebRtcPeerSendonly, WebRtcPeerRecvonly, WebRtcPeerSendrecv, WebRtcPeerConfiguration } from '../OpenViduInternal/WebRtcPeer/WebRtcPeer'; @@ -378,11 +379,10 @@ export class Stream { inputResolution: '160x96', outputFramerate: 30 }); - const response: { video: HTMLVideoElement, canvas: HTMLCanvasElement } = await VB.backgroundBlur({ - maskRadius: 0.1, - backgroundCoverage: 0.6, - lightWrapping: 0.3 - }); + + const optionsVB = options as VirtualBackgroundOptions; + + const response: { video: HTMLVideoElement, canvas: HTMLCanvasElement } = await VB.backgroundBlur(optionsVB); 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 new file mode 100644 index 00000000..597cb463 --- /dev/null +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundImageOptions.ts @@ -0,0 +1,28 @@ +/* + * (C) Copyright 2017-2022 OpenVidu (https://openvidu.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import { VirtualBackgroundOptions } from './VirtualBackgroundOptions'; + +/** + * See [[Stream.applyFilter]] + */ +export interface VirtualBackgroundImageOptions extends VirtualBackgroundOptions { + /** + * URL to the image asset to be used as background + */ + url: string; +} diff --git a/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts new file mode 100644 index 00000000..8056dce4 --- /dev/null +++ b/openvidu-browser/src/OpenViduInternal/Interfaces/Public/VirtualBackgroundOptions.ts @@ -0,0 +1,41 @@ +/* + * (C) Copyright 2017-2022 OpenVidu (https://openvidu.io) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * See [[Stream.applyFilter]] + */ +export interface VirtualBackgroundOptions { + /** + * Radius of the effect. Higher values mean less defined edges but a smoother transition between the person's mask and + * the background. Number between [0, 1] with 2 decimals + */ + maskRadius?: number; + + /** + * Amplitude of the space between the person's mask and the background. Higher values mean the effect will be applied + * more tightly to the person's mask, but this may cause loss of pixel information of the person. Lower values mean the + * effect will be applied further from the person's mask, granting a full view of the person but at the cost of the accuracy + * of the person's mask. Number between [0, 1] with 2 decimals + */ + backgroundCoverage?: number; + + /** + * Blends the background with the person's mask with a light effect. Higher values mean a more aggressive light blending + * Number between [0, 1] with 2 decimals + */ + lightWrapping?: number; +}