Javascript API Reference
    Preparing search index...

    Class VideoSDK

    Index

    Constructors

    Properties

    Constants: {
        BitrateMode: typeof BitrateMode;
        errors: typeof Errors;
        hlsEvents: typeof hlsEvents;
        leaveReason: typeof leaveReason;
        livestreamEvents: typeof livestreamEvents;
        modes: typeof modes;
        permission: typeof Permission;
        recordingEvents: typeof recordingEvents;
        reliabilityMode: typeof reliabilityMode;
        transcriptionEvents: typeof transcriptionEvents;
    }

    Methods

      • This method can be used to check whether the application already has permission to access media input devices.
      • It returns a Promise that resolves to a Map<string, boolean> indicating the permission status.

      Parameters

      • Optionalpermissions: string

        Specifies the type of media permission to request.

        Allowed value: Permission

      Returns Promise<Map<string, boolean>>

      A Promise that resolves to a Map<string, boolean> where:

      • true indicates permission is granted
      • false indicates permission is denied
      AUDIO_AND_VIDEO
      
      try {
      const checkAudioVideoPermission = await VideoSDK.checkPermissions(
      VideoSDK.Constants.permission.AUDIO_AND_VIDEO
      );

      console.log(
      "check Audio and Video Permissions",
      checkAudioVideoPermission.get(VideoSDK.Constants.permission.AUDIO),
      checkAudioVideoPermission.get(VideoSDK.Constants.permission.VIDEO)
      );
      } catch (ex) {
      console.log("Error in checkPermissions", ex);
      }

      Note

      This method will throw an error if the browser does not support permission checking functionality.

      • This method can be used to configure the VideoSDK with an authentication token.
      • Before initializing a meeting, you must provide a valid token using this method.

      Parameters

      • token: string

        Authentication token used to authorize SDK operations.

        You can generate a token in the following ways:

        1. Temporary Token – Generate it from the Dashboard API Keys.
        2. Server-generated Token – Generate a JWT on your backend and fetch it securely.

      Returns void

      const token = "<YOUR_TOKEN_FROM_DASHBOARD>";
      VideoSDK.config(token);
      • This method can be used to create video track using different encoding parameters, camera facing mode, bitrateMode, maxLayer and optimization mode.

      Parameters

      • Optionaloptions: {
            bitrateMode?: "high_quality" | "balanced" | "bandwidth_optimized";
            cameraId?: string;
            encoderConfig?:
                | "h90p_w160p"
                | "h180p_w320p"
                | "h216p_w384p"
                | "h360p_w640p"
                | "h540p_w960p"
                | "h720p_w1280p"
                | "h1080p_w1920p"
                | "h1440p_w2560p"
                | "h2160p_w3840p"
                | "h120p_w160p"
                | "h180p_w240p"
                | "h240p_w320p"
                | "h360p_w480p"
                | "h480p_w640p"
                | "h540p_w720p"
                | "h720p_w960p"
                | "h1080p_w1440p"
                | "h1440p_w1920p";
            facingMode?: "user"
            | "environment";
            maxLayer?: 2 | 3;
            multiStream?: boolean;
            optimizationMode?: "text" | "motion" | "detail";
        }
        • OptionalbitrateMode?: "high_quality" | "balanced" | "bandwidth_optimized"

          Controls the video quality and bandwidth consumption. You can choose between high_quality for the best picture, bandwidth_optimized to save data, or balanced for a mix of both. Defaults to balanced.

          Allowed Value: BitrateMode

          BitrateMode.BALANCED
          
        • OptionalcameraId?: string

          It will be the id of the camera from which the video should be captured.

        • OptionalencoderConfig?:
              | "h90p_w160p"
              | "h180p_w320p"
              | "h216p_w384p"
              | "h360p_w640p"
              | "h540p_w960p"
              | "h720p_w1280p"
              | "h1080p_w1920p"
              | "h1440p_w2560p"
              | "h2160p_w3840p"
              | "h120p_w160p"
              | "h180p_w240p"
              | "h240p_w320p"
              | "h360p_w480p"
              | "h480p_w640p"
              | "h540p_w720p"
              | "h720p_w960p"
              | "h1080p_w1440p"
              | "h1440p_w1920p"

          You can choose from the below mentioned list of values for the encoder config.

          Supported values include:

          Encoder Config Resolution Frame Rate Optimized (kbps) Balanced (kbps) High Quality (kbps)
          h90p_w160p 160x90 15 fps 60 100 150
          h180p_w320p 320x180 15 fps 100 150 250
          h216p_w384p 384x216 15 fps 120 200 350
          h360p_w640p 640x360 20 fps 200 400 600
          h540p_w960p 960x540 25 fps 350 550 800
          h720p_w1280p 1280x720 30 fps 1000 1500 2000
          h1080p_w1920p 1920x1080 30 fps 1600 2200 2700
          h1440p_w2560p 2560x1440 30 fps 5000 5500 6000
          h2160p_w3840p 3840x2160 30 fps 8000 8500 9000
          h120p_w160p 160x120 15 fps 60 100 150
          h180p_w240p 240x180 15 fps 100 150 250
          h240p_w320p 320x240 15 fps 120 200 350
          h360p_w480p 480x360 20 fps 200 400 600
          h480p_w640p 640×480 25 fps 300 500 700
          h540p_w720p 720×540 30 fps 350 550 800
          h720p_w960p 960×720 30 fps 900 1300 1600
          h1080p_w1440p 1440×1080 30 fps 1600 2200 2700
          h1440p_w1920p 1920×1440 30 fps 3500 4000 4500

          Note

          Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.

          "h720p_w1280p"
          
        • OptionalfacingMode?: "user" | "environment"

          It will specify whether to use front or back camera for the video track.

        • OptionalmaxLayer?: 2 | 3

          Specifies the maximum number of simulcast layers to publish. This parameter only has an effect if multiStream is set to true.

        • OptionalmultiStream?: boolean

          It will specify if the stream should send multiple resolution layers or single resolution layer.

          Info

          For meetings with fewer than or equal to four participants, setting multiStream:false is regarded as best practice.

          true
          
        • OptionaloptimizationMode?: "text" | "motion" | "detail"

          It will specify the optimization mode for the video track being generated.

      Returns Promise<MediaStream>

      const customTrack = await VideoSDK.createCameraVideoTrack({
      optimizationMode: "motion",
      encoderConfig: "h540p_w960p",
      facingMode: "environment",
      bitrateMode: VideoSDK.Constants.BitrateMode.HIGH_QUALITY,
      maxLayer: 2,
      multiStream: true,
      });
      • This method can be used to create audio track using different encoding parameters and noise cancellation configuration.

      Parameters

      • Optionaloptions: {
            encoderConfig?:
                | "high_quality"
                | "speech_low_quality"
                | "speech_standard"
                | "music_standard"
                | "standard_stereo"
                | "high_quality_stereo";
            microphoneId?: string;
            noiseConfig?: {
                autoGainControl: boolean;
                echoCancellation: boolean;
                noiseSuppression: boolean;
            };
        }
        • OptionalencoderConfig?:
              | "high_quality"
              | "speech_low_quality"
              | "speech_standard"
              | "music_standard"
              | "standard_stereo"
              | "high_quality_stereo"

          Default: "speech_standard"

          • It will be the encoder configuration you want to use for Audio Track.
          • You can choose from the below mentioned list of values for the encoder config.
          Encoder Config Bitrate Auto Gain Echo Cancellation Noise Suppression
          speech_low_quality 16 kbps TRUE TRUE TRUE
          speech_standard 24 kbps TRUE TRUE TRUE
          music_standard 32 kbps FALSE FALSE FALSE
          standard_stereo 64 kbps FALSE FALSE FALSE
          high_quality 128 kbps FALSE FALSE FALSE
          high_quality_stereo 192 kbps FALSE FALSE FALSE
        • OptionalmicrophoneId?: string

          It will be the id of the mic from which the audio should be captured.

        • OptionalnoiseConfig?: {
              autoGainControl: boolean;
              echoCancellation: boolean;
              noiseSuppression: boolean;
          }

          Configuration for audio noise processing.

          • autoGainControl: boolean

            If true auto gain will turned on else it would be turned off.

          • echoCancellation: boolean

            If true echo cancellation will turned on else it would be turned off.

          • noiseSuppression: boolean

            If true noise suppression will turned on else it would be turned off.

      Returns Promise<MediaStream>

      const customTrack = await VideoSDK.createMicrophoneAudioTrack({
      encoderConfig: "high_quality",
      noiseConfig: {
      noiseSuppression: true,
      echoCancellation: true,
      autoGainControl: true,
      },
      });
      • This method can be used to create screen share track using different encoding parameters and optimization mode.

      Parameters

      • Optionaloptions: {
            encoderConfig?:
                | "h360p_30fps"
                | "h480p_15fps"
                | "h480p_30fps"
                | "h720p_5fps"
                | "h720p_15fps"
                | "h720p_30fps"
                | "h1080p_15fps"
                | "h1080p_30fps";
            multiStream?: boolean;
            optimizationMode?: "text"
            | "motion"
            | "detail";
            withAudio?: "enable" | "disable";
        }
        • OptionalencoderConfig?:
              | "h360p_30fps"
              | "h480p_15fps"
              | "h480p_30fps"
              | "h720p_5fps"
              | "h720p_15fps"
              | "h720p_30fps"
              | "h1080p_15fps"
              | "h1080p_30fps"

          You can choose from the below mentioned list of values for the encoder config.

          Encoder Config Resolution Frame Rate Bitrate
          h360p_30fps 640x360 30 fps 400 kbps
          h480p_15fps 854x480 15 fps 300 kbps
          h480p_30fps 854x480 30 fps 500 kbps
          h720p_5fps 1280x720 5 fps 400 kbps
          h720p_15fps 1280x720 15 fps 1000 kbps
          h720p_30fps 1280x720 30 fps 1500 kbps
          h1080p_15fps 1920x1080 15 fps 1500 kbps
          h1080p_30fps 1920x1080 30 fps 2000 kbps

          Note

          Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.

          "h720p_15fps"
          
        • OptionalmultiStream?: boolean

          It will specify if the stream should send multiple resolution layers or single resolution layer.

          false
          
        • OptionaloptimizationMode?: "text" | "motion" | "detail"

          Optimization strategy for screen sharing.

        • OptionalwithAudio?: "enable" | "disable"

          Enables or disables audio during screen sharing.

          "enable"
          

      Returns Promise<MediaStream>

      import VideoSDK from "@videosdk.live/js-sdk";

      let customTrack = await VideoSDK.createScreenShareVideoTrack({
      optimizationMode: "motion",
      encoderConfig: "h720p_15fps",
      withAudio:'enable'
      multiStream: true
      });
      • This method can be used to retrieve a list of all currently available media input and output devices.
      • The returned Promise resolves with an array of DeviceInfo objects.

      Returns Promise<DeviceInfo[]>

      • This method can be used to retrieve network statistics such as upload and download speed.
      • The method returns a Promise that resolves with network speed statistics or rejects if the operation fails or exceeds the specified timeout.
      • The result object will include the downloadSpeed and uploadSpeed, expressed in megabytes per second (MB/s).

      Parameters

      • Optionaloptions: { timeoutDuration?: number }
        • OptionaltimeoutDuration?: number

          It helps prevent the method from getting stuck indefinitely when fetching network statistics. It lets you set a maximum time for the operation, and if it takes longer than that, the method stops gracefully.

          You can specify timeoutDuration in milliseconds. If it is not provided or is not an integer, the default timeout is set to 60,000 milliseconds (1 minute).

      Returns Promise<{ downloadSpeed: number; uploadSpeed: number }>

      try {
      const options = { timeoutDuration: 45000 }; // 45 seconds
      const networkStats = await VideoSDK.getNetworkStats(options);
      // will return value in Mb/s
      console.log("Download Speed: ", networkStats["downloadSpeed"]);
      console.log("Upload Speed: ", networkStats["uploadSpeed"]);
      } catch (ex) {
      console.log("Error in networkStats:", ex);
      }
      • This method can be used to initialize a meeting and return a Meeting instance.

      Parameters

      • options: {
            customCameraVideoTrack?: MediaStream;
            customMicrophoneAudioTrack?: MediaStream;
            debugMode?: boolean;
            defaultCamera?: "user" | "enviornment";
            maxResolution?: "hd" | "sd";
            meetingId: string;
            metaData?: object;
            micEnabled?: boolean;
            mode?: "SEND_AND_RECV" | "SIGNALLING_ONLY" | "RECV_ONLY";
            multiStream?: boolean;
            name?: string;
            participantId?: string;
            preferredProtocol?: "UDP_ONLY" | "UDP_OVER_TCP" | "TCP_ONLY";
            signalingBaseUrl?: string;
            webcamEnabled?: boolean;
        }

        Configuration options for initializing the meeting.

        • OptionalcustomCameraVideoTrack?: MediaStream

          Custom camera video track to use as the camera input.

          If this is not provided, the SDK will automatically create and use a default camera video track. You can create a custom track using createCameraVideoTrack.

        • OptionalcustomMicrophoneAudioTrack?: MediaStream

          Custom microphone audio track to use as the microphone input.

          If this is not provided, the SDK will automatically create and use a default microphone audio track.You can create a custom track using createMicrophoneAudioTrack.

        • OptionaldebugMode?: boolean

          Enables detailed SDK logs in the dashboard.

          true
          
        • OptionaldefaultCamera?: "user" | "enviornment"

          Specifies which camera to use by default.

          • user → front camera
          • environment → rear camera
        • OptionalmaxResolution?: "hd" | "sd"

          Maximum resolution for video publishing.

          "hd"
          
        • meetingId: string

          Unique ID of the meeting to join. Please refer this documentation to create a room.

        • OptionalmetaData?: object

          Custom metadata associated with the participant.

        • OptionalmicEnabled?: boolean

          Enables microphone on join.

          false
          
        • Optionalmode?: "SEND_AND_RECV" | "SIGNALLING_ONLY" | "RECV_ONLY"

          Defines how media streams should behave.There are 3 types of modes

        • OptionalmultiStream?: boolean

          Enables or disables multi-resolution streaming.

          true
          
        • Optionalname?: string

          Display name of the participant.

        • OptionalparticipantId?: string

          Unique participant identifier.

        • OptionalpreferredProtocol?: "UDP_ONLY" | "UDP_OVER_TCP" | "TCP_ONLY"

          Preferred network protocol for media transmission.

          Allowed Value:

          • UDP_OVER_TCP (default): Initially the server attempts to establish a connection using UDP, if that fails it automatically switches to TCP protocol.
          • UDP_ONLY: Force UDP protocol
          • TCP_ONLY: Force TCP protocol
        • OptionalsignalingBaseUrl?: string

          If you want to use a proxy server with the VideoSDK, you can specify your baseURL here.

          Note

          If you intend to use a proxy server with the VideoSDK, priorly inform us at support@videosdk.live

        • OptionalwebcamEnabled?: boolean

          Enables webcam on join.

          false
          

      Returns Meeting

      const meeting = VideoSDK.initMeeting({
      meetingId: "abc-1234-xyz",
      name: "John Doe",
      micEnabled: true,
      webcamEnabled: true,
      maxResolution: "hd",
      multiStream: true,
      mode: "SEND_AND_RECV",
      });
    • Removes an event listener that was previously registered.

      Parameters

      • eventType: "device-changed"

        Event name to which you want to unsubscribe.

      • listener: (data: any) => void

        Callback function which was passed while subscribing to the event

        To view the complete list of available events and their details, refer to VideosdkEvent

      Returns void

    • Registers an event listener.

      Parameters

      • eventType: "device-changed"

        Event name to which you want to subscribe.

      • listener: (data: any) => void

        Callback function which will be triggered when the event happens

        To view the complete list of available events and their details, refer to VideosdkEvent

      Returns void

      • This method can be used to prompt the user for permission to access media input devices.
      • It requests permission for the specified media types and returns the permission status for each requested media kind.

      Parameters

      • Optionalpermissions: string

        Specifies the type of media permission to request.

        Allowed value: Permission

      Returns Promise<Map<string, boolean>>

      try {
      const requestPermission = await VideoSDK.requestPermission(
      VideoSDK.Constants.permission.AUDIO_AND_VIDEO,
      );
      console.log(
      "request Audio and Video Permissions",
      requestPermission.get(VideoSDK.Constants.permission.AUDIO),
      requestPermission.get(VideoSDK.Constants.permission.VIDEO)
      );
      } catch(ex)
      {
      console.log("Error in requestPermission ", ex);
      }

      Note

      requestPermission() will throw an error when matching media is not available.

      • This method can be used to set the End-to-End Encryption (E2EE) key provider.
      • The key provider must be an instance of ExternalE2EEKeyProvider that contains a shared encryption key.
      • Before passing the provider to this method, ensure that the shared key is set using keyProvider.setSharedKey(...).
      • If the key provider is set before initializing a meeting, E2EE will be enabled automatically.

      Parameters

      Returns void

      import { ExternalE2EEKeyProvider } from "@videosdk.live/js-sdk";

      const keyProvider = new ExternalE2EEKeyProvider();
      keyProvider.setSharedKey("<SECRET_KEY>");

      // Set the key provider before initializing the meeting.
      // If the key is set before initialization, E2EE is enabled automatically.
      VideoSDK.setKeyProvider(keyProvider);

      const meeting = VideoSDK.initMeeting({
      // ...
      });