Tous les produits
Search
Centre de documentation

ApsaraVideo Live:Référence de l'API du SDK Web de co-streaming

Dernière mise à jour :Aug 19, 2026

Cette rubrique répertorie les classes, méthodes et événements du SDK Web de co-streaming d'ApsaraVideo Live pour l'ingestion et la lecture de flux.

Classes de base

Classe

Description

AlivcLivePusher

Classe d'ingestion de flux.

Remarque

Accessible via window.AlivcLivePush.AlivcLivePusher.

AlivcLivePlayer

Classe de lecture de flux.

Remarque

Accessible via window.AlivcLivePush.AlivcLivePlayer.

AlivcLivePusher (ingestion de flux)

Liste des méthodes

Méthode

Description

getCameras

Interroge les caméras. Méthode statique.

getMicrophones

Interroge les microphones. Méthode statique.

getPlayoutDevices

Interroge les périphériques de lecture. Méthode statique.

checkSystemRequirements

Vérifie les prérequis WebRTC. Méthode statique.

checkScreenShareSupported

Vérifie la prise en charge du partage d'écran. Méthode statique.

init

Initialise les paramètres d'ingestion de flux.

destroy

Libère l'instance d'ingestion de flux.

startPreview

Démarre l'aperçu.

stopPreview

Arrête l'aperçu.

startPush

Démarre l'ingestion de flux.

restartPush

Redémarre l'ingestion de flux.

reconnectPush

Se reconnecte et poursuit l'ingestion de flux.

stopPush

Arrête l'ingestion de flux.

startMicrophone

Active le microphone ou bascule vers un autre microphone.

stopMicrophone

Désactive le microphone.

getCurrentMicDeviceId

Interroge l'ID du périphérique du microphone.

startCamera

Active la caméra ou bascule vers une autre caméra.

stopCamera

Désactive la caméra.

getCurrentCameraDeviceId

Interroge l'ID du périphérique de la caméra.

startScreenShare

Démarre le partage d'écran.

stopScreenShare

Arrête le partage d'écran.

startCustomStream

Démarre l'ingestion du flux secondaire personnalisé.

stopCustomStream

Arrête l'ingestion du flux secondaire personnalisé.

mute

Coupe ou rétablit le son du flux. (L'ingestion de flux n'est pas arrêtée.)

muteVideo

Affiche ou masque le flux vidéo. (L'ingestion de flux n'est pas arrêtée.)

getLivePushStatsInfo

Interroge les dernières statistiques d'ingestion de flux signalées.

getPushUrl

Interroge l'URL d'ingestion.

getChannelId

Interroge l'ID du canal.

getUserId

Interroge l'ID utilisateur.

setLiveMixTranscodingConfig

Met à jour la disposition pour la relais et le mixage de flux.

getResolution

Interroge la résolution.

changeResolution

Met à jour la résolution.

getFps

Interroge la fréquence d'images.

changeFps

Met à jour la fréquence d'images.

getPublishMediaStream

Interroge les informations MediaStream du flux actuel.

getLiveTraceId

Interroge l'ID de trace.

updateScreenVideoProfile

Configure la largeur, la hauteur, le débit binaire et la fréquence d'images de la piste d'écran.

Détails

  • getCameras : interroge les caméras. Méthode statique.

    /**
     * Query cameras.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const cameras = await AlivcLivePusher.getCameras();
  • getMicrophones : interroge les microphones. Méthode statique.

    /**
     * Query microphones.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const microphones = await AlivcLivePusher.getMicrophones();
  • getPlayoutDevices : interroge les périphériques de lecture. Méthode statique.

    /**
     * Query playback devices.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const playoutDevices = await AlivcLivePusher.getPlayoutDevices();
  • checkSystemRequirements : vérifie les prérequis WebRTC. Méthode statique.

    /**
     * Check whether the requirements for WebRTC are met.
     * @param {('sendonly' | 'recvonly' | 'sendrecv')} [direction]
     * @return {Promise<CheckResult>}
     */
    const checkResult = await AlivcLivePusher.checkSystemRequirements();
    // checkResult.support: boolean; Indicates whether the requirements are met.
    // checkResult.detail.isBrowserSupported: boolean; Indicates whether the browser is supported.
    // checkResult.detail.isH264DecodeSupported: boolean; Indicates whether H.264 decoding is supported.
    // checkResult.detail.isH264EncodeSupported: boolean; Indicates whether H.264 encoding is supported.
    // checkResult.detail.isWebRTCSupported: boolean; Indicates whether WebRTC is supported.
  • checkScreenShareSupported : vérifie la prise en charge du partage d'écran. Méthode statique.

    /**
     * Check whether screen sharing is supported.
     * @returns {boolean}
     */
    const isScreenShareSupported = AlivcLivePusher.checkScreenShareSupported();
  • init : initialise les paramètres d'ingestion de flux.

    /**
     * Initialize the RTC engine.
     * @param config Configure parameters. All the parameters are optional.
     * config.resolution: AlivcResolutionEnum; The resolution.
     * config.fps: AlivcFpsEnum; The frame rate. Unit: frames per second (FPS).
     * config.logLevel: LogLevel; The log level. Default value: ERROR.
     * config.connectRetryCount: number; The maximum number of reconnection attempts.
     * config.audio: boolean; Specifies whether to enable audio.
     * config.audioId: string; The ID of the default audio device.
     * config.video: boolean; Specifies whether to turn on the camera.
     * config.cameraId: string; The device ID of the default camera.
     * config.screen: boolean; Specifies whether to enable screen sharing.
     */
    const pusher = new AlivcLivePush.AlivcLivePusher();
    pusher.init({
      resolution: AlivcLivePush.AlivcResolutionEnum.RESOLUTION_720P
    });
  • destroy : libère l'instance d'ingestion de flux.

    // Release the stream ingest instance. You cannot use the instance after you release it.
    pusher.destroy()
  • startPreview : démarre l'aperçu.

    /**
     * Start video preview.
     * @param {string | HTMLVideoElement} elementOrId The node where the video resides or the ID of the video.
     * @param {boolean} secondary Specifies whether to preview the secondary stream. This parameter is optional. By default, only the primary stream is previewed.
     * @return {Promise<MediaStream>}
     */
    const stream = pusher.startPreview(elementOrId);
  • stopPreview : arrête l'aperçu.

    /**
     * Stop video preview.
     * @param {string | HTMLVideoElement} elementOrId The node where the video resides or the ID of the video. This parameter is optional. If you do not specify this parameter, previewing for all videos is stopped.
     */
    pusher.stopPreview(elementOrId);
  • startPush : démarre l'ingestion de flux.

    /**
     * Start stream ingest.
     * @param {string} url The ingest URL. Example: artc://live.aliyun.com/push/....
     * @return {Promise}
     */
    await pusher.startPush(url);
    Important

    Vous devez spécifier une URL d'ingestion utilisée pour le co-streaming. Pour savoir comment générer des URL de co-streaming, consultez Générateur d'URL de co-streaming.

  • restartPush : redémarre l'ingestion de flux à l'aide de l'URL d'ingestion actuelle.

    /**
     * Use the current ingest URL to restart stream ingest.
     * @return {Promise}
     */
    await pusher.restartPush();
  • reconnectPush : se reconnecte et poursuit l'ingestion de flux.

    /**
     * Reconnect and continue stream ingest. 
     * @param {string} url The new ingest URL. Example: artc://live.aliyun.com/push/....
     * @return {Promise}
     */
    await pusher.reconnectPush(url);
  • stopPush : arrête l'ingestion de flux.

    /**
     * Stop stream ingest.
     * @return {Promise}
     */
    await pusher.stopPush(url);
  • startMicrophone : active le microphone ou bascule vers un autre microphone.

    /**
     * Turn on the microphone or switch to another microphone.
     * @param {string} deviceId The device ID of the microphone. This parameter is optional.
     * @return {Promise}
     */
    await pusher.startMicrophone(deviceId);
  • stopMicrophone : désactive le microphone.

    /**
     * Turn off the microphone.
     * @return {Promise}
     */
    await pusher.stopMicrophone();
  • getCurrentMicDeviceId : interroge l'ID du périphérique du microphone.

    /**
     * Query the device ID of the microphone.
     * @return {string | undefined} The device ID of the microphone.
     */
    const micId = pusher.getCurrentMicDeviceId();
  • startCamera : active la caméra ou bascule vers une autre caméra.

    /**
     * Turn on the camera or switch to another camera.
     * @param {string} deviceId The device ID of the camera. This parameter is optional.
     * @return {Promise}
     */
    await pusher.startCamera(deviceId);
  • stopCamera : désactive la caméra.

    /**
     * Turn off the camera.
     * @return {Promise}
     */
    await pusher.stopCamera();
  • getCurrentCameraDeviceId : interroge l'ID du périphérique de la caméra.

    /**
     * Query the device ID of the camera.
     * @return {string | undefined} The device ID of the camera.
     */
    const cameraId = pusher.getCurrentCameraDeviceId();
  • startScreenShare : démarre le partage d'écran.

    /**
     * Start screen sharing.
     * @return {Promise}
     */
    await pusher.startScreenShare();
  • stopScreenShare : arrête le partage d'écran.

    /**
     * Stop screen sharing.
     * @return {Promise}
     */
    await pusher.stopScreenShare();
  • startCustomStream : démarre l'ingestion du flux secondaire personnalisé.

    /**
     * Start ingest of the custom secondary stream.
     * @param mediaStream The custom secondary stream.
     * @return {Promise<MediaStream>}
     */
    await pusher.startCustomStream(mediaStream);
  • stopCustomStream : arrête l'ingestion du flux secondaire personnalisé.

    /**
     * Stop ingest of the custom secondary stream.
     * @return {Promise<void>}
     */
    await pusher.stopCustomStream();
  • mute : coupe ou rétablit le son du flux. (L'ingestion de flux n'est pas arrêtée.)

    /**
     * Mute or unmute the stream.
     * @param {boolean} Specifies whether to mute the stream.
     * @returns {AlivcLivePusher} Returns the pusher instance for method chaining.
     */
    pusher.mute(true);
  • muteVideo : affiche ou masque le flux vidéo. (L'ingestion de flux n'est pas arrêtée.)

    /**
     * Display or stop displaying the stream.
     * @param mute Specifies whether to stop sending video data. Valid values: true and false.
     * @returns {AlivcLivePusher} Returns the pusher instance for method chaining.
     */
    pusher.muteVideo(true);
  • getLivePushStatsInfo : interroge les dernières statistiques d'ingestion de flux signalées.

    /**
     * Query the stream ingest statistics that was last reported.
     * @return {StatsInfo} The stream ingest statistics.
     */
    const statsInfo = pusher.getLivePushStatsInfo();
  • getPushUrl : interroge l'URL d'ingestion.

    /**
     * Query the ingest URL.
     * @return {string | undefined} The current ingest URL.
     */
    const url = pusher.getPushUrl();
  • getChannelId : interroge l'ID du canal.

    /**
     * Query the channel ID.
     * @return {string | undefined} The current channel ID.
     */
    const channelId = pusher.getChannelId();
  • getUserId : interroge l'ID utilisateur.

    /**
     * Query the user ID.
     * @return {string | undefined} The current user ID.
     */
    const userId = pusher.getUserId();
  • setLiveMixTranscodingConfig : met à jour la disposition pour la relais et le mixage de flux.

    /**
     * Update the layout for stream relay and mixing.
     * @param {AlivcLiveTranscodingConfig} config This parameter is optional. If you do not specify this parameter, stream relay and mixing are stopped. For more information, check the details about the AlivcLiveTranscodingConfig class.
     * @return {Promise} The result of the operation.
     */
    const response = await pusher.setLiveMixTranscodingConfig(config);
  • getResolution : interroge la résolution.

    /**
     * Query the resolution.
     * @return {AlivcResolutionEnum | undefined} The resolution.
     */
    const resolution = pusher.getResolution();
  • changeResolution : met à jour la résolution.

    /**
     * Update the resolution.
     * @param resolutionEnum The resolution that you want to use. If you set this parameter to Custom, specify a custom resolution.
     * @param width The width, which is required when you specify a custom resolution.
     * @param height The height, which is required when you specify a custom resolution.
     * @param bitrate The maximum bitrate.
     * @return {Promise}
     */
    await pusher.changeResolution(AlivcResolutionEnum.RESOLUTION_720P);
  • getFps : interroge la fréquence d'images.

    /**
     * Query the frame rate.
     * @return {AlivcFpsEnum | undefined} The current frame rate.
     */
    const fps = pusher.getFps();
  • changeFps : met à jour la fréquence d'images.

    /**
     * Update the frame rate.
     * @param {AlivcFpsEnum} fps The frame rate that you want to use.
     * @return {Promise}
     */
    await pusher.changeFps(AlivcFpsEnum.FPS_30);
  • getPublishMediaStream : interroge les informations MediaStream du flux actuel.

    /**
     * Query the MediaStream information of the current stream.
     * @return {MediaStream | undefined} The MediaStream information of the stream.
     */
    const mediaStream = pusher.getPublishMediaStream();
  • getLiveTraceId : interroge l'ID de trace.

    /**
     * Query the trace ID.
     * @return {string} TraceId
     */
     pusher.getLiveTraceId();
  • updateScreenVideoProfile : configure la largeur, la hauteur, le débit binaire et la fréquence d'images de la piste d'écran.

    /**
     * Configure the width, height, bitrate, and frame rate of the screen track. (Due to browser constraints, the specified width and height are not applied.)
     * @param width 
     * @param height 
     * @param rate 
     * @param fps 
     * @return {Promise}
     */
    await pusher.updateScreenVideoProfile(width,height,rate,fps);

AlivcLiveTranscodingConfig

Liste des paramètres

Paramètre

Description

width

Largeur du flux relayé.

height

Hauteur du flux relayé.

backgroundColor

Couleur d'arrière-plan au format hexadécimal. Exemple : 0x000000.

cropMode

AlivcLiveTranscodingCropModeEnum

  • AlivcLiveTranscodingCropModeCrop : mode de recadrage.

  • AlivcLiveTranscodingCropModeFill : mode de remplissage.

mixStreams

AlivcLiveMixStream[] : configuration de la disposition pour chaque flux dans le mixage.

AlivcLiveMixStream

Liste des paramètres

Paramètre

Description

userId

ID utilisateur du participant au mixage de flux.

x

Décalage sur l'axe X en pixels pour le flux mixé.

y

Décalage sur l'axe Y en pixels pour le flux mixé.

width

Largeur du flux mixé.

height

Hauteur du flux mixé.

zOrder

Ordre des calques. Les valeurs plus élevées apparaissent au premier plan.

sourceType

Type de source vidéo.

Valeurs valides :

  • 0 : Caméra

  • 1 : Partage d'écran

Valeur par défaut : 0.

AlivcLivePusher.info

Événement

Description

bye

Un spectateur a quitté la salle, soit déplacé par d'autres spectateurs, soit supprimé par le diffuseur.

pushstatistics

Statistiques d'ingestion de flux. Déclenché toutes les 2 secondes.

Exemple de code :

pusher.info.on('bye', (_code, reason) => {
  // console.log ('You have left the room. Reason: ${reason}');
});
pusher.info.on('pushstatistics', _stat => {
  // console.log(_stat);
});

AlivcLivePusher.error

Événement

Description

system

Erreur système.

sdk

Erreur interne du SDK.

Exemple de code :

pusher.error.on('system', error => {
  // console.log(error);
});
pusher.error.on('sdk', error => {
  // console.log(error);
});

AlivcLivePusher.network

Événement

Description

connectionlost

Déconnexion.

networkrecovery

Rétablissement du réseau.

reconnectstart

Début de la reconnexion.

reconnectfail

Échec de la reconnexion.

reconnectsucceed

Succès de la reconnexion.

Exemple de code :

pusher.network.on('connectionlost', () => {
  // console.log ('A network exception occurs, which results in a disconnection.');
});

AlivcLivePlayer (lecture de flux)

Liste des méthodes

Méthode

Description

startPlay

Démarre la lecture audio et vidéo.

playAnotherElement

Lit l'audio et la vidéo sur un autre élément.

stopPlay

Arrête la lecture audio et vidéo.

pauseAudioPlaying

Met en pause la lecture audio.

pauseVideoPlaying

Met en pause la lecture vidéo.

resumeAudioPlaying

Reprend la lecture audio.

resumeVideoPlaying

Reprend la lecture vidéo.

destroy

Libère l'instance du lecteur.

Détails

  • startPlay : démarre la lecture audio et vidéo.

    /**
     * Start the playback of the audio and video streams.
     * @param url The streaming URL. Example: artc://live.aliyun.com/play/...
     * @param elementOrId The label or ID of the media resource.
     * @param secondaryElementOrId The label or ID of the media resource of the secondary stream.
     * @return {Promise<AlivcLivePlayInfo>} You can use AlivcLivePlayInfo to listen to related events.
     */
    const playInfo = await player.startPlay(url, elementOrId, secondaryElementOrId);
    Important
  • playAnotherElement : lit l'audio et la vidéo sur un autre élément.

    /**
     * Play the audio and video streams on another node.
     * @param elementOrId The label or ID of the media resource.
     * @param secondary Specifies whether to play the secondary stream. This parameter is optional. By default, only the primary stream is played.
     */
    player.playAnotherElement(elementOrId);
  • stopPlay : arrête la lecture audio et vidéo.

    /**
     * Stop the playback of the audio and video streams.
     * @param elementOrId The label or ID of the media resource. This parameter is optional. If you do not specify this parameter, playback of all media resources is stopped.
     * @return {Promise} 
     */
    await player.stopPlay(elementOrId);
  • pauseAudioPlaying : met en pause la lecture audio.

    /**
     * Pause the playback of the audio stream.
     */
    player.pauseAudioPlaying();
  • pauseVideoPlaying : met en pause la lecture vidéo.

    /**
     * Pause the playback of the video stream.
     */
    player.pauseVideoPlaying();
  • resumeAudioPlaying : reprend la lecture audio.

    /**
     * Resume the playback of the audio stream.
     */
    player.resumeAudioPlaying();
  • resumeVideoPlaying : reprend la lecture vidéo.

    /**
     * Resume the playback of the video stream.
     */
    player.resumeVideoPlaying();
  • destroy : libère l'instance du lecteur.

    /**
     * Release the stream pulling instance. You cannot use the instance after you release it.
     */
    player.destroy();

AlivcLivePlayInfo

Événement

Description

canplay

Flux prêt pour la lecture.

userleft

L'utilisateur distant a quitté la salle.

statistics

Statistiques de lecture.

update

Met à jour le flux distant.

Exemple de code :

playInfo.on('statistics', _stat => {
  // console.log(_stat);
});
playInfo.on('userleft', () => {
  // console.log ('The remote user leaves the room.');
});
playInfo.on('canplay', function () {
  // console.log ('The remote stream can be played.');
});
playInfo.on('update', function (previousStatus) {
  // console.log(previousStatus.mediaStream);
  // console.log(previousStatus.secondaryMediaStream);
});