Pili Streaming Cloud server-side library for NodeJS
Features
- Stream Create, Get, List
- Stream operations else
Content
Installaion
// install latest version
npm install pili --save
Usage
Configuration
var Pili = require('pili');
var ACCESS_KEY = 'QiniuAccessKey';
var SECRET_KEY = 'QiniuSecretKey';
var HUB = 'PiliHubName';
Hub
Instantiate a Pili Hub object
var credentials = new Pili.Credentials(ACCESS_KEY, SECRET_KEY);
var hub = new Pili.Hub(credentials, HUB);
Create a new Stream
var options = {
title : null,
publishKey : null,
publishSecurity : "static"
};
hub.createStream(options, function(err, stream) {
if (!err) {
console.log(stream);
} else {
console.log(err + 'error code: ' + err.errorCode + 'http code: ' err.httpCode);
}
});
Get a Stream
var streamId = 'z1.coding.35d7zfabe3bv5723280200c5';
hub.getStream(streamId, function(err, stream) {
if (!err) {
console.log(stream);
}
});
List Stream
var options = {
marker : null,
limit : null,
title : null
};
hub.listStreams(options, function(err, marker, streams) {
streams.forEach(function(stream) {
console.log(stream);
});
});
Stream
To JSON String
var result = stream.toJSONString();
console.log(result);
Update a Stream
var options = {
publishKey : 'new_secret_words',
publishSecrity : 'static',
disabled : false
};
stream.update(options, function(err, stream) {
console.log(stream);
});
Disable a Stream
stream.disable(function(err, stream) {
console.log(stream.disabled);
});
Enable a Stream
stream.enable(function(err, stream) {
console.log(stream.disabled);
});
Get Stream status
stream.status(function(err, status) {
if (!err) {
console.log(status);
}
});
Generate RTMP publish URL
var publishUrl = stream.rtmpPublishUrl();
console.log(publishUrl);
Generate RTMP live play URLs
var urls = stream.rtmpLiveUrls();
console.log(urls);
Generate HLS live play URLs
var urls = stream.hlsLiveUrls();
console.log(urls);
Generate Http-Flv live play URLs
var urls = stream.httpFlvLiveUrls();
console.log(urls);
Get Stream segments
var options = {
startTime : null,
endTime : null,
limit : null
};
stream.segments(options, function(err, segments) {
if (!err) {
console.log(segments);
}
});
Generate HLS playback URLs
var start = 1440196065;
var end = 1440196105;
var urls = stream.hlsPlaybackUrls(start, end);
console.log(urls);
Save Stream as a file
var name = 'videoName.mp4';
var start = 1440196065;
var end = 1440196105;
var format = 'mp4';
var options = {
notifyUrl : null,
pipeline : null
};
stream.saveAs(name, format, start, end, options, function(err, responseData) {
console.log(responseData);
});
While invoking saveAs()
and snapshot()
, you can get processing state via Qiniu FOP Service using persistentId
.
API: curl -D GET http://api.qiniu.com/status/get/prefop?id={PersistentId}
Doc reference: http://developer.qiniu.com/docs/v6/api/overview/fop/persistent-fop.html#pfop-status
Snapshot Stream
var name = 'imageName.jpg';
var format = 'jpg';
var options = {
time : 1440196100,
notifyUrl : null
};
stream.snapshot(name, format, options, function(err, responseData) {
console.log(responseData);
});
Delete a Stream
hub.deleteStream(streamId, function(err, data) {
console.log(data);
});
History
- 1.5.5
- fixed token url generate bug.
- 1.5.4
- 1.5.3
- Use saveAs in hlsPlaybackUrls, need async function
- 1.5.2
- Update
Stream
's hosts
- Add
startFrom
in Stream status
- 1.5.0
- Rename
Client
to Hub
- Add
Credentials
- 1.4.0
- Update stream struct
- Add stream.snapshot()
- Add stream.enable()
- Add stream.disable()
- Add stream.httpFlvLiveUrls()
- Update stream.status()
- Update stream.toJSONString()
- Update stream.segments()
- Update hub.listStreams()
- 1.2.1
- Add stream saveas function
- 1.2.0
- Update Stream object
- Add new Stream functions
- Update Client functions
- 1.0.7
- 1.0.6
- Fix GET request query method
- Add more defensive code to improve robustness
- 1.0.5
- Fix dynamic RTMP publish URL nonce generate bug
- 1.0.4
- Add server error handle
- Fix merge bugs
- 1.0.2
- Update client create function
- Update optional params
- Add
disabled
field in Stream
- Add
getStreamStatus
function in Client
- 1.0.1
- Update Stream publish and play url generate functions
- 1.0.0
- Init sdk
- Add Stream API
- Add publish and play policy