1.12.0 • Published 4 years ago

ustream-sdk v1.12.0

Weekly downloads
253
License
MIT
Repository
github
Last release
4 years ago

Ustream JavaScript SDK

npm version

JavaScript wrapper for Ustream's REST API.

Installation

NPM

npm install ustream-sdk

Yarn

yarn add ustream-sdk

Basic Usage

All methods that access API resources, such as ustream.video.* or ustream.channel.* will return a Promise.

let Ustream = require('ustream-sdk')

// Set up instance using password authentication
let ustream = new Ustream({
    username: "...",
    password: "...",
    client_id: "...",
    client_secret: "...",
    token_type: "...", // Optional, default is bearer
    type: "password"
})

ustream.video.get(videoId).then((video) => {
    // Use video
}).catch((err) => {
    // Handle error
})

Paging Results

Some methods return data that is divided into many pages. These methods will return an object with helper methods to allow for easy access to both your data and next pages.

// Get list of channels
ustream.channel.list().then((pageableResult) => {
    // Access the list of channels
    let channels = pageableResult.data
    
    // Check if result set has a next page
    if (pageableResult.hasNextPage()) {
        // Retrieve the next page of channels
        pageableResult.next().then((nextPageResults) => {
            // Use next page's results
        })
    }
}).catch((err) => {
    console.warn(err)
})
MethodReturnsDescription
next()Promise<PageableResult>Retrieves the next page of results. Returns null if a next page does not exist.
data()array<Object>Returns the data for a given page.
hasNextPage()booleanIf true, next() will return a new page of data. If false, no next page exists.

Authentication API

Resource Owner Password Credentials Flow

let ustream = new Ustream({
    type: 'password',
    username: '...',
    password: '...',
    client_id: '...',
    client_secret: '...',
    token_type: "..." // Optional, default is bearer
})

Client Credentials Flow

let ustream = new Ustream({
    type: 'client_credentials',
    device_name: '...',
    scope: '...', // "broadcaster" or empty
    client_id: '...',
    client_secret: '...',
    token_type: "..." // Optional, default is bearer
})

Oauth Implicit Authentication Flow

let ustream = new Ustream({
  type: 'oauth_token',
  access_token: '...',
  token_type: 'bearer',
  expires_in: 86400
})

Oauth Authorization Code Authentication Flow

let ustream = new Ustream({
  type: 'oauth_code',
  client_id: '...',
  client_secret: '...',
  code: '...',
  redirect_uri: '...'
})

Password Credentials Flow for Analytics API

let ustream = new Ustream({
    type: 'password',
    username: '...',
    password: '...',
    client_id: '...',
    client_secret: '...',
    token_type: "jwt",
    endpoint: 'https://analytics-api.video.ibm.com',
    version: 'v1'
})

Note: The Analytics API uses only the jwt token type with a different API endpoint, and the targetted version is required.

Oauth Demo App

View Demo

Changing Authentication Credentials Workflow

If you choose to change your authentication workflow or swap out credentials after initializing Ustream, you can utilize the setAuthCredentials method.

ustream.setAuthCredentials({
    type: "<new authentication workflow>",
    ...
})

Video API

Upload Video

ustream.video.upload(channelId, file, opts)
ParameterTypeDescription
channelIdintID of an existing channel.
file.originalnamestringName of file.
file.streamReadStreamFile stream.
opts.titlestringTitle of video.
opts.descriptionstringDescription of video.
opts.protect"public" "private"Default is "private". If set to true, video will be published upon end of upload.

Video Upload Status

ustream.video.getStatus(channelId, videoId)
ParameterTypeDescription
channelIdintID of an existing channel.
videoIdintID of an existing video.

List Videos

ustream.video.list(channelId, pageSize, page)

Promise returns a Pageable result. See "Paging Results" section for details.

ParameterTypeDescription
channelIdintId of a channel.
pageSizeint(optional) Default: 100. The number of results to show per page.
pageint(optional) Default: 1. The page to retrieve.

Get Video Details

ustream.video.get(videoId)
ParameterTypeDescription
videoIdintID of an existing video.

Delete Video

ustream.video.remove(videoId)
ParameterTypeDescription
videoIdintID of an existing video.

Channel API

Get Channel

ustream.channel.get(channelId, opts)
ParameterTypeDescription
channelIdintID of an existing channel.
opts.detail_levelstringDefault is null. If set to "minimal", the result set is limited to id, title, picture, owner and locks data. If the channel is protected, only minimal data can be retrieved without valid access token.

Create Channel

ustream.channel.create(channelId, opts)
ParameterTypeDescription
titlestringChannel title.
opts.descriptionstringDescription of channel.

Edit Channel

ustream.channel.edit(channelId, title, opts)
ParameterTypeDescription
channelIdintID of an existing channel.
titlestringTitle of channel.
opts.descriptionstringDescription of channel.
opts.tagsstringComma delimited list of channel tags

Delete Channel

ustream.channel.remove(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

List Channels

ustream.channel.list(pageSize, page)

Promise returns a Pageable result. See "Paging Results" section for details.

ParameterTypeDescription
pageSizeint(optional) Default: 100. The number of results to show per page.
pageint(optional) Default: 1. The page to retrieve.

Check Password Protection Status

ustream.channel.getPasswordProtectionStatus(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

Enable Password Protection

ustream.channel.enablePasswordProtection(channelId, password)
ParameterTypeDescription
channelIdintID of an existing channel.
passwordstringThe password used to access the channel.

Disable Password Protection

ustream.channel.disablePasswordProtection(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

Get Embed Lock Status

ustream.channel.getEmbedLockStatus(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

Edit Embed Lock Status

ustream.channel.setEmbedLock(channelId, isEmbedLocked)
ParameterTypeDescription
channelIdintID of an existing channel.
isEmbedLockedbooleanDefault is false. True to enable restricted embed access. False to disable.

Get Whitelisted URLs

ustream.channel.getUrlWhiteList(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

Add URL to Whitelist

ustream.channel.addUrlToWhiteList(channelId, url)
ParameterTypeDescription
channelIdintID of an existing channel.
urlstringURL to whitelisted domain.

Remove URLs from Whitelist

The API currently does not support removing a single URL from the whitelist. All URLs must be removed, then added.

ustream.channel.emptyUrlWhiteList(channelId, url)
ParameterTypeDescription
channelIdintID of an existing channel.
urlstringURL to whitelisted domain.

Sharing Control

ustream.channel.setSharingControl(channelId, canShare)
ParameterTypeDescription
channelIdintID of an existing channel.
canSharebooleanIf true, users will be able to share a channel's content.

Change Branding Type

ustream.channel.setBrandingType(channelId, type)
ParameterTypeDescription
channelIdintID of an existing channel.
typestringThe branding type.

Playlist API

Is Enabled

You can check whether playlists are enabled or disabled on the channel page.

ustream.isEnabled(channelId)
ParameterTypeDescription
channelIdintID of an existing channel.

Promise returns a boolean result stating if playlists are enabled for the channel or not.

List Playlists

Allows for the retrieval of the list of the playlists in the channel.

ustream.playlist.list(channelId, pageSize, page, includeEmptyLists)
ParameterTypeDescription
channelIdintID of an existing channel.
pageSizeintHow many entries to return in one request. Default is 50 and max is 50.
pageintStarting page number. Default is 1.
includeEmptyListsbooleanIf the value is true then empty playlists will be returned (false by default).

Promise returns a Pageable result. See "Paging Results" section for details.

List Videos in Playlist

This service retrieves a list of videos that are in a specific playlist.

ustream.playlist.listVideos(playlistId, pageSize, page)
ParameterTypeDescription
playlistIdintID of an existing playlist.
pageSizeintHow many entries to return in one request. Default is 200 and max is 200.
pageintStarting page number. Default is 1.

Promise returns a Pageable result. See "Paging Results" section for details.

Create Playlist

Create a new playlist in the channel.

ustream.playlist.create(channelId, title, options)
ParameterTypeDescription
channelIdintID of an existing channel.
titlestringThe title of the playlist.
isEnabledintWhether the playlist is enabled or not. Possible values are 1 (enabled), 0 (disabled). The default is 1 (enabled).

Get Playlist Details

This entry point retrieves the details of a playlist.

ustream.playlist.get(playlistId)
ParameterTypeDescription
playlistIdintID of an existing playlist.

Add Video to Playlist

Add an already uploaded video in the channel to the playlist.

ustream.playlist.addVideo(playlistId)
ParameterTypeDescription
playlistIdintID of an existing playlist.
videoIdintID of an existing video.

Delete Playlist

Remove a playlist from a channel.

ustream.playlist.remove(channelId)
ParameterTypeDescription
playlistIdintID of an existing playlist.

Todo

  • Authentication
    • Oauth implicit flow
    • Oauth authorization code flow
  • Device passwords
    • Get device passwords
    • Create device password
    • Delete device password
  • Playlists
    • List the user's playlists
    • Create a playlist
    • Playlist details
    • Modify a playlist
    • Delete a playlist
    • Playlist videos
    • Playlist video
    • Channel playlists
  • Video (new endpoints)
    • Download video
    • Set up viewer authentication
    • Video expiration
    • Video thumbnail
    • Video labels
      • List all labels
      • Create label
      • Modify label
      • Delete label
      • List a video's labels
      • Add labels to video
      • Remove label from video
      • Edit video details
    • Video metadata
      • List all video metadata values
      • Set video metadata value
      • Remove video metadata value
    • Video caption
      • List captions
      • Show caption details
      • Modify caption details
      • Download captions
      • Upload captions
      • List supported caption languages
    • Video trim
    • Video copy
      • Check copy status
    • Video chapters
  • Channel
    • List featured videos
    • Update featured videos
    • Get channel managers
    • Set up viewer authentication
    • Channel metadata
      • List metadata values
      • set metadata value
      • remove metadata value
      • List metadata display settings
      • set metadata display setting
      • remove metadata display setting
    • Recording broadcasts
      • Get recording status
      • Start recording
      • Stop recording
      • Auto-record
      • Get record time limit
  • Stream settings
    • Multi quality streaming
  • Custom metadata
    • List metadata fields
    • Create new metadata field
    • Delete metadata field
  • Ingest settings
    • Get ingest settings
  • User
    • List channels
    • List videos
    • Create label
    • Update label
    • List labels
    • Delete label
  • Analytics
    • List of unique viewers for all contents
    • List of unique viewers for a specific content type
    • Raw view export for a given time period
    • Raw view export for a specific content type for a given time period
    • [] Sum total view number for a given period for all contents
    • [] Sum total view number for a given period and a specific content type
    • [] Number of sum unique devices for a given period and all contents
    • [] Number of sum unique devices for a given period and a specific content type
    • ...
  • Other
    • Improve test coverage

Testing

All tests are located in the /test directory. To execute the testing suite, or check for style guide violations, run the following command.

npm run test

Issues and Contributing

Have a feature request or bug report? Create an entry in the issue tracker, and include as much detail as possible. I usually reply within 12 hours.

Code contributions must adhere to the contribution guidelines.

1.12.0

4 years ago

1.11.1

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.0.2

7 years ago

1.0.0

7 years ago