Skip to content

Commit

Permalink
修改默认配置
Browse files Browse the repository at this point in the history
  • Loading branch information
谢庭 authored and 谢庭 committed Jul 13, 2017
1 parent 08f8c00 commit 89fe1f5
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 44 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added dist/.DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions dist/pear-player.min.js

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ var PearPlayer = require('PearPlayer');
algorithm: 'firstaid', //核心算法,默认firstaid
autoplay: true, //是否自动播放视频,默认true
interval: 5000, //滑动窗口的时间间隔,单位毫秒,默认10s
auto: false, //true为连续下载buffer,false则是只有当前播放时间与已缓冲时间小于slideInterval时下载buffer,如果是fmp4建议设为true,默认false
auto: false, //true为连续下载buffer,false则是只有当前播放时间与已缓冲时间小于slideInterval时下载buffer,默认true
slideInterval: 15, //当前播放时间与已缓冲时间小于这个数值时触发窗口滑动,单位秒,默认20s
useDataChannel: true, //是否开启data channel,默认true
dataChannels: 4, //创建data channel的最大数量,默认3
useMonitor: true //是否开启monitor,会稍微影响性能,默认true,只有开启useMonitor才能监听事件
useMonitor: true //是否开启monitor,会稍微影响性能,默认false,只有开启useMonitor才能监听事件
}
```

Expand All @@ -61,29 +61,33 @@ var PearPlayer = require('PearPlayer');

## `player.on('progress', function (downloaded) {})`

通过该事件可以监听PearPlayer的下载进度(下载的字节数除以总的字节数)。
通过该事件可以监听PearPlayer的下载进度(下载的字节数除以总的字节数)。(useMonitor需设为true)

## `player.on('cloudspeed', function (speed) {})`

通过该事件可以监听cloud(即server节点)的平均下载速度(单位KB/s)。
通过该事件可以监听cloud(即server节点)的平均下载速度(单位KB/s)。(useMonitor需设为true)

## `player.on('fogspeed', function (speed) {})`

通过该事件可以监听fog节点(包括WebRTC和HTTP)的平均下载速度(单位KB/s)。
通过该事件可以监听fog节点(包括WebRTC和HTTP)的平均下载速度(单位KB/s)。(useMonitor需设为true)

## `player.on('fograte', function (p2pRate) {})`

通过该事件可以监听fog节点(包括WebRTC和HTTP)总的下载比率(fog下载的字节数除以目前总的下载字节数)。
通过该事件可以监听fog节点(包括WebRTC和HTTP)总的下载比率(fog下载的字节数除以目前总的下载字节数)。(useMonitor需设为true)

## `player.on('buffersources', function (bufferSources) {})`

每下载一个buffer都会触发该事件,bufferSources是一个bitmap,每个元素代表该buffer是从哪个源下载的,有以下几种取值:<br/>
每下载一个buffer都会触发该事件,bufferSources是一个bitmap,每个元素代表该buffer是从哪个源下载的,有以下几种取值:(useMonitor需设为true)<br/>
null: 该处的buffer还未下载<br/>
s: server,从服务器端下载(HTTP协议)<br/>
n: node,从节点下载(HTTP协议)<br/>
d: data channel,从节点下载(WebRTC协议)<br/>
b: browser,从其它浏览器下载(WebRTC协议)<br/>

## `player.on('traffic', function (mac, downloaded, type) {})`
通过该事件可以监听每个节点的实时流量,其中mac是节点的mac地址,downloaded是对应节点的下载流量(字节),type是
节点的类型(http、datachannel等)。(useMonitor需设为true)

## `player.on('exception', onException)`

当PearPlayer内部发生异常时会触发该事件,通过回调函数中的exception可以获取errCode和对应的errMsg:
Expand Down
17 changes: 1 addition & 16 deletions docs/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,12 @@ There is a complete example in [examples/test.html](examples/test.html)。
var player = new PearPlayer('#pearvideo', token, { //第一个参数为video标签的id或class
type: 'mp4', //播放视频的类型,目前只能是mp4
src: 'https://qq.webrtc.win/tv/pear001.mp4', //视频播放的src
useMonitor: true //是否开启monitor,会稍微影响性能,默认true
useMonitor: true //是否开启monitor,会稍微影响性能,默认false
});

player.on('exception', onException);
player.on('begin', onBegin);
player.on('progress', onProgress);
player.on('cloudspeed', onCloudSpeed);
player.on('fogspeed', onFogSpeed);
player.on('fograte', onWebRTCRate);
player.on('buffersources', onBufferSources); //s: server n: node d: data channel b: browser
player.on('done', onDone);

Expand All @@ -90,18 +87,6 @@ function onProgress(downloaded) {
console.log('Progress: ' + (downloaded * 100).toFixed(1) + '%');
}

function onCloudSpeed(speed) {
console.log('Cloud download speed: ' + speed + 'KBps');
}

function onFogSpeed(speed) {
console.log('Fog download speed: ' + speed + 'KBps');
}

function onWebRTCRate(p2pRate) {
console.log('Fog Rate: ' + (p2pRate * 100).toFixed(1) + '%');
}

function onDone() {
console.log('finished downloading buffer by first aid');
}
Expand Down
6 changes: 3 additions & 3 deletions examples/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
algorithm: 'firstaid', //核心算法,默认firstaid
autoplay: true, //是否自动播发视频,默认true
interval: 5000, //滑动窗口的时间间隔,单位毫秒,默认10s
auto: false, //true为连续下载buffer,false则是只有当前播放时间与已缓冲时间小于slideInterval时下载buffer,如果是fmp4建议设为true,默认false
auto: false, //true为连续下载buffer,false则是只有当前播放时间与已缓冲时间小于slideInterval时下载buffer,默认true
slideInterval: 15, //当前播放时间与已缓冲时间小于这个数值时触发窗口滑动,单位秒,默认20s
useDataChannel: true, //是否开启data channel,默认true
dataChannels: 2, //创建data channel的最大数量,默认2
useMonitor: true //是否开启monitor,会稍微影响性能,默认true
dataChannels: 1, //创建data channel的最大数量,默认2
useMonitor: true //是否开启monitor,会稍微影响性能,默认false
});

player.on('exception', onException); //播放器出现异常时的回调函数
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function PearPlayer(selector,token, opts) {
self.urlObj = url.parse(self.src);
self.token = token;
self.useDataChannel = (opts.useDataChannel === false)? false : true;
self.useMonitor = (opts.useMonitor === false)? false : true;
self.useMonitor = (opts.useMonitor === true)? true : false;
self.autoPlay = (opts.autoplay === false)? false : true;
self.params = opts.params || {};
self.dataChannels = opts.dataChannels || 2;
Expand Down
3 changes: 1 addition & 2 deletions lib/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Dispatcher(config) {
self.pieceLength = config.chunkSize || 1*1024*1024;
self.interval = config.interval || 10000;
self._slideInterval = config.slideInterval || 20;
self.auto = config.auto || false;
self.auto = config.auto || true;
self.useMonitor = config.useMonitor || false;
self.downloaded = 0;
self.fogDownloaded = 0; //通过data channel下载的字节数
Expand Down Expand Up @@ -492,7 +492,6 @@ Dispatcher.prototype.addDataChannel = function (dc) { //TODO:让每个
this._setupDC(dc);
console.log('addDataChannel now:'+this.downloaders.length);
for (var i=0;i<this.downloaders.length;++i) {
console.log('666');
console.log('downloader type:'+this.downloaders[i].type);
}
};
Expand Down
14 changes: 14 additions & 0 deletions lib/simple-RTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,23 @@ SimpleRTC.prototype.close = function () {

if (this.peerConnection){
this.peerConnection.close();
clearInterval(this.timer);
}
};

SimpleRTC.prototype.startHeartbeat = function () {
var self = this;
var heartbeat = {
action: 'ping'
};

this.timer = setInterval(function () {
console.log(JSON.stringify(heartbeat));
self.send(JSON.stringify(heartbeat));

}, 30*1000);
};


function getBrowserRTC () {
if (typeof window === 'undefined') return null;
Expand Down
8 changes: 5 additions & 3 deletions lib/webrtc-downloader-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ RTCDownloader.prototype._receive = function (chunk) {
// }

var headerInfo = self._getHeaderInfo(uint8);
// console.log('headerInfo:'+JSON.stringify(headerInfo));
console.log('headerInfo:'+JSON.stringify(headerInfo));
if (headerInfo) {

if (headerInfo.value){
Expand Down Expand Up @@ -152,10 +152,12 @@ RTCDownloader.prototype._receive = function (chunk) {
}

self.emit('data',Buffer.concat(finalArray), self.start, self.end, self.speed);
if (self.queue.length>0){ //如果下载队列不为空
if (self.queue.length>0) { //如果下载队列不为空
var pair = self.queue.shift();
self.startDownloading(pair[0], pair[1]);
}
} else if (headerInfo.action) {
//心跳信息
} else {
console.log('RTC error msg:'+JSON.stringify(headerInfo));
self.emit('error');
Expand Down Expand Up @@ -226,7 +228,7 @@ RTCDownloader.prototype._setupSimpleRTC = function (simpleRTC) {
simpleRTC.on('connect', function (state) {
console.log('[datachannel] '+self.dc_id+' CONNECT');
// simpleRTC.send('[simpleRTC] PEER CONNECTED!');

simpleRTC.startHeartbeat(); //开始周期性发送心跳信息
if (!self.connectFlag){
self.emit('connect',state);
self.connectFlag = true;
Expand Down
26 changes: 21 additions & 5 deletions pear-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function PearPlayer(selector,token, opts) {
self.urlObj = url.parse(self.src);
self.token = token;
self.useDataChannel = (opts.useDataChannel === false)? false : true;
self.useMonitor = (opts.useMonitor === false)? false : true;
self.useMonitor = (opts.useMonitor === true)? true : false;
self.autoPlay = (opts.autoplay === false)? false : true;
self.params = opts.params || {};
self.dataChannels = opts.dataChannels || 2;
Expand Down Expand Up @@ -443,7 +443,7 @@ function Dispatcher(config) {
self.pieceLength = config.chunkSize || 1*1024*1024;
self.interval = config.interval || 10000;
self._slideInterval = config.slideInterval || 20;
self.auto = config.auto || false;
self.auto = config.auto || true;
self.useMonitor = config.useMonitor || false;
self.downloaded = 0;
self.fogDownloaded = 0; //通过data channel下载的字节数
Expand Down Expand Up @@ -1790,9 +1790,23 @@ SimpleRTC.prototype.close = function () {

if (this.peerConnection){
this.peerConnection.close();
clearInterval(this.timer);
}
};

SimpleRTC.prototype.startHeartbeat = function () {
var self = this;
var heartbeat = {
action: 'ping'
};

this.timer = setInterval(function () {
console.log(JSON.stringify(heartbeat));
self.send(JSON.stringify(heartbeat));

}, 30*1000);
};


function getBrowserRTC () {
if (typeof window === 'undefined') return null;
Expand Down Expand Up @@ -1925,7 +1939,7 @@ RTCDownloader.prototype._receive = function (chunk) {
// }

var headerInfo = self._getHeaderInfo(uint8);
// console.log('headerInfo:'+JSON.stringify(headerInfo));
console.log('headerInfo:'+JSON.stringify(headerInfo));
if (headerInfo) {

if (headerInfo.value){
Expand Down Expand Up @@ -1965,10 +1979,12 @@ RTCDownloader.prototype._receive = function (chunk) {
}

self.emit('data',Buffer.concat(finalArray), self.start, self.end, self.speed);
if (self.queue.length>0){ //如果下载队列不为空
if (self.queue.length>0) { //如果下载队列不为空
var pair = self.queue.shift();
self.startDownloading(pair[0], pair[1]);
}
} else if (headerInfo.action) {
//心跳信息
} else {
console.log('RTC error msg:'+JSON.stringify(headerInfo));
self.emit('error');
Expand Down Expand Up @@ -2039,7 +2055,7 @@ RTCDownloader.prototype._setupSimpleRTC = function (simpleRTC) {
simpleRTC.on('connect', function (state) {
console.log('[datachannel] '+self.dc_id+' CONNECT');
// simpleRTC.send('[simpleRTC] PEER CONNECTED!');

simpleRTC.startHeartbeat(); //开始周期性发送心跳信息
if (!self.connectFlag){
self.emit('connect',state);
self.connectFlag = true;
Expand Down

0 comments on commit 89fe1f5

Please sign in to comment.