This topic describes the methods of different versions of Real-Time Streaming (RTS) Web SDK.

V2.0.0

  • Create an instance
    var aliRts = new AliRTS.createClient();
  • Check whether a browser is available
    /**
     * isSupport // Check whether a browser is available.
     * @ param {Object} supportInfo // The check result.
     * @ param {Boolean} supportInfo.isReceiveVideo // Specify whether to pull video streams.
     * @return {Promise}
     */
    aliRts.isSupport(supportInfo).then(re=> {
      // The browser is available.
    }).catch(err=> {
      // The browser is unavailable.
      console.log('not support errorCode: ${err.errorCode}');
      console.log('not support message: ${err.message}');
    })
  • Pull streams over RTS
    /**
     * rts // The method that is used to pull streams.
     * @param {String} pullStreamUrl // The source URL. Add @ subaudio=no or @ subvideo=no after the URL to specify that the audio stream or video stream is not subscribed.
     * @return {Promise}
     */
    aliRts.subscribe(pullStreamUrl).then((remoteStream) => {
      // The MediaElement parameter indicates the media type of the stream. Valid values: audio and video.
      remoteStream.play(mediaElement);
    }).catch((err) => {
      // The subscription failed.
    })
  • Stop playback
    aliRts.unsubscribe();
  • Mute a video
    remoteStream.muted = true;
  • Add a local stream
    /**
     * Add the localStream local stream.
     */
    aliRts.createStream({
      audio: true,
      video: true,
      screen: false,
    }).then((localStream) => {
      // Preview the content of the ingested stream. The mediaElement parameter indicates the media type of the stream. Valid values of the mediaElement parameter: audio and video.
      localStream.play(mediaElement);
    }).catch((err) => {
      // The local stream failed to be added.
    })
  • Ingest a stream
    /**
     * Start to ingest a stream.
     */
    aliRts.publish(pushUrl, localStream)).then(() => {
      // The stream is ingested.
    }).catch((err) => {
      // The stream failed to be ingested.
    })
  • Stop ingesting a stream
    aliRts.unpublish();
  • Issue a callback
    /*
     * If the error code 10201 is returned, the video is muted. 
     * You must manually trigger the event on the web page. You cannot use code to automatically trigger the event.
     * Call the remoteStream.muted = false method to unmute the video.
     */
    aliRts.on("onError", (err)=> {
      console.log('errorCode: ${err.errorCode}');
      console.log('message: ${err.message}');
    })
    
    const PLAY_EVENT = {
      CANPLAY: "canplay",
      WAITING: "waiting",
      PLAYING: "playing"
    }
    
    aliRts.on('onPlayEvent', (play)=>{
      if(play.event === PLAY_EVENT.CANPLAY){
        // Streams can be played.
      }else if(play.event === PLAY_EVENT.WAITING){
        // Streams are waiting for buffer. This setting applies only to Chrome.
      }else if(play.event === PLAY_EVENT.PLAYING){
        // Playback is resumed from stuttering. This setting applies only to Chrome.
      }
    })

Earlier versions (V1.1.0 to V1.2.4)

  • Create an instance
    var aliRts = new AliRTS();
  • Check whether a browser is available
    // When you call the isSupport method, you must pass parameters. Otherwise, an error is returned.
    /** 
     * isSupport // Check whether a browser is available. 
     * @ param {Object} supportInfo // The check result. 
     * @ param {Boolean} supportInfo.isReceiveVideo // Specify whether to pull video streams. 
     * @return {Promise}  
     */ 
    aliRts.isSupport(supportInfo).then(re=> { 
        // The browser is available. 
    }).catch(err=> { 
      // The browser is unavailable. 
      console.log('not support errorCode: ${err.errorCode}'); 
      console.log('not support message: ${err.message}'); 
    })
  • Pull streams over RTS
    /** 
     * rts // The method that is used to pull streams. 
     * @param {String} pullStreamUrl // The source URL. 
     * @param {HTMLMediaElement} mediaElement // The tag that is added to the video. 
     * @return {Promise}  
     */ 
    aliRts.startLiveStream(pullStreamUrl, mediaElement);
  • Stop playback
    aliRts.stopLiveStream();
  • Mute a video
    /** 
     * The method that is used to mute the video. 
     * @ param {Boolean} muted // Specify whether to mute the video. 
     */ 
    aliRts.muteLiveStream(muted);
  • Issue a callback
    /*
     * If the error code 10201 is returned, the video is muted. 
     * You must manually trigger the event on the web page. You cannot use code to automatically trigger the event.
     * Call the aliRts.muteLiveStream(false) method to unmute the video.
     */
    aliRts.on("onError", (err)=> {
      console.log('errorCode: ${err.errorCode}');
      console.log('message: ${err.message}');
    })
    
    const PLAY_EVENT = {
      CANPLAY: "canplay",
      WAITING: "waiting",
      PLAYING: "playing"
    }
    
    aliRts.on('onPlayEvent', (play)=>{
      if(play.event === PLAY_EVENT.CANPLAY){
        // Streams can be played.
      }else if(play.event === PLAY_EVENT.WAITING){
        // Streams are waiting for buffer. This setting applies only to Chrome.
      }else if(play.event === PLAY_EVENT.PLAYING){
        // Playback is resumed from stuttering. This setting applies only to Chrome.
      }
    })