Todos os produtos
Search
Central de documentação

Object Storage Service:Manage LiveChannels (Node.js SDK)

Última atualização: Jul 03, 2026

Este tópico descreve operações comuns de LiveChannels, como criação, listagem e exclusão.

Criar um LiveChannel

Para enviar dados de áudio e vídeo pelo protocolo RTMP (Real-Time Messaging Protocol), chame esta operação de API para criar um LiveChannel. A operação PutLiveChannel retorna uma URL de ingestão RTMP e a URL de reprodução correspondente.

O código a seguir mostra como criar um LiveChannel:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name. The name cannot contain forward slashes (/). For example, mychannel.
const cid = 'mychannel';
const conf = {
  // Specify the description of the LiveChannel. The description can be up to 128 bytes in length.
  Description: 'this is my channel',
  // Specify the status of the LiveChannel. In this example, the status is set to enabled. To disable the LiveChannel, set this parameter to disabled.
  Status: 'enabled',
  Target: {
    // Specify the dump type. Only HLS is supported.
    Type: 'HLS',
    // Specify the duration of each .ts file in seconds.
    FragDuration: '10',
    // If Type is set to HLS, specify the number of .ts files in the .m3u8 file.
    FragCount: '5',
    // If Type is set to HLS, specify the name of the generated .m3u8 file. The name must end with .m3u8 and be 6 to 128 bytes in length.
    PlaylistName: 'playlist.m3u8'
  }
};

// Create a LiveChannel.
store.putChannel(cid, conf).then(r=>console.log(r))

Obter informações do LiveChannel

O código a seguir mostra como obter informações de um LiveChannel específico:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel'; 

// Get information about the LiveChannel.
store.getChannel(cid).then(r=>console.log(r));

Definir o status do LiveChannel

O código a seguir mostra como definir o status de um LiveChannel:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel';

// A LiveChannel can be enabled or disabled.
// If a LiveChannel is disabled, OSS blocks stream ingest to the channel. If a client is ingesting a stream to the channel, the client is disconnected after a delay of about 10 seconds.
store.putChannelStatus(cid, 'disabled').then(r=>console.log(r));

Obter informações de status do LiveChannel

O código a seguir mostra como obter o status de ingestão de fluxo de um LiveChannel específico:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel';
// Get the status information of the LiveChannel.
store.getChannelStatus(cid).then(r=>console.log(r))

Gerar uma playlist de LiveChannel

A operação PostVodPlaylist gera uma playlist de vídeo sob demanda (VOD) para um LiveChannel específico. Essa operação consulta os arquivos .ts gerados pela ingestão de fluxo no LiveChannel dentro de um intervalo de tempo definido e os combina em uma playlist .m3u8 no OSS.

O código a seguir mostra como gerar uma playlist de LiveChannel:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel';

const r = await this.store.createVod(cid, 're-play', {
  // Specify the start time to query for .ts files. The time must be a UNIX timestamp.
  startTime: 1460464870,
  // Specify the end time to query for .ts files. The time must be a UNIX timestamp.
  endTime: 1460465877
  // The end time must be later than the start time. The time span cannot exceed one day.
}).then(r=>console.log(r))

Listar LiveChannels específicos

O código a seguir mostra como listar LiveChannels específicos:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

const r = await this.store.listChannels({
  // List LiveChannels with the prefix 'my'.
  prefix: 'my',
  // Specify that a maximum of three LiveChannels can be returned.
  'max-keys': 3
}).then(r=>console.log(r))

Obter registros de ingestão de fluxo do LiveChannel

A operação GetLiveChannelHistory obtém os registros de ingestão de fluxo de um LiveChannel específico. Essa operação retorna os últimos 10 registros de ingestão de fluxo do LiveChannel especificado.

O código a seguir mostra como obter os registros de ingestão de fluxo de um LiveChannel:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel';
// Get the stream ingest records of the LiveChannel.
store.getChannelHistory(cid).then(r=>console.log(r))

Excluir um LiveChannel

Importante
  • Se um cliente estiver enviando um fluxo para o LiveChannel, a solicitação de exclusão falhará.

  • A operação DeleteLiveChannel exclui apenas o LiveChannel. Ela não exclui os arquivos gerados pela ingestão de fluxo.

O código a seguir mostra como excluir um LiveChannel específico:

const OSS = require('ali-oss');

const store = new OSS({
  // Replace yourRegion with the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set Region to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before running the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name.
  bucket: 'examplebucket',
})

// Specify the LiveChannel name.
const cid = 'mychannel'; 

// Delete the LiveChannel.
store.deleteChannel(cid).then(r=>console.log(r))

Referências

  • Para obter detalhes sobre a operação PutLiveChannel, consulte PutLiveChannel.

  • Para obter detalhes sobre a operação GetLiveChannelInfo, consulte GetLiveChannelInfo.

  • Para obter detalhes sobre a operação PutLiveChannelStatus, consulte PutLiveChannelStatus.

  • Para obter detalhes sobre a operação GetLiveChannelStat, consulte GetLiveChannelStat.

  • Para obter mais informações sobre a operação de listagem de LiveChannels específicos, consulte ListLiveChannel.

  • Para obter detalhes sobre a operação PostVodPlaylist, consulte PostVodPlaylist.

  • Para obter detalhes sobre a operação GetLiveChannelHistory, consulte GetLiveChannelHistory.

  • Para obter detalhes sobre a operação DeleteLiveChannel, consulte DeleteLiveChannel.