npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

piliv2

v2.1.1

Published

Pili Streaming Cloud Server-Side Library For NodeJS

Downloads

180

Readme

Table of Contents generated with DocToc

Pili Streaming Cloud server-side library for NodeJS

Features

  • URL
    • [x] RTMP推流地址: RTMPPublishURL(domain, hub, streamKey, mac, expireAfterSeconds)
    • [x] RTMP直播地址: RTMPPlayURL(domain, hub, streamKey)
    • [x] HLS直播地址: HLSPlayURL(domain, hub, streamKey)
    • [x] HDL直播地址: HDLPlayURL(domain, hub, streamKey)
    • [x] 截图直播地址: SnapshotPlayURL(domain, hub, streamKey)
  • Hub
    • [x] 创建流: hub.Create(streamKey)
    • [x] 获得流: hub.Stream(streamKey)
    • [x] 列出流: hub.List(prefix, limit, marker)
    • [x] 列出正在直播的流: hub.ListLive(prefix, limit, marker)
    • [x] 批量查询直播实时信息: hub.batchLiveStreamsInfo(items)
  • Stream
    • [x] 流信息: stream.Info()
    • [x] 禁用流: stream.Disable()
    • [x] 启用流: stream.Enable()
    • [x] 查询直播状态: stream.LiveStatus()
    • [x] 保存直播回放: stream.Save(start, end)
    • [x] 查询直播历史: stream.HistoryActivity(start, end)
    • [x] 保存直播截图: stream.saveSnapshot()
    • [x] 修改流转码配置: stream.updateConverts(profiles)

Installaion

// install latest version
npm install piliv2 --save

Usage

Configuration

var Pili = require('piliv2');

var ACCESS_KEY  = 'QiniuAccessKey';
var SECRET_KEY  = 'QiniuSecretKey';

var HUB = 'PiliHubName'; // The Hub must be exists before use

var credentials = new Pili.Credentials(ACCESS_KEY, SECRET_KEY);

URL

Generate RTMP publish URL

var url = Pili.publishURL(credentials,'publish-rtmp.test.com', 'PiliSDKTest', 'streamkey', 60);
console.log(url);
// rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1466652726&token=9roGzeeJkZh4y5gHpzT7Uv1CIw0KiVV8K4dfXRY0:bYZGIdK-tjjAfyIwbShQ5Bb1kBY=

Generate RTMP play URL

var url = Pili.rtmpPlayURL('live-rtmp.test.com', 'PiliSDKTest', 'streamkey');
console.log(url);
// rtmp://live-rtmp.test.com/PiliSDKTest/streamkey

Generate HLS play URL

var url = Pili.hlsPlayURL('live-rtmp.test.com', 'PiliSDKTest', 'streamkey');
console.log(url);
// http://live-rtmp.test.com/PiliSDKTest/streamkey.m3u8

Generate HDL play URL

var url = Pili.hdlPlayURL('live-rtmp.test.com', 'PiliSDKTest', 'streamkey');
console.log(url);
// http://live-rtmp.test.com/PiliSDKTest/streamkey.flv

Generate Snapshot play URL

var url = Pili.snapshotPlayURL('live-rtmp.test.com', 'PiliSDKTest', 'streamkey');
console.log(url);
// http://live-rtmp.test.com/PiliSDKTest/streamkey.jpg

Hub

Instantiate a Pili Hub object

var hub = new Pili.Hub(credentials, HUB);

Create a new Stream

hub.createStream(streamKey, function(err, stream) {

  if (!err) {
      console.log(stream);
  } else {
    // Log error
    console.log(err, err.errorCode, err.httpCode);
  }
});

Get a Stream

var stream = hub.newStream(streamKey);

stream.loadInfo(function(err) {
	if (!err) {
		console.log(stream);
	} else {
		console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
	}
})

LiveInfo

stream.liveInfo(function(err, status) {
    if (!err) {
			console.log(status);
		} else {
			console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
		}
});

List Stream

var listOptions = {
	'liveonly': false,
	'prefix': '',
	'limit': 2,
};

var listCallBack = function(err, marker, streams) {
	if (!err) {
		streams.forEach(function(stream) {
			console.log(stream);
		});
		if (marker) {
			listOptions.marker = marker;
			hub.listStreams(listOptions, listCallBack);
		}
	} else {
		 console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
	}
}

hub.listStreams(listOptions, listCallBack);

Get Streams live status

hub.batchLiveStreamsInfo([streamKey], function (err, items) {
    if (!err) {
        console.log('live streams: ');
        items.forEach(function(item) {
            console.log(item);
        });
    }
    else {
        console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
    }
});

Stream

Disable a Stream

stream.disable(-1, function(err) {
    console.log(stream.disabledTill);
});

Enable a Stream

stream.enable(function(err) {
    console.log(stream.disabledTill);
});

Get Stream live status

stream.liveInfo(function(err, status) {
    if (!err) {
			console.log(status);
		} else {
			console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
		}
});

Get Stream history activity

var publishHistoryOptions = {
   start : null,    // optional, in second, unix timestamp
   end   : null,    // optional, in second, unix timestamp
};
stream.publishHistory(publishHistoryOptions, function(err, history) {
	if (!err) {
		console.log(history);
	} else {
			console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
	}
})

Save Stream live playback

var savePlaybackOptions = {
   start : null,    // optional, in second, unix timestamp
   end   : null,    // optional, in second, unix timestamp
   format: null,    // optional, file format
};

stream.savePlayback(savePlaybackOptions, function(err, m3u8Name) {

    if (!err) {
			console.log(m3u8Name);
		} else {
			console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
		}
});

Save Stream snapshot

var saveSnapshotOptions = {
    fname: streamKey    // optional, file name
};

stream.saveSnapshot(saveSnapshotOptions, function(err, snapshotName) {
    if (!err) {
        console.log(snapshotName);
    } else {
        console.log(err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
    }
});

Update Stream converts

stream.updateConverts(['480p', '720p'], function (err) {
    if (!err) {
        console.log('update converts success');
    }
    else {
        console.log('update converts error: ' + err + 'error code: ' + err.errorCode + 'http code: ' + err.httpCode);
    }
})