Skip to content

Latest commit

 

History

History
1111 lines (850 loc) · 69.3 KB

README.md

File metadata and controls

1111 lines (850 loc) · 69.3 KB

Stream

(stream)

Overview

Operations related to livestream api

Available Operations

create

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"}

Example Usage

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: "720p0",
          videoOnly: false,
          id: "PUSH123",
          spec: {
            name: "My target",
            url: "rtmps://live.my-service.tv/channel/secretKey",
          },
        },
      ],
    },
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

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: "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();

Parameters

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.

Response

Promise<operations.CreateStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

getAll

Retrieve streams

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.GetStreamsResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

get

Retrieve a stream

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.GetStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

update

Update a stream

Example Usage

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({
    record: false,
    multistream: {
      targets: [
        {
          profile: "720p0",
          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,
        },
      ],
    },
    name: "test_stream",
  }, "<id>");

  // Handle the result
  console.log(result);
}

run();

Standalone function

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, {
    record: false,
    multistream: {
      targets: [
        {
          profile: "720p0",
          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,
        },
      ],
    },
    name: "test_stream",
  }, "<id>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

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.

Response

Promise<operations.UpdateStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

delete

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.

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.DeleteStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

terminate

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.

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.TerminateStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

startPull

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.

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.StartPullStreamResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

createClip

Create a clip

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.CreateClipResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

getClips

Retrieve clips of a livestream

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.GetClipsResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

addMultistreamTarget

Add a multistream target

Example Usage

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await livepeer.stream.addMultistreamTarget({
    profile: "720p0",
    videoOnly: false,
    id: "PUSH123",
    spec: {
      name: "My target",
      url: "rtmps://live.my-service.tv/channel/secretKey",
    },
  }, "<id>");

  // Handle the result
  console.log(result);
}

run();

Standalone function

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, {
    profile: "720p0",
    videoOnly: false,
    id: "PUSH123",
    spec: {
      name: "My target",
      url: "rtmps://live.my-service.tv/channel/secretKey",
    },
  }, "<id>");

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

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.

Response

Promise<operations.AddMultistreamTargetResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*

removeMultistreamTarget

Remove a multistream target

Example Usage

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

Standalone function

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

Parameters

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.

Response

Promise<operations.RemoveMultistreamTargetResponse>

Errors

Error Type Status Code Content Type
errors.SDKError 4XX, 5XX */*