RangerMauve / discovery-swarm-stream

Give access to a discovery swarm instance over a stream.
MIT License
17 stars 3 forks source link

idea: expose as a browser extension #1

Closed billiegoose closed 6 years ago

billiegoose commented 6 years ago

My dream / vision would be:

  1. Install Browser WebExtension "discovery-swarm" (I've written Chrome extensions that communicate with pages via postMessage, so I know how to inject a new global API into all the web pages.)
  2. Install OS service for "discovery-swarm". (I've gotten some experience doing this with hypergit)
  3. Pages can magically communicate with "discovery-swarm" via a global.

Example page usage:

let sw = await window.getDiscoverySwarm()
// only difference between "sw" and normal "discovery-swarm" is it's async instead of sync.
// Promises resolve once the command & return value passes from page -> WebExtension -> OS Service -> WebExtension -> page.
await sw.listen(1000)
await sw.join('ubuntu-14.04') // can be any id/name/hash

sw.on('connection', function (connection) {
  console.log('found + connected to peer')
})
billiegoose commented 6 years ago

Holyshit I just realized this idea can be generalized to any node module. Oh man. Hang on this is nutz. I can't believe nobody has done this. (Also, I can't believe the Chrome Web Store is flooded with extensions that do nothing but replace the text "Node.js" with "The One True Dev Language" or "My Butt".)

RangerMauve commented 6 years ago

I don't think you even need an extension if you have a local service running. My goal is to allow browser pages to talk to the local gateway directly, and fallback to public discovery-swarm gateways if one doesn't exist. With this you can skip the first step and have the JS import a library which implements the discoverySwarm API and auto-discovers a gateway.

A few years ago I was inspired by leapmotion's JavaScript SDK, it started a local WS server along with the software needed to make the leapmotion work, and the JS SDK automatically connected to the server if it existed. From the point of view of a developer, I just had to focus on the JS API, and the integration was handled for me behind the scenes.

I really want to have a similar experience with this. Just import the module in your JS, and use it (optionally specifying a domain for the WS server).

billiegoose commented 6 years ago

Ah, I see. Yeah... so a raw WebSocket API would be annoying, I think, but wrapped in a small JS library that makes a lot of sense. I still think there's room for a browser extension - I really like the IPFS Companion chrome extension - but that might be orthogonal / unrelated to the WebSocket idea.

RangerMauve commented 6 years ago

Yeah, @gozala is working on libdweb which is going to enable extensions to implement all the stuff necessary for the discovery swarm without any external services.

@mafintosh just made this to act as a proxy for hypercores. Which might be relevant.

RangerMauve commented 6 years ago

@fsteff is working on an Android thing that injects globals into a WebView in order to provide the dns-discovery functionality.

billiegoose commented 6 years ago

😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁 😁

So much good stuff happening! I decided not to pursue the browser extension idea, and stay focused on hypergit and isomorphic-git. I need to get isomorphic-git to the point where you can clone over WebRTC.