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({
        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 Advanced: Screen Sharing on the Web.

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

  • 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.

  • 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.

  • 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.

  • DTX: boolean

    Marks whether to enable discontinuous transmission.

    The default value is false (disable). To enable the discontinuous transmission, set DTX as true.

audioSource

audioSource: object

Specifies the auido source of the stream.

Optional cameraId

cameraId: string

The camera device ID retrieved from the getDevices method.

Optional extensionid

extensionid: string

The extension ID of the Chrome screen-sharing extension.

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

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": 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.

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.

screen

screen: boolean

Marks whether this stream conatains a screen-sharing track.

streamID

streamID: number

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.

videoSource

videoSource: object

Specifies the video source of the stream.