Introduction
P2P streaming SDK for all browsers(iOS Safari included) and web players, with the help of ServiceWorker and WebRTC.
WebRTC has been supported by iOS and Safari since 2017, but MEDIA SOURCE EXTENSIONS still cannot be used. These extensions are indispensable for integrating the P2P client of browser-based eCDN solutions.
Without the MEDIA SOURCE EXTENSIONS, it appears that no user data can be intercepted at the XHR object or the fetch API, and creating a cluster for peer-to-peer streaming is almost impossible. Luckily there is another way to intercept HTTP traffic while streaming on an iOS device. Even if iOS restricts the possibilities to make adjustments in the browser’s background to make it perfectly cooperating with your own coding and software, there is a way iOS allows developers to insert some web applications inside of Safari. This standard is called “ServiceWorker”.
This SDK creates a communal, distributed CDN with the latest HTML5 APIs — WebRTC to connect browsers, ServiceWorker to fulfill requests. As you might expect, it supports all modern browsers and all web players.
# 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 and Service Worker.
Compatibility | Chrome | Firefox | macOS Safari | Opera | Edge | iOS Safari | IE |
---|---|---|---|---|---|---|---|
WebRTC Datachannel | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
Service Worker | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
SwarmCloud | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ❌ |
On the Android devices, Service Worker cannot intercept media files when playing HLS by video tag directly. Therefore, MSE-based player such as hls.js is required to make this SDK work normally
# 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(ServiceWorker) waits for network requests of HLS (like, say, https://yourwebsite.com/a.ts) by listening for network fetch events, then forward the request to main thread
self.addEventListener('fetch', event => { /* ⛦ magic here ⛦ */ })
- The main thread decides whether to download from the peer according to the P2P network situation. After downloading, the main thread save 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 peer-to-peer network instead of the more expensive, slower origin server (over WebRTC instead of HTTP).
- If no peers or p2p failed, the request fall through Service Worker unmodified and are fetched from the origin server
# Online Demo
(https://demo.cdnbye.com/?ios=true)[https://demo.cdnbye.com/?ios=true]
# Limitations
- Only work on https website
- Need to host our web SDK(sw.js) on your own servers instead of getting it from our public cloud
- LL-HLS is not supported currently