SDK Usage
Media Streams

Managing Media Streams

Once you have set up event listeners and initialized the Videoedge SDK, the next step is to manage media streams, specifically audio and video. This includes functionalities to mute/unmute the microphone and turn the camera on or off. Managing media streams effectively enhances user control over their participation in a video call.

Why Manage Media Streams?

Managing media streams is essential for providing users with control over their audio and video settings during a call. This allows participants to:

  • Mute themselves when not speaking to reduce background noise.
  • Turn off their camera for privacy or bandwidth conservation.
  • Easily toggle their audio and video settings based on their preferences.

Sample Code for Managing Media Streams

Here are two functions that demonstrate how to toggle the microphone and camera states using the Videoedge SDK:

Toggle Microphone

This function mutes or unmutes the microphone based on the isMuted parameter.

async function toggleMic(videoedgeInstance, isMuted) {
  if (isMuted) {
    await videoedgeInstance.muteMic(); // Mute the microphone
    console.log("Microphone muted.");
  } else {
    await videoedgeInstance.unmuteMic(); // Unmute the microphone
    console.log("Microphone unmuted.");
  }
}

Toggle Camera

This function turns the camera on or off based on the isCameraOn parameter.

async function toggleCamera(videoedgeInstance, isCameraOn) {
  if (isCameraOn) {
    await videoedgeInstance.disableCam(); // Turn off the camera
    console.log("Camera turned off.");
  } else {
    await videoedgeInstance.enableCam(); // Turn on the camera
    console.log("Camera turned on.");
  }
}

Usage Example

You can call these functions in response to user actions, such as button clicks

// Example usage
const videoedgeInstance = /* initialized videoedgeInstance instance */;
let isMuted = false; // Track microphone state
let isCameraOn = true; // Track camera state
 
// Toggle microphone on button click
document.getElementById("muteButton").addEventListener("click", async () => {
    isMuted = !isMuted; // Toggle state
    await toggleMic(videoedgeInstance, isMuted);
});
 
// Toggle camera on button click
document.getElementById("cameraButton").addEventListener("click", async () => {
    isCameraOn = !isCameraOn; // Toggle state
    await toggleCamera(videoedgeInstance, isCameraOn);
});

Summary

By implementing these functions, you provide users with the ability to manage their audio and video streams effectively during a call. This enhances user experience by allowing participants to control their presence in the meeting, ensuring they can engage as needed while maintaining privacy and reducing distractions.