Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cdnbye-dash

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cdnbye-dash

Save Your Bandwidth using WebRTC.

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by1200%
Maintainers
1
Weekly downloads
 
Created
Source

English | 简体中文

cdnbye logo

Save Your Bandwidth using WebRTC.

npm jsdelivr size

CDNBye dashjs-p2p-engine implements WebRTC datachannel to scale live/vod video streaming by peer-to-peer network using bittorrent-like protocol. The forming peer network can be layed over other CDNs or on top of the origin server. Powered by dash.js, it can play MPEG-dash on any platform with many popular HTML5 players such as video.js, JWPlayer and Flowplayer. BTW, you can view how much traffic has been saved here!

Features

  • WebRTC data channels for lightweight peer-to-peer communication with no plugins
  • Support live and VOD streams over MPEG-dash protocol
  • Very easy to integrate with an existing dash.js project
  • Seamlessly fallback to normal server usage if a browser doesn't support WebRTC
  • Highly configurable for users
  • Support most popular HTML5 players such as video.js、Clappr、Flowplayer
  • Efficient scheduling policies to enhance the performance of P2P streaming
  • Use IP database to group up peers by ISP and regions
  • API frozen, new releases will not break your code

Getting Started

Put the quick-start.html in your web page, run it. Wait for a few seconds,then open the same page from another browser. Now you have a direct P2P connection between two browsers without plugin! The first web peer will serve as a seed, if no one else in the same channel.

Browser Support

WebRTC has already been incorporated into the HTML5 standard and it is broadly deployed in modern browsers. The compatibility of CDNBye depends on the browser support of WebRTC and dash.js. Please note that iOS Safari "Mobile" does not support the MediaSource API.

CompatibilityChromeFirefoxmacOS SafariAndroid Wechat/QQOperaEdgeIEiOS Safari
WebRTC Datachannel
dash.js
CDNBye

Include

Include the pre-built script of latest version:

<script src="https://cdn.jsdelivr.net/npm/cdnbye-dash@latest"></script>

Usage

<!doctype html>
<html>
    <head>
        <title>Dash with P2P</title>
        <style>
            video {
                width: 640px;
                height: 360px;
            }
        </style>
    </head>
    <body>
        <div>
            <video id="videoPlayer" controls></video>
        </div>
        <script src="yourPathToDash/dash.all.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/cdnbye-dash@latest"></script>
        <script>
            (function(){
                var url = "https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd";
                var player = dashjs.MediaPlayer().create();
                new P2PEngine(player);
                player.initialize(document.querySelector("#videoPlayer"), url, true);
            })();
        </script>
    </body>
</html>

API and Configuration

Create instance

var engine = new P2PEngine(player, {p2pConfig: [opts]});

Create a new P2PEngine instance, player is an instance of dashjs#MediaPlayer.

If opts is specified, then the default options (shown below) will be overridden.

FieldTypeDefaultDescription
logLevelstring or boolean'none'Print log level(warn, error, none,false=none, true=warn).
livebooleanfalsetell engine whether in live or VOD mode, set to false will pre-buffer for smooth playing.
wsSignalerAddrstring'wss://signal.cdnbye.com'The address of signal server.
announcestring'https://tracker.cdnbye.com/v1'The address of tracker server.
wsMaxRetriesnumber15The maximum number of reconnection attempts that will be made by websocket before giving up.
wsReconnectIntervalnumber30The number of seconds to delay before attempting to reconnect by websocket.
memoryCacheLimitObject{"pc": 1024 * 1024 * 512, "mobile": 1024 * 1024 * 256}The max size of binary data that can be stored in the cache.
p2pEnabledbooleantrueEnable or disable p2p engine.
dcDownloadTimeoutnumber25Max download timeout for WebRTC datachannel.
webRTCConfigObject{}A Configuration dictionary providing options to configure WebRTC connections.
useHttpRangebooleanfalseUse HTTP ranges requests where it is possible. Allows to continue (and not start over) aborted P2P downloads over HTTP(True in live mode by default).
getStatsfunction-Get the downloading statistics, including totalP2PDownloaded, totalP2PUploaded and totalHTTPDownloaded.
getPeerIdfunction-Emitted when the peer Id of this client is obtained from server.
getPeersInfofunction-Emitted when successfully connected with new peer.
channelIdfunction-Pass a function to generate channel Id.(See advanced usage)
validateSegmentfunction-Pass a function to check segment validity downloaded from peers.

P2PEngine API

P2PEngine.version (static method)

Get the version of P2PEngine.

P2PEngine.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.

P2PEngine 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).

Advanced Usage

Another way to get the downloading statistics
p2pConfig: {
    getStats: function (totalP2PDownloaded, totalP2PUploaded, totalHTTPDownloaded) {
        // do something
    }
}
Another way to get peer Id
p2pConfig: {
    getPeerId: function (peerId) {
        // do something
    }
}
Another way to get peers information
p2pConfig: {
    getPeersInfo: function (peers) {
        // do something
    }
}
Dynamic MPD path issue

Some MPD urls play the same live/vod but have different paths on them. For example, example.com/clientId1/file.mpd and example.com/clientId2/file.mpd. In this case, you can format a common channelId for them. It is strongly recommended to add a unique identifier to the channelid to prevent conflicts with other channels.

p2pConfig: {
    channelId: function (mpdUrl) {
        const formatedUrl = 'YOUR_UNIQUE_ID' + format(mpdUrl);   // format a channelId by removing the different part
        return formatedUrl;
    }
}
Config STUN Servers
p2pConfig: {
    webRTCConfig: { 
        config: {         // custom webrtc configuration (used by RTCPeerConnection constructor)
            iceServers: [
                { urls: 'stun:stun.l.google.com:19302' }, 
                { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }
            ] 
        }
    }
}
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,
}

Console

Bind your domain in https://oms.cdnbye.com, where you can view p2p-related information.

They are using CDNBye

FAQ

We have collected some frequently asked questions. Before reporting an issue, please search if the FAQ has the answer to your problem.

Contact Us

Email: service@cdnbye.com

Keywords

FAQs

Package last updated on 27 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc