Skip to main content

Introduction

npmjsdelivr

This MP4/MP3 SDK creates a communal, distributed CDN using the latest HTML5 APIs — WebRTC to connect browsers and Service Worker to handle requests. As expected, it supports all modern browsers and all web players.

Browser Support

WebRTC is already part of the HTML5 standard and is broadly supported in modern browsers. SwarmCloud's compatibility depends on browser support for WebRTC and Service Worker.

CompatibilityChromeFirefoxmacOS SafariOperaEdgeiOS SafariIE
WebRTC Datachannel
Service Worker
Supported

How does it Work?

  • The SwarmCloud SDK embeds a local proxy server between the player and the origin to intercept content requests
  • The player starts streaming content through the proxy
  • The local proxy (Service Worker) waits for network requests of MP4/MP3 files by listening for network fetch events, then forwards the request to the main thread
self.addEventListener('fetch', event => { /* ⛦ magic here ⛦ */ })
  • The main thread decides whether to download from a peer based on the P2P network situation. After downloading, the main thread saves a copy to share with other nodes
  • After an asset is cached, every device watches for future requests for that asset and automatically retrieves it from the peer-to-peer network instead of the more expensive, slower origin server (via WebRTC instead of HTTP)
  • If no peers are available or P2P fails, the request passes through the Service Worker unmodified and is fetched from the origin server

Limitations

  • Only works on HTTPS websites
  • You must host the web SDK (sw.js) on your own servers instead of retrieving it from our public cloud

Demo

View the demo