A class defining the spec paramter in the createStream method.

Create a Stream

You have two options to create an audio/video stream:

Set the audio, video, and screen properties

var stream = AgoraRTC.createStream({
  streamID: uid,
  audio:true,
  video:true,
  screen:false
});

Set the audioSource and videoSource properties

Compared with the first option, the audioSource and videoSource properties can specify the audio and video tracks for the stream. Use this option if you need to process the audio and video before creating the stream.

Use the mediaStream method to get the audio and video tracks from MediaStreamTrack, and then set audioSource and videoSource:

navigator.mediaDevices.getUserMedia(
    {video: true, audio: true}
).then(function(mediaStream){
    var videoSource = mediaStream.getVideoTracks()[0];
    var audioSource = mediaStream.getAudioTracks()[0];
    // After processing videoSource and audioSource
    var localStream = AgoraRTC.createStream({
        video: true,
        audio: true,
        videoSource: videoSource,
        audioSource: audioSource
    });
    localStream.init(function(){
        client.publish(localStream, function(e){
            //...
        });
    });
});

Note:

  • MediaStreamTrack refers to the MediaStreamTrack object supported by the browser. See MediaStreamTrack API for details.

  • Currently this option only supports the Chrome brower.

Enable Screen-sharing on the Chrome Web Browser

var stream = AgoraRTC.createStream({
  streamID: uid,
  audio:false,
  video:false,
  screen:true,
  extensionId:"minllpmhdgpndnkomcoccfekfegnlikg"});

Enable Screen-sharing on the Firefox Web Browser

localStream = AgoraRTC.createStream({
     streamID: uid,
     audio: false,
     video: false,
     screen: true,
     mediaSource: "screen",
   });

For a tutorial on screen-sharing on a website, see Share the Screen.

Note:

  • Do not set video and screen as true at the same time.

  • To enable screen-sharing on the Firefox browser, ensure that the screen property is set to true, and the mediaSource property has been set to specify a certain sharing mode.

Hierarchy

  • StreamSpec

Index

Properties

audio

audio: boolean

Marks whether this stream contains an audio track.

Optional audioProcessing

audioProcessing: object

Marks whether to enable audio processing.

Type declaration

  • Optional AEC?: boolean

    Marks whether to enable acoustic echo cancellation.

    The default value is true (enable). If you wish not to enable the acoustic echo cancellation, set AEC as false.

    Note:

    Safari does not support this setting.

  • Optional AGC?: boolean

    Marks whether to enable audio gain control.

    The default value is true (enable). If you wish not to enable the audio gain control, set AGC as false.

    Note:

    Safari does not support this setting.

  • Optional ANS?: boolean

    Marks whether to enable automatic noise suppression.

    The default value is true (enable). If you wish not to enable automatic noise suppression, set ANS as false.

    Note:

    • Safari does not support this setting.
    • Noise suppression is always enabled on Firefox. Setting ANS as false does not take effect on Firefox.

Optional audioSource

audioSource: MediaStreamTrack

Specifies the audio source of the stream.

Optional cameraId

cameraId: string

The camera device ID retrieved from the getDevices method.

The retrieved ID is ASCII characters, and the string length is greater than or equals to 0 and less than 256 bytes.

When the string length is 0, this property is ignored.

Optional extensionId

extensionId: string

The extension ID of the Chrome screen-sharing extension.

ASCII characters only, and the string length must be greater than 0 and less than 256 bytes.

Set this property if you use the Chrome screen-sharing extension. See Chrome Extension for Screen Sharing for details.

Note:

Chrome 72 and later versions support screen sharing without the extension. You can leave extensionId as empty.

If you set the extensionId, then you need to use the screen-sharing extension.

Optional mediaSource

mediaSource: "screen" | "application" | "window"

The screen-sharing mode on the Firefox browser.

If you are using the Firefox browser, setting this property specifies the screen-sharing mode:

  • "screen": (default) share the current screen
  • "application": share all windows of an App
  • "window": share a specified window of an App

Note:

Firefox on Windows does not support the application mode.

See Screen Sharing on Firefox for details.

Optional microphoneId

microphoneId: string

The microphone device ID retrieved from the getDevices method.

The retrieved ID is ASCII characters, and the string length is greater than or equals to 0 and less than 256 bytes.

When the string length is 0, this property is ignored.

Optional mirror

mirror: boolean

Marks whether the video image of the publisher is mirrored on the publisher’s webpage.

The default value is true (except in the screen-share mode). Agora recommends enabling this function when using the front camera, and disabling it when using the rear camera.

Optional screen

screen: boolean

Marks whether this stream contains a screen-sharing track.

Optional streamID

streamID: number | string

The stream ID.

Please set the stream ID as the user ID, which can be retrieved from the callback of Client.join.

video

video: boolean

Marks whether this stream contains a video track.

Optional videoSource

videoSource: MediaStreamTrack

Specifies the video source of the stream.

Note:

If you use a video source created by the Canvas API, re-draw on the canvas every one second when the drawing is still to keep the video publishing.