P2P Streaming Engine

vuePress-theme-reco    2018 - 2021
P2P Streaming Engine P2P Streaming Engine

Choose mode

  • dark
  • auto
  • light
Documents
  • Introduction
  • Web SDK

    • Hls.js
    • Dash.js
    • Shaka-Player
    • MP4
    • Downloader
    • Website Acceleration
  • Android SDK
  • iOS SDK
  • Flutter SDK
Pricing
Contact Us
Partnership
Console
GitHub
语言
  • English
  • 简体中文

Documents
  • Introduction
  • Web SDK

    • Hls.js
    • Dash.js
    • Shaka-Player
    • MP4
    • Downloader
    • Website Acceleration
  • Android SDK
  • iOS SDK
  • Flutter SDK
Pricing
Contact Us
Partnership
Console
GitHub
语言
  • English
  • 简体中文
  • Introduction
  • FAQ
  • Tracking Service
  • Signaling Service
  • P2P Optimization
  • Console

    • Domain/AppId Binding
    • Data Analysis
    • P2P Control
    • Restful API
  • Hls.js SDK

    • Introduction
    • Usage
    • Player Integration
    • API & Config
    • CDN
    • Change Log
  • Android SDK

    • Introduction
    • Usage
    • API & Config
    • Change Log
  • iOS SDK

    • Introduction
    • Usage
    • API & Config
    • Change Log
  • Flutter SDK

    • Introduction
    • Usage
    • API & Config
    • Change Log
  • ServiceWorker SDK

    • Introduction
      • Usage
      • API & Config
      • Change Log
    • Shaka-Player SDK

      • Introduction
      • Usage
      • Player Integration
      • API & Config
      • Change Log
    • Web MP4 SDK

      • Introduction
      • Usage
      • Player Integration
      • API & Config
      • Change Log
    • Dash.js SDK

      • Introduction
      • Usage
      • Player Integration
      • API & Config
      • Change Log
    • Web Downloader

      • Introduction
      • Usage
      • API & Config
      • Change Log
    • Android SDK 1.x

      • Introduction
      • Usage
      • API & Config
      • Change Log
    • More

      • Design

    Introduction

    vuePress-theme-reco    2018 - 2021

    Introduction


    Speed up your website using WebRTC and ServiceWorker.

    npm jsdelivr

    Sites with SwarmCloud load faster because their content is fetched from people's devices near you instead of from data centers far away.
    SW P2P Engine creates a communal, distributed CDN with the latest HTML5 APIs — WebRTC to connect browsers, ServiceWorker to fulfill requests, IndexedDB to cache data, and WebCrypto to do it all securely. And it never impacts the user experience. Ever. This lightweight library uses only a small portion of spare bandwidth, imperceptible CPU, 150MB of browser cache.

    # Features

    • WebRTC data channels for lightweight peer-to-peer communication with no plugins
    • Support most popular static assets such as js, css, image and audio.
    • Automated pre-caching and intelligent pre-loading.
    • Seamlessly fallback to normal server usage if a browser doesn't support WebRTC
    • Compatible with all CDNs. No service side changes required.
    • Efficient scheduling policies to enhance the performance of P2P streaming
    • Use IP database to group up peers by ISP and regions

    # Browser Support

    WebRTC has already been incorporated into the HTML5 standard and it is broadly deployed in modern browsers. The compatibility of SwarmCloud depends on the browser support of WebRTC, Service Worker and IndexedDB.

    Compatibility Chrome Firefox Mac Safari Android Wechat/QQ Opera Edge iOS Safari IE
    WebRTC ✔ ✔ ✔ ✔ ✔ ✔ ✔ ❌
    Service Worker ✔ ✔ ✔ ✔ ✔ ✔ ✔ ❌
    IndexedDB ✔ ✔ ✔ ✔ ✔ ✔ ✔ ❌
    SwarmCloud ✔ ✔ ✔ ✔ ✔ ✔ ✔ ❌

    # How does it Work?

    • The js library sw-p2p-engine starts the Service Worker.
    • The Service Worker waits for network requests for cacheable, static assets (like, say, https://yourwebsite.com/kitty.png) by listening for network fetch events.
    self.addEventListener('fetch', event => { /* ⛦ magic here ⛦ */ })
    
    • A network request is determined cacheable if both
      • The response headers include valid, unexpired cache headers, like Cache-Control or Expires, and
      • The asset is one of the supported static file types (e.g. jpg, png, js, css, mp3, etc).
    • Once a network response is deemed cacheable, in the background, our PeerWorker independently retrieve, fragment, encrypt, distribute, and securely cache a mirrored copy of that asset across CDNBye's peer-to-peer network.
    • After an asset is cached, every device watches for future requests for that asset and automatically retrieves it from peer-to-peer network instead of the more expensive, slower origin server (over WebRTC instead of HTTP).
    • All assets not cached or deemed uncacheable transparently fall through Service Worker unmodified and are fetched from the origin server.

    # Best Practices

    • Prepare
      • SSL enabled on your website
      • A CDNBye Portal Account
      • Your domain registered on the CDNBye Portal
    • Put the SDK on the entrance page, such as the home page of the website
    • Redirect user's HTTP request to HTTPS, so as to ensure that P2P can work normally
    • When user jump to other pages, open the new page in the new tab to keep the original page from being covered
    • Put pictures and other resources under the current domain to avoid cross domain configuration
    • If you have to use the third-party domain name resources (such as AWS's CDN), please remember to configure the CORS header in the CDN, and add the third-party domain name to the white list on the SDK side. For detailed steps, please refer to here
    • Please do not use this SDK to speed up large resources such as long videos and large files