SDK Usage
Join Room

Initializing the Videoedge SDK

After completing the installation steps for the Videoedge SDK, the next step is to initialize the SDK in your application. This involves joining a room using a session token, room ID, and optionally specifying a peer name.

Step-by-Step Guide to Initialize the SDK

  1. Create an Async Function: Define an asynchronous function to handle the initialization and joining of the room.

  2. Obtain the Session Token: Fetch the session token from your backend server. This token is essential for authenticating your connection to the Videoedge platform.

  3. Specify Room Details: Define the roomId and peerName (optional) that you want to join.

  4. Join the Room: Use the videoedge.JsSdk.joinRoom method to join the specified room with the required parameters.

  5. Handle Connection Success or Errors: Implement error handling to manage any potential issues during the connection process.

Sample Code

Here’s a sample code snippet demonstrating how to initialize the Videoedge SDK and join a room:

import videoedge from "videoedge-js";
 
async function initializeRoom() {
  const sessionToken = "your-session-token"; // Obtain this from your backend server
  const roomId = "your-room-id"; // Specify the room ID you want to join
  const peerName = "your-peer-name"; // Optionally specify a peer name
 
  try {
    const videoedgeInstance = await videoedge.JsSdk.joinRoom({
      sessionToken,
      roomId,
      peerName,
      produce: true, // Set to true to send audio/video streams
      consume: true, // Set to true to receive audio/video streams
      // Additional parameters can be added here as needed
    });
 
    // Handle successful connection
    console.log("Successfully joined the room:", videoedgeInstance);
  } catch (error) {
    console.error("Error joining room:", error);
  }
}

Parameters

  • sessionToken: The token obtained from your backend server, required for authentication.

  • roomId: The ID of the room you want to join.

  • peerName:(Optional) A name for the peer that represents the user in the room.

  • produce:Set to true if you want to send your audio and video streams to the room.

  • consume: Set to true if you want to receive audio and video streams from other participants in the room.

  • forcePCMU: This parameter forces the use of the PCMU audio codec.The default audio codec used in OPUS. PCMU is particulary useful in environments with varying network conditions, as it ensures stable audio quality and low latency. The default value of this setting is false.

  • forceH264: This parameter forces the use of H264 video codec for efficient compression and high-quality video streaming. The default video codec is VP8. This codec works well across different devices and network conditions. The default value of this setting is false.

  • h264Profile: This parameter specifies the H264 profile for video encoding, which decides the video compression quality. Common profiles were low and high. The default value of this setting is high.

  • forceFPS: This parameter sets the video frame rate, which directly affects the smoothness of the video. A higher frame rate requires more processing power but provides smoother motion, while low frame rate uses less resources results in a less smoother video. The default value of this setting is 25.

  • enableWebcamLayers: This parameter enables simulcast layers for the webcam, which allows different resolutions to be sent simultaneously. This feature ensures that participants with varying network conditions can receive the most appropriate video quality. The default value of this setting is true.

  • numSimulcastStreams: This parameter specifies the number of simulcast streams to produce, The default value of this setting is 3.

  • videoBitRates: This parameter control the bit rates for different simulcast layers, affecting the video quality and bandwith usage. You can adjust the bit rates to change the video quality for different layers. By default this setting will take 500, 200, 75 for high, medium and low bitrates respectively.

  • autoGainControl: This parameter enables automatic gain control for the microphone.This helps maintain consistent audio level by adjusting the microphone sensitivity in response to changes in speaking volume. This will be veryuseful when you move closer or further from the microphone The default value of this setting is true.

  • echoCancellation: This parameter when enabled prevents the feedback loop by detecting and eliminating the echo from the audio signal. It ensures that when someone speaks, their voice is not picked up by their own microphone and sent back to them or others in the call. By default this setting is true.

  • noiseSuppression: This parameter when enabled reduces background noise, ensuring that your voice remains clear even in noisy environments. By default this setting is true.

  • sampleRate : This parameter specifies the audio sample rate, which determines the quality of the audio stream. Higher sample rates(1600Hz) result in better audio but requires more processing power, while lower sample rates are efficient but result in lower audio quality.For PCMU, this setting should be set to 8000. Otherwise, default setting for this parameter is 44000.

  • channelCount: This parameter refers to the number of audio channels that are captured and transmitted in an audio stream. It determines whether the audio is mono (a single audio channel with the same signal sent to all speakers) or stereo (two audio channels, with one for the left speaker and one for the right). The OPUS codec supports both mono and stereo signals. Depending on the device's capabilities and CPU performance, the channel count can be increased to 2. The default setting for this parameter is 1 (mono).

Summary

By following these steps and using the provided code, you can successfully initialize the Videoedge SDK and join a room. Ensure that you handle any errors appropriately to provide a smooth user experience. Feel free to customize the parameters and logic to fit your application's specific requirements.