-
Notifications
You must be signed in to change notification settings - Fork 354
Streams and Effects
NOTE: This feature will be currently available only in the stream-classes (later on will be merged to next) branch of webex-js-sdk.
Previously, we were using streams generated by the getUserMedia() and getDisplayMedia() methods to manage microphone, camera, and screen sharing functionalities.
In alignment with the Web JS SDK v3 initiative, we are introducing new APIs designed to facilitate the management of local media streams, including those for the microphone, camera, and screen sharing. This document explain how these new 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 them in the samples app provided by the Web JS SDK here.
We have the following new local stream classes and methods:
We have the following methods to create the above local streams:
- createCameraStream
- createMicrophoneStream
- createDisplayStream
- createDisplayStreamWithAudio
These all can be imported via plugin-meetings package, for e.g.,
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, such as:
const cameraStream = await createCameraStream(cameraConstraints);
const microphoneStream = await createMicrophoneStream(audioConstraints);
const [localShareVideoStream, localShareAudioStream] = await createDisplayStreamWithAudio();
The following are optional camera and audio constraints that can be provided to generate the mentioned local streams:
const cameraConstraints = {
deviceId?: ConstrainDOMString;
width?: ConstrainULong;
height?: ConstrainULong;
aspectRatio?: ConstrainDouble;
frameRate?: ConstrainDouble;
facingMode?: ConstrainDOMString;
};
const audioConstraints = {
deviceId?: string;
autoGainControl?: boolean;
echoCancellation?: boolean;
noiseSuppression?: boolean;
};
Now, Let's dive into the discussion of the effects.
We have 2 new media effects created and ready for use, namely:
- VirtualBackgroundEffect - for blur, image replacement, video replacement
- NoiseReductionEffect - for background noise removal
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 |
Now, let's explore how to utilize the new local camera stream API and the virtual background effect to create and apply a basic blurred background to a video stream. Follow these steps:
-
To start, let's create a local camera stream, which we'll later apply the blur background effect to. Simply use the createCameraStream() API, as discussed earlier, like this:
const cameraConstraints = { width: 640, height: 480 }; const cameraStream = await createCameraStream(cameraConstraints);
-
Add the camera stream on your video srcObject in your code like,
meetingStreamsLocalVideo.srcObject = cameraStream.outputStream
-
Then, create the virtual background effect using createVirtualBackgroundEffect() API like,
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. This can be done as follows:
const effect = await cameraStream.addEffect("blur-background", effect); //first parameter can be any string name you want to give to your 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. This can be achieved by calling the enable method on the effect, like this:
await effect.enable();
-
After calling enable, you will see the virtual background effect applied to your camera stream.
There are some more methods available on effect and local stream which can be conveniently used by developers. Let's discuss them below,
- 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.getEffect('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
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 detailed below:
await webex.meetings.createNoiseReductionEffect(options);
Asynchronous | Yes | ||||||||||||||
Parameters |
options
|
||||||||||||||
Returns | A promise that returns noise reduction effect |
Now, let's explore how to use the new local microphone stream API along with the noise reduction effect to eliminate background noise from an audio stream. Follow this consolidated code snippet:
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();
Helper methods are same as discussed in virtual background example.
If you have any questions or need further clarification, please don't hesitate to reach out to us
Thanks for reading it out!!
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