(stream)
Operations related to livestream api
- create - Create a stream
- getAll - Retrieve streams
- get - Retrieve a stream
- update - Update a stream
- delete - Delete a stream
- terminate - Terminates a live stream
- startPull - Start ingest for a pull stream
- createClip - Create a clip
- getClips - Retrieve clips of a livestream
- addMultistreamTarget - Add a multistream target
- removeMultistreamTarget - Remove a multistream target
The only parameter you are required to set is the name of your stream,
but we also highly recommend that you define transcoding profiles
parameter that suits your specific broadcasting configuration.
If you do not define transcoding rendition profiles when creating the
stream, a default set of profiles will be used. These profiles include
240p, 360p, 480p and 720p.
The playback policy is set to public by default for new streams. It can
also be added upon the creation of a new stream by adding
"playbackPolicy": {"type": "jwt"}
import { Livepeer } from "livepeer";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.create({
name: "test_stream",
pull: {
source: "https://myservice.com/live/stream.flv",
headers: {
"Authorization": "Bearer 123",
},
location: {
lat: 39.739,
lon: -104.988,
},
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
record: false,
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
multistream: {
targets: [
{
profile: "720p",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
});
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamCreate } from "livepeer/funcs/streamCreate.js";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamCreate(livepeer, {
name: "test_stream",
pull: {
source: "https://myservice.com/live/stream.flv",
headers: {
"Authorization": "Bearer 123",
},
location: {
lat: 39.739,
lon: -104.988,
},
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
record: false,
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
multistream: {
targets: [
{
profile: "720p",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
request |
components.NewStreamPayload | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.CreateStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Retrieve streams
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.getAll();
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamGetAll } from "livepeer/funcs/streamGetAll.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamGetAll(livepeer);
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
streamsonly |
string | ➖ | N/A |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetStreamsResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Retrieve a stream
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.get("<id>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamGet } from "livepeer/funcs/streamGet.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamGet(livepeer, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the stream |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Update a stream
import { Livepeer } from "livepeer";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.update("<id>", {
record: false,
multistream: {
targets: [
{
profile: "720p",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
});
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamUpdate } from "livepeer/funcs/streamUpdate.js";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamUpdate(livepeer, "<id>", {
record: false,
multistream: {
targets: [
{
profile: "720p",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the stream |
streamPatchPayload |
components.StreamPatchPayload | ✔️ | N/A |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.UpdateStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
This will also suspend any active stream sessions, so make sure to wait until the stream has finished. To explicitly interrupt an active session, consider instead updating the suspended field in the stream using the PATCH stream API.
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.delete("<id>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamDelete } from "livepeer/funcs/streamDelete.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamDelete(livepeer, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the stream |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.DeleteStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
DELETE /stream/{id}/terminate
can be used to terminate an ongoing
session on a live stream. Unlike suspending the stream, it allows the
streamer to restart streaming even immediately, but it will force
terminate the current session and stop the recording.
A 204 No Content status response indicates the stream was successfully
terminated.
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.terminate("<id>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamTerminate } from "livepeer/funcs/streamTerminate.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamTerminate(livepeer, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the stream |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.TerminateStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
POST /stream/{id}/start-pull
can be used to start ingest for a stream
configured with a pull source. If the stream has recording configured,
it will also start recording.
A 204 No Content status response indicates the stream was successfully
started.
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.startPull("<id>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamStartPull } from "livepeer/funcs/streamStartPull.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamStartPull(livepeer, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the stream |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.StartPullStreamResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Create a clip
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.createClip({
playbackId: "eaw4nk06ts2d0mzb",
startTime: 1587667174725,
endTime: 1587667174725,
name: "My Clip",
sessionId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
});
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamCreateClip } from "livepeer/funcs/streamCreateClip.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamCreateClip(livepeer, {
playbackId: "eaw4nk06ts2d0mzb",
startTime: 1587667174725,
endTime: 1587667174725,
name: "My Clip",
sessionId: "de7818e7-610a-4057-8f6f-b785dc1e6f88",
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
request |
components.ClipPayload | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.CreateClipResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Retrieve clips of a livestream
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.getClips("<id>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamGetClips } from "livepeer/funcs/streamGetClips.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamGetClips(livepeer, "<id>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the parent stream or playbackId of parent stream |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.GetClipsResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Add a multistream target
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.addMultistreamTarget("<id>", {
profile: "720p0",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
});
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamAddMultistreamTarget } from "livepeer/funcs/streamAddMultistreamTarget.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamAddMultistreamTarget(livepeer, "<id>", {
profile: "720p0",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the parent stream |
targetAddPayload |
components.TargetAddPayload | ✔️ | N/A |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.AddMultistreamTargetResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |
Remove a multistream target
import { Livepeer } from "livepeer";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.removeMultistreamTarget("<id>", "<value>");
// Handle the result
console.log(result)
}
run();
The standalone function version of this method:
import { LivepeerCore } from "livepeer/core.js";
import { streamRemoveMultistreamTarget } from "livepeer/funcs/streamRemoveMultistreamTarget.js";
// Use `LivepeerCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const livepeer = new LivepeerCore({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const res = await streamRemoveMultistreamTarget(livepeer, "<id>", "<value>");
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result)
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
id |
string | ✔️ | ID of the parent stream |
targetId |
string | ✔️ | ID of the multistream target |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.RemoveMultistreamTargetResponse>
Error Object | Status Code | Content Type |
---|---|---|
errors.SDKError | 4xx-5xx | / |