All Products
Search
Document Center

ApsaraVideo Live:Referensi API SDK co-streaming Web

Last Updated:Jul 15, 2026

Menyajikan daftar kelas, metode, dan event dalam SDK co-streaming Web ApsaraVideo Live untuk stream ingest dan stream pulling.

Kelas dasar

Class

Description

AlivcLivePusher

Stream ingest class.

Catatan

Akses melalui window.AlivcLivePush.AlivcLivePusher.

AlivcLivePlayer

Stream pulling class.

Catatan

Akses melalui window.AlivcLivePush.AlivcLivePlayer.

AlivcLivePusher (stream ingest)

Daftar metode

Method

Description

getCameras

Menanyakan kamera. Metode statis.

getMicrophones

Menanyakan mikrofon. Metode statis.

getPlayoutDevices

Menanyakan perangkat pemutaran. Metode statis.

checkSystemRequirements

Memeriksa persyaratan WebRTC. Metode statis.

checkScreenShareSupported

Memeriksa dukungan screen sharing. Metode statis.

init

Menginisialisasi parameter stream ingest.

destroy

Melepas instans stream ingest.

startPreview

Memulai pratinjau.

stopPreview

Menghentikan pratinjau.

startPush

Memulai stream ingest.

restartPush

Memulai ulang stream ingest.

reconnectPush

Menyambung ulang dan melanjutkan stream ingest.

stopPush

Menghentikan stream ingest.

startMicrophone

Menyalakan mikrofon atau beralih ke mikrofon lain.

stopMicrophone

Mematikan mikrofon.

getCurrentMicDeviceId

Menanyakan ID perangkat mikrofon.

startCamera

Menyalakan kamera atau beralih ke kamera lain.

stopCamera

Mematikan kamera.

getCurrentCameraDeviceId

Menanyakan ID perangkat kamera.

startScreenShare

Memulai screen sharing.

stopScreenShare

Menghentikan screen sharing.

startCustomStream

Memulai ingest aliran sekunder kustom.

stopCustomStream

Menghentikan ingest aliran sekunder kustom.

mute

Merendahkan atau mengaktifkan kembali suara aliran. (Stream ingest tidak dihentikan.)

muteVideo

Menampilkan atau menghentikan tampilan aliran. (Stream ingest tidak dihentikan.)

getLivePushStatsInfo

Menanyakan statistik stream ingest terakhir yang dilaporkan.

getPushUrl

Menanyakan URL ingest.

getChannelId

Menanyakan ID channel.

getUserId

Menanyakan ID pengguna.

setLiveMixTranscodingConfig

Memperbarui tata letak untuk relay dan mixing aliran.

getResolution

Menanyakan resolusi.

changeResolution

Memperbarui resolusi.

getFps

Menanyakan frame rate.

changeFps

Memperbarui frame rate.

getPublishMediaStream

Menanyakan informasi MediaStream dari aliran saat ini.

getLiveTraceId

Menanyakan trace ID.

updateScreenVideoProfile

Mengonfigurasi lebar, tinggi, bitrate, dan frame rate track layar.

Detail

  • getCameras: mengambil daftar kamera. Metode statis.

    /**
     * Query cameras.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const cameras = await AlivcLivePusher.getCameras();
  • getMicrophones: mengambil daftar mikrofon. Metode statis.

    /**
     * Query microphones.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const microphones = await AlivcLivePusher.getMicrophones();
  • getPlayoutDevices: mengambil daftar perangkat pemutaran. Metode statis.

    /**
     * Query playback devices.
     * @return {Promise<MediaDeviceInfo[]>}
     */
    const playoutDevices = await AlivcLivePusher.getPlayoutDevices();
  • checkSystemRequirements: memeriksa persyaratan sistem WebRTC. Metode statis.

    /**
     * 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: memeriksa dukungan screen sharing. Metode statis.

    /**
     * Check whether screen sharing is supported.
     * @returns {boolean}
     */
    const isScreenShareSupported = AlivcLivePusher.checkScreenShareSupported();
  • init: menginisialisasi parameter stream ingest.

    /**
     * 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: melepas instans stream ingest.

    // Release the stream ingest instance. You cannot use the instance after you release it.
    pusher.destroy()
  • startPreview: memulai pratinjau.

    /**
     * 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: menghentikan pratinjau.

    /**
     * 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: memulai stream ingest.

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

    Anda harus menentukan URL ingest yang digunakan untuk co-streaming. Untuk informasi tentang cara menghasilkan URL untuk co-streaming, lihat Co-streaming URL generator.

  • restartPush: menggunakan URL ingest saat ini untuk memulai ulang stream ingest.

    /**
     * Use the current ingest URL to restart stream ingest.
     * @return {Promise}
     */
    await pusher.restartPush();
  • reconnectPush: menyambung ulang dan melanjutkan stream ingest.

    /**
     * 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: menghentikan stream ingest.

    /**
     * Stop stream ingest.
     * @return {Promise}
     */
    await pusher.stopPush(url);
  • startMicrophone: mengaktifkan mikrofon atau beralih ke mikrofon lain.

    /**
     * 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: menonaktifkan mikrofon.

    /**
     * Turn off the microphone.
     * @return {Promise}
     */
    await pusher.stopMicrophone();
  • getCurrentMicDeviceId: mengambil ID perangkat mikrofon saat ini.

    /**
     * Query the device ID of the microphone.
     * @return {string | undefined} The device ID of the microphone.
     */
    const micId = pusher.getCurrentMicDeviceId();
  • startCamera: mengaktifkan kamera atau beralih ke kamera lain.

    /**
     * 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: menonaktifkan kamera.

    /**
     * Turn off the camera.
     * @return {Promise}
     */
    await pusher.stopCamera();
  • getCurrentCameraDeviceId: mengambil ID perangkat kamera saat ini.

    /**
     * Query the device ID of the camera.
     * @return {string | undefined} The device ID of the camera.
     */
    const cameraId = pusher.getCurrentCameraDeviceId();
  • startScreenShare: memulai screen sharing.

    /**
     * Start screen sharing.
     * @return {Promise}
     */
    await pusher.startScreenShare();
  • stopScreenShare: menghentikan screen sharing.

    /**
     * Stop screen sharing.
     * @return {Promise}
     */
    await pusher.stopScreenShare();
  • startCustomStream: memulai ingest aliran sekunder kustom.

    /**
     * Start ingest of the custom secondary stream.
     * @param mediaStream The custom secondary stream.
     * @return {Promise<MediaStream>}
     */
    await pusher.startCustomStream(mediaStream);
  • stopCustomStream: menghentikan ingest aliran sekunder kustom.

    /**
     * Stop ingest of the custom secondary stream.
     * @return {Promise<void>}
     */
    await pusher.stopCustomStream();
  • mute: membisukan atau mengaktifkan kembali suara aliran. (Stream ingest tidak dihentikan.)

    /**
     * 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: menyembunyikan atau menampilkan kembali tampilan video aliran. (Stream ingest tidak dihentikan.)

    /**
     * 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: mengambil statistik stream ingest terakhir yang dilaporkan.

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

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

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

    /**
     * Query the user ID.
     * @return {string | undefined} The current user ID.
     */
    const userId = pusher.getUserId();
  • setLiveMixTranscodingConfig: memperbarui tata letak untuk relay dan mixing aliran.

    /**
     * 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: mengambil resolusi.

    /**
     * Query the resolution.
     * @return {AlivcResolutionEnum | undefined} The resolution.
     */
    const resolution = pusher.getResolution();
  • changeResolution: memperbarui resolusi.

    /**
     * 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: mengambil frame rate.

    /**
     * Query the frame rate.
     * @return {AlivcFpsEnum | undefined} The current frame rate.
     */
    const fps = pusher.getFps();
  • changeFps: memperbarui frame rate.

    /**
     * Update the frame rate.
     * @param {AlivcFpsEnum} fps The frame rate that you want to use.
     * @return {Promise}
     */
    await pusher.changeFps(AlivcFpsEnum.FPS_30);
  • getPublishMediaStream: mengambil informasi MediaStream dari aliran saat ini.

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

    /**
     * Query the trace ID.
     * @return {string} TraceId
     */
     pusher.getLiveTraceId();
  • updateScreenVideoProfile: mengonfigurasi lebar, tinggi, bitrate, dan frame rate track layar.

    /**
     * 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

Daftar parameter

Parameter

Description

width

Lebar aliran yang direlay.

height

Tinggi aliran yang direlay.

backgroundColor

Warna latar belakang dalam heksadesimal. Contoh: 0x000000.

cropMode

AlivcLiveTranscodingCropModeEnum

  • AlivcLiveTranscodingCropModeCrop: Mode cropping.

  • AlivcLiveTranscodingCropModeFill: Mode padding.

mixStreams

AlivcLiveMixStream[]: Konfigurasi tata letak untuk setiap aliran dalam mix.

AlivcLiveMixStream

Daftar parameter

Parameter

Description

userId

ID pengguna peserta mixing aliran.

x

Offset sumbu-X dalam piksel untuk aliran yang dicampur.

y

Offset sumbu-Y dalam piksel untuk aliran yang dicampur.

width

Lebar aliran yang dicampur.

height

Tinggi aliran yang dicampur.

zOrder

Urutan layer. Nilai yang lebih tinggi muncul di atas.

sourceType

Jenis sumber video.

Nilai yang valid:

  • 0: Kamera

  • 1: Screen sharing

Nilai default: 0.

AlivcLivePusher.info

Event

Description

bye

Penonton meninggalkan ruangan, baik karena digantikan oleh penonton lain maupun dihapus oleh streamer.

pushstatistics

Statistik aliran ingest. Dipicu setiap 2 detik.

Kode contoh:

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

Event

Description

system

Kesalahan sistem.

sdk

Kesalahan internal SDK.

Kode contoh:

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

AlivcLivePusher.network

Event

Description

connectionlost

Terputus.

networkrecovery

Jaringan pulih.

reconnectstart

Proses penyambungan ulang dimulai.

reconnectfail

Penyambungan ulang gagal.

reconnectsucceed

Penyambungan ulang berhasil.

Kode contoh:

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

AlivcLivePlayer (stream pulling)

Daftar metode

Method

Description

startPlay

Memulai pemutaran audio dan video.

playAnotherElement

Memutar audio dan video pada elemen lain.

stopPlay

Menghentikan pemutaran audio dan video.

pauseAudioPlaying

Mengjeda pemutaran audio.

pauseVideoPlaying

Mengjeda pemutaran video.

resumeAudioPlaying

Melanjutkan pemutaran audio.

resumeVideoPlaying

Melanjutkan pemutaran video.

destroy

Melepas instans pemutar.

Detail

  • startPlay: memulai pemutaran audio dan video.

    /**
     * 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);
    Penting
    • Anda harus menentukan URL streaming yang digunakan untuk co-streaming. Untuk informasi tentang cara menghasilkan URL untuk co-streaming, lihat Co-streaming URL generator.

    • Penonton biasa dapat memutar aliran dengan ApsaraVideo Player SDK untuk Web. Akses cepat ke pemutar web.

  • playAnotherElement: memutar audio dan video pada elemen lain.

    /**
     * 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: menghentikan pemutaran audio dan video.

    /**
     * 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: menjeda pemutaran audio.

    /**
     * Pause the playback of the audio stream.
     */
    player.pauseAudioPlaying();
  • pauseVideoPlaying: menjeda pemutaran video.

    /**
     * Pause the playback of the video stream.
     */
    player.pauseVideoPlaying();
  • resumeAudioPlaying: melanjutkan pemutaran audio.

    /**
     * Resume the playback of the audio stream.
     */
    player.resumeAudioPlaying();
  • resumeVideoPlaying: melanjutkan pemutaran video.

    /**
     * Resume the playback of the video stream.
     */
    player.resumeVideoPlaying();
  • destroy: melepas instans pemutar.

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

AlivcLivePlayInfo

Event

Description

canplay

Aliran siap diputar.

userleft

Pengguna jarak jauh meninggalkan ruangan.

statistics

Statistik pemutaran.

update

Memperbarui aliran jarak jauh.

Kode contoh:

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);
});