-
Notifications
You must be signed in to change notification settings - Fork 346
Streams and Effects
Meetings SDK 3.0 introduces new APIs designed to facilitate the management of local media streams for audio, video, and screen sharing. This document explains how Streams function with two newly added effects: VirtualBackgroundEffect and NoiseReductionEffect. These effects and corresponding methods are available in the plugin-meetings package. Developers can explore and play around with these effects in the Kitchen sink app here.
The classes that have been introduced are below.
Use these methods to create Streams for various devices.
- createCameraStream
- createMicrophoneStream
- createDisplayStream
- createDisplayStreamWithAudio
Import Streams into your applications via plugin-meetings package as shown in the code snippet below.
import {
LocalCameraStream,
LocalMicrophoneStream,
LocalDisplayStream,
LocalSystemAudioStream,
createCameraStream,
createMicrophoneStream,
createDisplayStream,
createDisplayStreamWithAudio
} from '@webex/plugin-meetings';
To create any of the mentioned local streams (camera, microphone, or display), simply invoke the respective method while optionally passing the required parameters as shown below.
const cameraStream = await createCameraStream(cameraConstraints);
const microphoneStream = await createMicrophoneStream(audioConstraints);
const [localShareVideoStream, localShareAudioStream] = await createDisplayStreamWithAudio();
Here are the constraints that the create functions accept.
const cameraConstraints = {
deviceId?: ConstrainDOMString;
width?: ConstrainULong;
height?: ConstrainULong;
aspectRatio?: ConstrainDouble;
frameRate?: ConstrainDouble;
facingMode?: ConstrainDOMString;
};
const audioConstraints = {
deviceId?: string;
autoGainControl?: boolean;
echoCancellation?: boolean;
noiseSuppression?: boolean;
};
Meetings 3.0 SDK introduces two media effects:
- VirtualBackgroundEffect
- NoiseReductionEffect
The virtual background can take the form of an image, an MP4 video, or the user's background with applied blur. The blur option offers flexibility with adjustable strength and quality levels, with higher settings demanding greater computational resources.
We have following API to create the effect. Access this API via the meetings object as mentioned below:
await webex.meetings.createVirtualBackgroundEffect(options);
Asynchronous | Yes | |||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters |
options
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
Returns | A promise that returns virtual background effect |
Follow these steps to apply the virtual background effect to your camera stream.
-
Let's create a local camera stream, which we'll later apply the blur background effect to.
const cameraConstraints = { width: 640, height: 480 }; const cameraStream = await createCameraStream(cameraConstraints);
-
Add the camera stream on your video srcObject in your code
meetingStreamsLocalVideo.srcObject = cameraStream.outputStream
-
Then, create the virtual background effect using createVirtualBackgroundEffect()
const effect = await webex.meetings.createVirtualBackgroundEffect(); //we're not passing any optional parameters as default mode is BLUR
-
After creating the blur background effect, we will utilize the addEffect method of the local camera stream to apply the newly created effect to the camera stream.
const effect = await cameraStream.addEffect("blur-background", effect);
-
Now that we've added the effect to the camera stream, we need to enable the effect to observe it in action on the video.
await effect.enable();
-
You will now be able to observe the virtual background effect applied to your camera stream.
The noise reduction effect is designed to eliminate background noise from an audio stream, ensuring clear audio during calls. To create this effect, you can access the following API through the meetings object, as shown below.
await webex.meetings.createNoiseReductionEffect(options);
Asynchronous | Yes | ||||||||||||||
Parameters |
options
|
||||||||||||||
Returns | A promise that returns noise reduction effect |
Follow these steps to apply the noise reduction effect on a microphone stream.
const microphoneStream = await createMicrophoneStream();
const effect = await webex.meetings.createNoiseReductionEffect();
meetingStreamsLocalAudio.srcObject = microphoneStream.outputStream;
const effect = await microphoneStream.addEffect("noise-reduction", effect);
await effect.enable();
Both effects offer generic helper methods for various purposes.
- effect.disable() - disables the effect
- effect.dispose() - tears down the effect
- effect.setEnabled(enable) - single method to enable or disable the effect // pass true to enable the effect and false for disable
- stream.getEffectByName('effectName') - get the effect added on the stream
- stream.getAllEffects(****) - get all the effects added on the stream
- stream.disposeEffects() - tears down all the effects from the stream
Caution
- Introducing the Webex Web Calling SDK
- Core Concepts
- Quickstart guide
- Authorization
- Basic Features
- Advanced Features
- Introduction
- Quickstart Guide
- Basic Features
- Advanced Features
- Multistream
- Migrating SDK version 1 or 2 to version 3