All Products
Search
Document Center

RTS Web SDK

Last Updated: May 08, 2021

This topic describes the basic information of Real-Time Streaming (RTS) Web SDK. This topic also describes how to use the SDK.

Overview

RTS Web SDK is a JavaScript library loaded on HTML web pages. You cannot use the SDK to watch live streaming online and do not need to install an application. RTS Web SDK is used only to pull streams over RTS. It allows you to view audio or video streams by using mobile phones, WeChat, and web browsers. This topic is intended for developers who have basic knowledge of JavaScript. The video playback feature of RTS Web SDK is not provided by web page code but by browsers. Therefore, videos may fail to be properly played in some browsers. The following table describes the compatibility between different operating systems and browsers.

Compatibility

Operating system

Browser

Supported earliest version

Windows

Chrome

63

Firefox

62

Opera

15

Mac

Chrome

63

Safari

11

Firefox

62

Opera

15

Android

Chrome

63

WeChat browser

7.0.9

iOS

Safari

11

WeChat browser

7.0.9

DingTalk browser

11.2.5

Notice

Browsers do not allow you to use HTTPS to load HTTP resources because of policy issues. Therefore, you must use the HTTPS URL demo to access an HTTPS-based source URL. Similarly, you must use the HTTP URL demo to access an HTTP-based source URL.

Instructions

Access method

  • Initialize an instance.

    var aliRts = new AliRTS()
  • Call the isSupport method to 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=> { 
        // Available. 
    }).catch(err=> { 
      // Not available. 
      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 attached to the video. 
     * @return {Promise}  
     */ 
    aliRts.startLiveStream(pullStreamUrl, mediaElement);
  • Stop playback.

    /** 
     * The method that is used to stop playback. 
     */ 
    aliRts.stopLiveStream();
  • Mute the 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.)
      }
    })

Error codes

Error code

Error message

Description

10001

http request error

The error message returned because a signaling request error occurs.

10002

play failed

The error message returned because playback fails.

10010

not support webrtc

The error message returned because WebRTC is not supported.

10011

browser not support

The error message returned because the browser is not supported.

10012

browser version too low

The error message returned because the browser version is outdated.

10013

not support h264

The error message returned because H.264 is not supported.

10014

create offer error

The error message returned because the offer fails to be created.

10201

auto play failed

The error message returned because autoplay fails.