Create a new P2PEngineDash instance, player is an instance of dashjs#MediaPlayer .
If opts is specified, then the default options (shown below) will be overridden.
Field Type Default Description logLevel string|boolean 'error' Print log level(warn, error, none,false=none, true=warn). token string undefined Token is used to summarize and display multi domain name data on the console. In addition, token is required while customizing channelId. trackerZone string 'eu' The country code name of the tracker server address('eu', 'hk', 'us'). memoryCacheLimit Object {"pc": 400 * 1024 * 1024, "mobile": 100 * 1024 * 1024} The max size of binary data that can be stored in the cache. useDiskCache boolean true Use IndexedDB to cache data for VOD streaming. diskCacheLimit Object {"pc": 1500 * 1024 * 1024, "mobile": 1000 * 1024 * 1024} The max size of binary data that can be stored in the disk cache. p2pEnabled boolean true Enable or disable p2p engine. webRTCConfig Object {} A Configuration dictionary providing options to configure WebRTC connections. useHttpRange boolean true Use HTTP ranges requests where it is possible. Allows to continue (and not start over) aborted P2P downloads over HTTP. showSlogan boolean false Display slogan of cdnbye on console. startFromSegmentOffset number 3 The segment offset that start to connect to tracker server. P2PEngineDash API P2PEngineDash.version (static)Get the version of P2PEngineDash.
P2PEngineDash.protocolVersion (static)Get the version of P2P protocol.
P2PEngineDash.isSupported() (static method)Returns true if WebRTC data channel is supported by the browser.
engine.enableP2P()Resume P2P if it has been stopped.
engine.disableP2P()Disable engine to stop p2p and free used resources.
engine.destroy()Stop p2p and free used resources.
P2PEngineDash Events engine.on('peerId', function (peerId) {})Emitted when the peer Id of this client is obtained from server.
engine.on('peers', function (peers) {})Emitted when successfully connected with new peer.
engine.on('stats', function (stats) {})Emitted when data is downloaded/uploaded.
stats.totalHTTPDownloaded: total data downloaded by HTTP(KB).
stats.totalP2PDownloaded: total data downloaded by P2P(KB).
stats.totalP2PUploaded: total data uploaded by P2P(KB).
stats.p2pDownloadSpeed: p2p download speed(KB/s).
Emitted when websocket is opened/closed.
engine.on('exception', function (e) {})Emitted when exception occured.
e.code: Exception identifier(TRACKER_EXPT SIGNAL_EXPT DASHJS_EXPT)
e.message: Exception message
e.stack: Exception stack
p2pConfig: {
getStats: function (totalP2PDownloaded, totalP2PUploaded, totalHTTPDownloaded, p2pDownloadSpeed) {
},
getPeerId: function (peerId) {
},
getPeersInfo: function (peers) {
},
onHttpDownloaded: function (traffic) {
},
onP2pDownloaded: function (traffic, speed) {
},
onP2pUploaded: function (traffic) {
},
}
note
The unit of download and upload is KB. The unit of download speed is KB/s.
Advanced Usage Dynamic MPD Path SupportSome MPD urls play the same live/vod but have different paths on them. For example, example.com/clientId1/streamId.mpd and example.com/clientId2/streamId.mpd. In this case, you can format a common channelId for them.
p2pConfig: {
token: YOUR_TOKEN,
channelId: function (mpdUrl) {
const videoId = extractVideoIdFromUrl(mpdUrl);
return videoId;
},
}
Dynamic Segment Path Support
Like dynamic mpd path, you should format a common segmentId for the same segment file. You can override the segment ID like this:
p2pConfig: {
segmentId: function (segmentUrl, range) {
const segId = extractSegmentIdFromUrl(segmentUrl);
return segId;
}
}
Allow Http Range Request
If http range request is activated, we are able to get chunks of data from peer and then complete the segments by getting other chunks from the CDN, thus, reducing your CDN bandwidth. Besides, the code below is needed:
p2pConfig: {
useHttpRange: true,
}
How to Check Segment Validity
Sometimes we need to prevent a peer from sending a fake segment (such as the bittorrent with a hash function). CDNBye provides a validation callback with buffer of the downloaded segment, developer should implement the actual validator. For example, you can create a program that generates hashes for the segments and stores them in a specific file or injects into m3u8 playlist files the hashes information. If the callback returns false, then the segment is not valid.
p2pConfig: {
validateSegment: function (segId, buffer) {
var hash = hashFile.getHash(segId);
return hash === md5(buffer);
}
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4