1 Star 1 Fork 73

fnet / PearDownloader.js

forked from Pear / PearDownloader.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
get-started.md 2.74 KB
一键复制 编辑 原始数据 按行查看 历史
谢庭 提交于 2017-11-11 13:35 . update

Get Started with PearDownloader

PearDownloader is a multi-source and multi-protocol P2P streaming downloader that works in the browser. It's easy to get started!

Import

Script

Simply include the (pear-downloader.min.js) script on your page:

<script src="pear-downloader.min.js"></script>

Browserify

To install PearPlayer for use in the browser with require('PearDownloader'), run:

npm install peardownloader --save

Then you can require PearDownloader like this:

var PearDownloader = require('PearDownloader');

Quick Examples

input url and download

var PearDownloader = require('PearDownloader');
var downloader = new PearDownloader(url);

There is a complete example in examples/downloader-test.html

Listen to PearDownloader events

var downloader = new PearDownloader(url, {      //第一个参数为url
                    useMonitor: true             //是否开启monitor,会稍微影响性能,默认false
                });

downloader.on('exception', onException);
downloader.on('begin', onBegin);
downloader.on('progress', onProgress);
downloader.on('sourcemap', onSourceMap);        
downloader.on('done', onDone);
                
function onBegin(fileLength, chunks) {
    console.log('start downloading buffer by first aid, file length is:' + fileLength + ' total chunks:' + chunks);
}

function onProgress(downloaded) {
    console.log('Progress: ' + (downloaded * 100).toFixed(1) + '%');
}

function onDone() {
    console.log('finished downloading buffer by first aid');
}

function onException(exception) {
    var errCode = exception.errCode;
    switch (errCode) {
        case 1:                   //当前浏览器不支持WebRTC
        console.log(exception.errMsg);
            break
    }
}
function onSourceMap(sourceType, index) {
        console.log('Received source type:' + sourceType + ' index:' + index);
    }

Build

PearDownloader works great with browserify, which lets you use node.js style require() to organize your browser code, and load packages installed by npm.

npm install -g browserify

Install dependencies:

npm install

To get a normal size bundle,use:

npm run build-downloader

To get a compressed bundle,use:

npm run uglify-downloader

More Documentation

Check out the API Documentation and FAQ for more details.

JavaScript
1
https://gitee.com/fnet/PearDownloader.js.git
git@gitee.com:fnet/PearDownloader.js.git
fnet
PearDownloader.js
PearDownloader.js
master

搜索帮助