Comment on page
Create Live Stream
Host your events virtually and see community interaction as it happens
.png?alt=media&token=07208f25-f273-4860-a873-7849a5f79354)
There is a limitation for the maximum number of concurrent live events. Reach out to us at community.amity.co with your use-case and we will determine if the current limit can be raised.
To create a stream, follow the code below. This will return a
LiveObject
instance of the created StreamModel
.import { StreamRepository, StreamResolutions } from '@amityco/js-sdk'
const liveObject = StreamRepository.createStream({
title: 'title',
thumbnailFileId: 'fileId', // use FileRepository.createFile to upload the file and get the id
description: 'description',
resolution: StreamResolutions.HD,
metadata: { customField: 'customValue' },
});
liveObject.on('dataUpdated', (stream) => {
console.log(stream);
});
To delete a stream, you will need the ID of the stream that you want to delete. The function will return true if successfully deleted, otherwise, it will throw an error.
import { StreamRepository } from '@amityco/js-sdk';
try {
await StreamRepository.deleteStream('streamId');
console.log('Stream is deleted');
} catch (error) {
console.error('Can not delete the steam', error);
}
Disposing a stream means updating the streaming status to ended and invalidating the streaming URL.
To dispose a stream, you need the ID of the stream that you want to dispose. The function will return true if successfully deleted, otherwise, it will throw an error.
try {
await StreamRepository.disposeStream('streamId');
console.log('Stream is disposed');
} catch (error) {
console.error('Can not dispose the steam', error);
}
Each stream object has a unique identifier. To retrieve a single stream object, use the sample code below. This function returns a
LiveObject
instance of streamModel
. The stream object contains essential data such as the video stream title and description.const liveObject = StreamRepository.getStream('streamId');
liveObject.on('dataUpdated', stream => {
console.log(stream);
);
Stream consists of many states. It can change from one state to another, depending on events and actions. The following enum cases describe all the possible status of a stream.
StreamStatus.Idle
- has generated but no actions have been takenStreamStatus.Live
- currently being broadcastedStreamStatus.Ended
- has ended broadcasting and in the progress of transforming to a recorded streamStreamStatus.Recorded
- has ended broadcasting and has been transformed to a recorded stream
You can check the status of a stream by calling
.status
.import { StreamStatus } from 'amityco/js-sdk';
//retrieve a stream
const liveObject = StreamRepository.getStream('streamId');
liveObject.on('dataUpdated', (stream) => {
console.log(stream.status);
});
StreamRepository
provides a convenient method queryStreams
and can be called to query live streams. We provide enums of stream status as parameters.statuses
. You can observe changes in a collection as per the defined statuses.This function returns a live collection of stream objects.
import { StreamRepository, StreamStatus } from '@amityco/js-sdk';
let streams;
const liveCollection = StreamRepository.queryStreams({
statuses: [StreamStatus.Live],
isDeleted: false,
sortBy: 'lastCreated',
});
liveCollection.on('dataUpdated', newModels => {
streams = newModels;
});
streams = liveCollection.models;
isDeleted
can be any of these values:null
(default) - show all streams (deleted and undeleted)true
- show only deleted streamsfalse
- show only non deleted streams
Last modified 2mo ago