All Products
Search
Document Center

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

Last Updated:Nov 29, 2025

This topic describes common operations for LiveChannels, such as creating, listing, and deleting LiveChannels.

Create a LiveChannel

Before you can upload audio and video data over the Real-Time Messaging Protocol (RTMP), you must call this API operation to create a LiveChannel. The PutLiveChannel API operation returns an RTMP ingest URL and the corresponding playback URL.

The following code shows how to create a 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))

Get LiveChannel information

The following code shows how to retrieve information about a specific 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 information about the LiveChannel.
store.getChannel(cid).then(r=>console.log(r));

Set the LiveChannel status

The following code shows how to set the status of a 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));

Get LiveChannel status information

The following code shows how to retrieve the stream ingest status of a specific 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 status information of the LiveChannel.
store.getChannelStatus(cid).then(r=>console.log(r))

Generate a LiveChannel playlist

The PostVodPlaylist API operation generates a video-on-demand (VOD) playlist for a specific LiveChannel. This operation queries OSS for the .ts files that are generated from stream ingest to the LiveChannel within a specified time range and combines them into an .m3u8 playlist.

The following code shows how to generate a LiveChannel playlist:

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

List specific LiveChannels

The following code shows how to list specific LiveChannels:

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

Get LiveChannel stream ingest records

The GetLiveChannelHistory API operation gets the stream ingest records of a specific LiveChannel. The GetLiveChannelHistory API operation returns the last 10 stream ingest records for the specified LiveChannel.

The following code shows how to retrieve the stream ingest records of a 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))

Delete a LiveChannel

Important
  • If a client is ingesting a stream to the LiveChannel, the delete request fails.

  • The DeleteLiveChannel API operation deletes only the LiveChannel. It does not delete the files generated from stream ingest.

The following code shows how to delete a specific 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'; 

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

References

  • For more information about the API operation that you can call to create a LiveChannel, see PutLiveChannel.

  • For more information about the API operation that you can call to query the configurations of a LiveChannel, see GetLiveChannelInfo.

  • For more information about the API operation that you can call to configure the status of a LiveChannel, see PutLiveChannelStatus.

  • For more information about the API operation that you can call to query the stream ingest status of a LiveChannel, see GetLiveChannelStat.

  • For more information about the API operation to list specific LiveChannels, see ListLiveChannel.

  • For more information about the API operation that you can call to generate a playlist for a LiveChannel, see PostVodPlaylist.

  • For more information about the API operation that you can call to query the stream ingest records of a LiveChannel, see GetLiveChannelHistory.

  • For more information about the API operation that you can call to delete a LiveChannel, see DeleteLiveChannel.