The Stream object created by the createStream method.

A stream represents a published local or remote media stream object in a call session.

Hierarchy

  • Stream

Index

Methods

close

  • close(): void
  • CLose the Audio/Video Stream

    This method closes the video/audio stream.

    After calling this method, the camera and microphone authorizations will be reset.

    Returns void

disableAudio

  • disableAudio(): void
  • Disable the Audio

    This method disables the audio track in the stream.

    It works only when the audio flag is true in the stream.

    Returns void

disableVideo

  • disableVideo(): void
  • Disable the Video

    This method disables the video track in the stream.

    It works only when the video flag is true in the stream.

    Returns void

enableAudio

  • enableAudio(): void
  • Enable the Audio

    This method enables the audio track in the stream.

    It works only when the audio flag is true in the stream.

    By default the audio track is enabled. If you called disableAudio, call this method to enable audio.

    Returns void

enableVideo

  • enableVideo(): void
  • Enable the Video

    This method enables the video track in the stream.

    It works only when the video flag is true in the stream.

    By default the video track is enabled. If you called disableVideo, call this method to enable video.

    Returns void

getAudioLevel

  • getAudioLevel(): number
  • Retrieve the Current Audio Level

    This method retrieves the current audio level.

    Call setTimeout or setInterval to retrieve the local or remote audio change.

    example

    Sample Code

    setInterval(function() {
      var audioLevel = stream.getAudioLevel();
      // Use audioLevel to render the UI
    }, 100)
    

    This method does not apply to streams that contain no audio data and may result in warnings.

    Note:

    On Chrome 90+, the first call of this method must be triggered by the users’ clicking action, see https://goo.gl/7K7WLu.

    Returns number

getId

  • getId(): number
  • Retrieve the Stream ID

    This method retrieves the stream ID.

    example

    stream.getId()

    Returns number

getStats

  • getStats(callback: function): void

hasAudio

  • hasAudio(): boolean
  • Retrieve the Audio Flag

    This method retrieves the audio flag.

    Returns boolean

    • true: The stream contains auido data.
    • false: The stream does not contain audio data.

hasVideo

  • hasVideo(): boolean
  • Retrieve the Video Flag

    This method retrieves the video flag.

    Returns boolean

    • true: The stream contains video data.
    • false: The stream does not contain video data.

init

  • init(onSuccess: function, onFailure: function): void
  • Initialize the Stream Object

    This method initializes the stream object.

    If this method fails, the returned callback will show the error message, for example: {type: "error", msg: "MEDIA_OPTION_INVALID"}.

    The error messages include:

    • MEDIA_OPTION_INVALID: The camera is occupied or the resolution is not supported (on browsers in early versions).
    • DEVICES_NOT_FOUND: No device is found.
    • NOT_SUPPORTED: The browser does not support using camera and microphone.
    • PERMISSION_DENIED: The device is disabled by the browser or the user has denied permission of using the device.
    • CONSTRAINT_NOT_SATISFIED: The settings are illegal (on browsers in early versions).
    • UNDEFINED: Undefined error.
    example

    Sample Code

    init(function() {
        console.log("local stream initialized");
        // publish the stream
        //……
    }, function(err) {
        console.error("local stream init failed ", err);
        //error handling
    });
    

    Parameters

    • onSuccess: function

      The callback when the method succeeds.

        • (): void
        • Returns void

    • onFailure: function

      The callback when the method fails.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

on

  • on(event: "accessAllowed", callback: function): void
  • on(event: "accessDenied", callback: function): void
  • on(event: "stopScreenSharing", callback: function): void
  • This callback notifies the application that the user has given access to the camera and microphone.

    Parameters

    • event: "accessAllowed"
    • callback: function
        • (evt: any): void
        • Parameters

          • evt: any

          Returns void

    Returns void

  • This callback notifies the application that the user has denied access to the camera and microphone.

    Parameters

    • event: "accessDenied"
    • callback: function
        • (evt: any): void
        • Parameters

          • evt: any

          Returns void

    Returns void

  • This callback notifies the application that screen-sharing has stopped.

    Parameters

    • event: "stopScreenSharing"
    • callback: function
        • (evt: any): void
        • Parameters

          • evt: any

          Returns void

    Returns void

play

  • play(HTMLElementID: string): void
  • Play the Audio/Video Stream

    This method plays the video or audio stream.

    example

    Sample Code

    stream.play("agora_remote"); // stream will be played in the element with the ID agora_remote

    Parameters

    • HTMLElementID: string

      Represents the HTML element ID.

    Returns void

setAudioOutput

  • setAudioOutput(deviceId: string): void
  • Set the Audio Output

    This method sets the auido output device. You can use it to switch between the microphone and the speakerphone.

    Note:

    Only Chrome 49+ supports this function.

    Parameters

    • deviceId: string

      The device ID can be retrieved from getDevices.

    Returns void

setAudioProfile

  • setAudioProfile(profile: "speech_standard" | "music_standard" | "standard_stereo" | "high_quality" | "high_quality_stereo"): void
  • Set the Audio Profile

    This method sets the audio profile.

    It is optional and works only when called before Stream.init. The default value is "music_standard".

    Note:

    Due to the limitations of browsers, some browsers may not be fully compatible with the audio profile you set.

    • Firefox does not support setting the audio encoding rate.
    • Safari does not support stereo audio.
    • The latest version of Google Chrome does not support playing stereo audio, but supports sending a stereo audio stream.

    Parameters

    • profile: "speech_standard" | "music_standard" | "standard_stereo" | "high_quality" | "high_quality_stereo"

      The audio profile has the following options:

      • "speech_standard": Sample rate 32 kHz, mono, encoding rate 24 Kbps.
      • "music_standard": Sample rate 48 kHz, mono, encoding rate 40 Kbps.
      • "standard_stereo": Sample rate 48 kHz, stereo, encoding rate 64 Kbps.
      • "high_quality": Sample rate 48 kHz, stereo, encoding rate 128 Kbps.
      • "high_quality_stereo": Sample rate 48 kHz, stereo, encoding rate 192 Kbps.

    Returns void

setAudioVolume

  • setAudioVolume(volume: number): void
  • Set the Volume of the Remote Stream

    This method set the volume of the remote stream.

    Parameters

    • volume: number

      Ranges from 0 to 100.

    Returns void

setScreenProfile

  • setScreenProfile(profile: string): void
  • Set the Screen Profile

    This method sets the profile of the screen in screen-sharing.

    Parameters

    • profile: string

      The screen profile. See the following table for details.

      Screen Profile Definition

      Screen Profile Resolution Frame Rate
      480p_1 640 × 480 5
      480p_2 640 × 480 30
      720p_1 1280 × 720 5
      720p_2 1280 × 720 30
      1080p_1 1920 × 1080 5
      1080p_2 1920 × 1080 30

      Note:

      Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings will be calculated based on the actual resolution.

    Returns void

setVideoProfile

  • setVideoProfile(profile: string): void
  • Set the Video Profile

    This method sets the video profile.

    It is optional and works only when called before Stream.init. The default value is "480p_1".

    example

    setVideoProfile("480p");

    Parameters

    • profile: string

      The video profile. See the following table for its definition and supported profiles in different scenarios.

      Video Profile Definition

      Video profile Resolution Frame rate (fps) Bitrate (Kbps) Chrome Firefox/Opera Safari
      120p 160 × 120 15 65
      120p_1 160 × 120 15 65
      120p_3 120 × 120 15 50
      180p 320 × 180 15 140
      180p_1 320 × 180 15 140
      180p_3 180 × 180 15 100
      180p_4 240 × 180 15 120
      240p 320 × 240 15 200
      240p_1 320 × 240 15 200
      240p_3 240 × 240 15 140
      240p_4 424 × 240 15 220
      360p 640 × 360 15 400
      360p_1 640 × 360 15 400
      360p_3 360 × 360 15 260
      360p_4 640 × 360 30 600
      360p_6 360 × 360 30 400
      360p_7 480 × 360 15 320
      360p_8 480 × 360 30 490
      360p_9 640 × 360 15 800
      360p_10 640 × 360 24 800
      360p_11 640 × 360 24 1000
      480p 640 × 480 15 500
      480p_1 640 × 480 15 500
      480p_2 648 × 480 30 1000
      480p_3 480 × 480 15 400
      480p_4 640 × 480 30 750
      480p_6 480 × 480 30 600
      480p_8 848 × 480 15 610
      480p_9 848 × 480 30 930
      480p_10 640 × 480 10 400
      720p 1280 × 720 15 1130
      720p_1 1280 × 720 15 1130
      720p_2 1280 × 720 15 2080
      720p_3 1280 × 720 30 1710
      720p_5 960 × 720 15 910
      720p_6 960 × 720 30 1380
      1080p 1920 × 1080 15 2080
      1080p_1 1920 × 1080 15 2080
      1080p_2 1920 × 1080 30 3000
      1080p_3 1920 × 1080 30 3150
      1080p_5 1920 × 1080 60 4780
      1440p 2560 × 1440 30 4850
      1440p_1 2560 × 1440 30 4850
      1440p_2 2560 × 1440 60 7350
      4K 3840 × 2160 30 8910
      4K_1 3840 × 2160 30 8910
      4K_3 3840 × 2160 60 13500

      Note:

      • Whether 1080 resolution or above can be supported depends on the device. If the device cannot support 1080p, the frame rate will be lower than the one listed in the table. Agora optimizes the video on low-end devices. For special requirements, please contact support@agora.io.

      • The video frame rate is fixed as 30 fps on the Safari brower, which does not support modifying the video frame rate.

      • Due to limitations of some devices and browsers, the resolution you set may fail to take effect and get adjusted by the browser. In this case, billings will be calculated based on the actual resolution.

    Returns void

stop

  • stop(): void
  • Stop the Audio/Video Stream

    Call this method to stop playing the stream set by Stream.play.

    Returns void