retrohacker / peerweb.js

A client side library for fetching and rendering a static website via torrent over WebRTC
198 stars 15 forks source link

Fallback when peerweb is not supported #4

Open hhirsch opened 8 years ago

hhirsch commented 8 years ago

Hello,

nice work. How about enabling a fallback to a non-torrent version in case the browser does not support it? For me this is the only issue blocking me from using it in production.

retrohacker commented 8 years ago

Hey @hhirsch, this is somewhat possible with the way the project currently stands.

window.peerweb.init(function(e) {
  if(e) {
    // either the service worker didn't register yet and a refresh will fix
    // OR service workers aren't available in the current browser
    // redirect to normal HTTP
  }
  window.peerweb.debug = true
  window.peerweb.render([torrent_hash])
})

If you would like to open a PR that extends the init function to do additional feature detection, it could check to make sure blobs are available from the service worker (chrome can't do this) and websockets don't get broken by the service worker (firefox does this).