Tous les produits
Search
Centre de documentation

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

Dernière mise à jour :Aug 18, 2026

Cette rubrique décrit les opérations courantes sur les LiveChannels, telles que la création, la liste et la suppression de LiveChannels.

Créer un LiveChannel

Avant de pouvoir envoyer des données audio et vidéo via le protocole RTMP (Real-Time Messaging Protocol), vous devez appeler cette opération d'API pour créer un LiveChannel. L'opération d'API PutLiveChannel renvoie une URL d'ingestion RTMP et l'URL de lecture correspondante.

Le code suivant montre comment créer un 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))

Obtenir des informations sur un LiveChannel

Le code suivant montre comment récupérer des informations sur un LiveChannel spécifique :

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

Définir le statut d'un LiveChannel

Le code suivant montre comment définir le statut d'un 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));

Obtenir des informations sur le statut d'un LiveChannel

Le code suivant montre comment récupérer le statut d'ingestion de flux d'un LiveChannel spécifique :

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

Générer une playlist de LiveChannel

L'opération d'API PostVodPlaylist génère une playlist de vidéo à la demande (VOD) pour un LiveChannel spécifique. Cette opération interroge OSS pour rechercher les fichiers .ts générés par l'ingestion de flux vers le LiveChannel dans une plage de temps spécifiée et les combine dans une playlist .m3u8.

Le code suivant montre comment générer une 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))

Répertorier des LiveChannels spécifiques

Le code suivant montre comment répertorier des LiveChannels spécifiques :

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

Obtenir les enregistrements d'ingestion de flux d'un LiveChannel

L'opération d'API GetLiveChannelHistory récupère les enregistrements d'ingestion de flux d'un LiveChannel spécifique. L'opération d'API GetLiveChannelHistory renvoie les 10 derniers enregistrements d'ingestion de flux pour le LiveChannel spécifié.

Le code suivant montre comment récupérer les enregistrements d'ingestion de flux d'un 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))

Supprimer un LiveChannel

Important
  • Si un client ingère un flux vers le LiveChannel, la requête de suppression échoue.

  • L'opération d'API DeleteLiveChannel supprime uniquement le LiveChannel. Elle ne supprime pas les fichiers générés par l'ingestion de flux.

Le code suivant montre comment supprimer un LiveChannel spécifique :

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

Références

  • Pour plus d'informations sur l'opération d'API PutLiveChannel, voir PutLiveChannel.

  • Pour plus d'informations sur l'opération d'API GetLiveChannelInfo, voir GetLiveChannelInfo.

  • Pour plus d'informations sur l'opération d'API PutLiveChannelStatus, voir PutLiveChannelStatus.

  • Pour plus d'informations sur l'opération d'API GetLiveChannelStat, voir GetLiveChannelStat.

  • Pour plus d'informations sur l'opération d'API permettant de répertorier des LiveChannels spécifiques, voir ListLiveChannel.

  • Pour plus d'informations sur l'opération d'API PostVodPlaylist, voir PostVodPlaylist.

  • Pour plus d'informations sur l'opération d'API GetLiveChannelHistory, voir GetLiveChannelHistory.

  • Pour plus d'informations sur l'opération d'API DeleteLiveChannel, voir DeleteLiveChannel.