# hlsp2p **Repository Path**: jackchoon/hlsp2p ## Basic Information - **Project Name**: hlsp2p - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-12-19 - **Last Updated**: 2021-11-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # P2P fetcher ## 使用方法 > npm ```js //P2P服务参数 const videoId = '****'; const server = '/'; //功能参数 const timeout = 1500; const forceCDN = false; const cacheSize = 419430400; const debug = false; const trytimes = 5; const ioOpts = { transports: ['polling']//只用polling模式 }; const onreport = (byteLength, type) => { if (type === fetchSource.CDN) { console.log(`来自CDN的${byteLength}流量`); } else if (type === fetchSourc.P2P) { console.log(`来自P2P的${byteLength}流量`); } }; const fs = new fetchSource(server, videoId, { //全局参数 timeout, forceCDN, cacheSize, debug, trytimes, ioOpts, onreport }); const resourceUrl = '**/**.ts'; fs .fetch(resourceUrl, { //单次请求参数 forceCDN, timeout }) .then(({ buf, p2pbw, cdnbw, type, support, size, loadtime, starttime, speed }) => { //p2pbw == buf.byteLength; 如果从p2p获取流量 //cdnbw == buf.byteLength; 如果从cdn获取流量 console.log(typeof buf); //[ArrayBuffer] }); ``` > 包引入 ```html ... ``` ## change log > 1.0.0 第一版,能跑通 > 1.0.1 加入优先询问已连接的资源请求模块数据,减少  中间服务器查询压力 > 1.0.2 增加缓冲池大小设置,增加配置属性 forceCDN > 1.0.3 增加销毁方法 > 1.0.4 增加上报回调 > 1.0.5 为每一次 fetch 回传来源信息 > 1.0.6 增加 “promise-polyfill” 和 “fetch-polyfill” > 1.0.7 增加 debug log 开关 > 1.0.8 增加 p2p 服务尝试连接次数 > 1.0.9 增加socket.io的参数配置 ioOpts > 1.0.10 添加下载资源速度回传 > 1.0.11 加补丁 修正速度回传计算 单位确定为Kbps