livepeer
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

Livepeer JavaScript Library

Version Downloads Try on RunKit

The Livepeer JavaScript library provides convenient access to the Livepeer Studio API from applications written in both browser and server-side JavaScript

Documentation

For full documentation and examples, please visit docs.livepeer.org.

Installation

Install the package with:

npm install livepeer
# or
yarn add livepeer

Usage

The package needs to be configured with your Livepeer Studio account's API key, which is available in the Studio Dashboard

import Livepeer from "livepeer";

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

const streams = await livepeer.stream.getAll;

console.log(stream.length);

Configuration

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the serverURL: str optional parameter when initializing the SDK client instance. For example:

import { Livepeer } from "livepeer";

const livepeer = new Livepeer({
  serverURL: "https://livepeer.studio/api",
  apiKey: "",
});

const res = await sdk.stream.getAll();

if (res.statusCode == 200) {
  // handle response
}

Custom HTTP Client

The Typescript SDK makes API calls using the (axios)[https://axios-http.com/docs/intro] HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance object.

For example, you could specify a header for every request that your sdk makes as follows:

import { Livepeer } from "livepeer";
import axios from "axios";

const httpClient = axios.create({
  headers: { "x-custom-header": "someValue" },
});

const livepeer = new Livepeer({ defaultClient: httpClient });

Available Resources and Operations

stream

multistreamTarget

  • getAll - Retrieve Multistream Targets
  • create - Create a multistream target
  • delete - Delete a multistream target
  • get - Retrieve a multistream target
  • update - Update Multistream Target

webhook

asset

metrics

session

accessControl

task

  • getAll - Retrieve Tasks
  • get - Retrieve a Task

transcode

playback

  • get - Retrieve Playback Info

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Error type.

Error Object Status Code Content Type
errors.ErrorT 404 application/json
errors.SDKError 400-600 /

Example

import { Livepeer } from "livepeer";
import { GetPlaybackInfoRequest } from "livepeer/dist/models/operations";

(async() => {
  const sdk = new Livepeer({
    apiKey: "",
  });
const id: string = "string";

  
  let res;
  try {
    res = await sdk.playback.get(id);
  } catch (e) { 
    if (e instanceof errors.ErrorT) {
      console.error(e) // handle exception 
    
  }

  if (res.statusCode == 200) {
    // handle response
  }
})();

Server Selection

Select Server by Index

You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables
0 https://livepeer.studio/api None

Example

import { Livepeer } from "livepeer";

(async () => {
    const sdk = new Livepeer({
        serverIdx: 0,
        apiKey: "",
    });

    const res = await sdk.getAll();

    if (res.statusCode == 200) {
        // handle response
    }
})();

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the serverURL: str optional parameter when initializing the SDK client instance. For example:

import { Livepeer } from "livepeer";

(async () => {
    const sdk = new Livepeer({
        serverURL: "https://livepeer.studio/api",
        apiKey: "",
    });

    const res = await sdk.getAll();

    if (res.statusCode == 200) {
        // handle response
    }
})();

Custom HTTP Client

The Typescript SDK makes API calls using the (axios)[https://axios-http.com/docs/intro] HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom AxiosInstance object.

For example, you could specify a header for every request that your sdk makes as follows:

from livepeer import Livepeer;
import axios;

const httpClient = axios.create({
    headers: {'x-custom-header': 'someValue'}
})

const sdk = new Livepeer({defaultClient: httpClient});

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
apiKey http HTTP Bearer

To authenticate with the API the apiKey parameter must be set when initializing the SDK client instance. For example:

import { Livepeer } from "livepeer";

(async () => {
    const sdk = new Livepeer({
        apiKey: "",
    });

    const res = await sdk.getAll();

    if (res.statusCode == 200) {
        // handle response
    }
})();

Readme

Keywords

none

Package Sidebar

Install

npm i livepeer

Weekly Downloads

1,832

Version

3.0.2

License

none

Unpacked Size

1.45 MB

Total Files

473

Last publish

Collaborators

  • clacladev
  • chase-adams
  • ericxtang
  • victorges
  • iameli
  • ads1018
  • suhailkakar