Este tópico descreve os métodos do SDK de Real-Time Streaming (RTS) para web.
Visão geral
|
Método |
Descrição |
|
Cria uma instância do SDK de RTS para web. |
|
|
Verifica se o navegador é compatível. |
|
|
Inicia o pull de streams por RTS. |
|
|
Interrompe a reprodução de streams por RTS. |
|
|
Silencia os streams. |
|
|
Registra um callback. |
Código de exemplo
-
new AliRTS(): cria uma instância do SDK de RTS para web.
var aliRts = new AliRTS(); -
isSupport: verifica se o navegador é compatível.
// 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: inicia o pull de streams por 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: interrompe a reprodução de streams por RTS.
aliRts.stopLiveStream(); -
muteLiveStream: silencia os streams.
/** * Mute streams. * @param {Boolean} muted Specifies whether to mute streams. */ aliRts.muteLiveStream(muted); -
on: registra um 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. } })