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)
})
Method
Returns
Description
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()
boolean
If true, next() will return a new page of data. If false, no next page exists.
Authentication API
Resource Owner Password Credentials Flow
let ustream =newUstream({
type:'password',
username:'...',
password:'...',
client_id:'...',
client_secret:'...',
token_type:"..."// Optional, default is bearer
})
Client Credentials Flow
let ustream =newUstream({
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 =newUstream({
type:'oauth_token',
access_token:'...',
token_type:'bearer',
expires_in:86400
})
Oauth Authorization Code Authentication Flow
let ustream =newUstream({
type:'oauth_code',
client_id:'...',
client_secret:'...',
code:'...',
redirect_uri:'...'
})
Password Credentials Flow for Analytics API
let ustream =newUstream({
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.
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)
Parameter
Type
Description
channelId
int
ID of an existing channel.
file.originalname
string
Name of file.
file.stream
ReadStream
File stream.
opts.title
string
Title of video.
opts.description
string
Description 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)
Parameter
Type
Description
channelId
int
ID of an existing channel.
videoId
int
ID of an existing video.
List Videos
ustream.video.list(channelId, pageSize, page)
Promise returns a Pageable result. See "Paging Results" section for details.
Parameter
Type
Description
channelId
int
Id of a channel.
pageSize
int
(optional) Default: 100. The number of results to show per page.
page
int
(optional) Default: 1. The page to retrieve.
Get Video Details
ustream.video.get(videoId)
Parameter
Type
Description
videoId
int
ID of an existing video.
Delete Video
ustream.video.remove(videoId)
Parameter
Type
Description
videoId
int
ID of an existing video.
Channel API
Get Channel
ustream.channel.get(channelId, opts)
Parameter
Type
Description
channelId
int
ID of an existing channel.
opts.detail_level
string
Default 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)
Parameter
Type
Description
title
string
Channel title.
opts.description
string
Description of channel.
Edit Channel
ustream.channel.edit(channelId, title, opts)
Parameter
Type
Description
channelId
int
ID of an existing channel.
title
string
Title of channel.
opts.description
string
Description of channel.
opts.tags
string
Comma delimited list of channel tags
Delete Channel
ustream.channel.remove(channelId)
Parameter
Type
Description
channelId
int
ID of an existing channel.
List Channels
ustream.channel.list(pageSize, page)
Promise returns a Pageable result. See "Paging Results" section for details.
Parameter
Type
Description
pageSize
int
(optional) Default: 100. The number of results to show per page.