This topic describes the methods of Web RTS SDK.

Overview

Method Description
new AliRTS() Creates an instance on which Web RTS SDK is used.
isSupport Checks whether a browser is available.
startLiveStream Starts to pull streams over Real-Time Streaming (RTS).
stopLiveStream Stops playing streams over RTS.
muteLiveStream Mutes streams.
on Invokes a callback.

Sample code

  • new AliRTS(): creates an instance on which Web RTS SDK is used.
    var aliRts = new AliRTS();
  • isSupport: checks whether a browser is available.
    // When you call the isSupport method, you must specify parameters. Otherwise, an error is returned.
    /** 
     * isSupport Check whether a browser is available. 
     * @param {Object} supportInfo The check information. 
     * @param {Boolean} supportInfo.isReceiveVideo Specifies 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}`); 
    })
  • startLiveStream: starts to pull streams over RTS.
    /** 
     * rts 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);
  • stopLiveStream: stops playing streams over RTS.
    aliRts.stopLiveStream();
  • muteLiveStream: mutes streams.
    /** 
     * Mute streams. 
     * @param {Boolean} muted Specifies whether to mute streams. 
     */ 
    aliRts.muteLiveStream(muted);
  • on: invokes 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.
      }
    })