Local Wireless Discovery and Communication


#1

The web really needs local networking/discovery abilities to put it at parity with native apps. What I’d like to see is an API that allows the ability to transfer arbitrary data between devices over local wireless. For example, I’d like to make a podcast app, but that app should sync your subscriptions, listened to items and progress between two devices, say phone and desktop. Typically this would be accomplished via a web service, however there are a number of problems with this:

  • Hosting costs money, perhaps not much for metadata but imagine later I wish to transfer the actual podcast data it can get big quickly.
  • The service might be inaccessable (server goes down, user maybe experiencing connectivity issues).
  • The host is responsible for privacy considerations, and the user must trust them.

Currently the web does not provide anything that accomplishes something like this. There are a few avenues available now:

  • Basic fetches to a webserver (issues above)
  • Visual data transfer (e.g. QR). This is not sufficient for anything more than trivial, very short range data transfers and requires considerably complex libraries.
  • Audio data transfer (e.g. ultrasonic communication). This can be prone to error, not suitable for large transfers, and requires complex libraries.
  • Web RTC. This gets us about halfway there. The hosting goes down considerably and the transfers are between peers. The main problem is it’s still dependent on some infrastructure, it wouldn’t work where the user has no connectivity or where connectivity is limited.
  • Web Bluetooth. Since this can only connect to peripherals, it cannot be used to communicate arbitrarily between apps on devices.
  • Web USB. This requires that the device itself allows pages to connect to it which the app has no control over. Also wires.
  • Web NFC. Short range and low bandwidth.

My example on the surface might seem a little unconvincing but there are plenty of other usecases like:

  • Mesh networking (chat, file transfers, IoT etc)
  • Perhipheral web apps that communicate to a main app (ie use phone as a remote)
  • Local multiplayer in games (handheld consoles have always supported this)
  • Privacy focused apps where the user wouldn’t trust a cloud service
  • Apps that want good offline tolerance. Full internet access can be seen as a progressive enhancement to local networks.

I’m not any sort of expert on wireless networking but I imagine this could be built on Wifi Direct. It might even be the case that the device must go offline to accomplish this task (depending on capibilities) which seems okay if it’s backed by a service worker.

I imagine the security model would pose most of the questions. I envision something like having the pages need to manually signal they want to be discoverable and then requiring that connecting apps on each device must have matching domains but obviously there’s probably a lot more there.

The API I’d be thinking of would something like:

navigator.makeDiscoverable(advertisedMetaData);

navigator.findDevices(advertisedMetaDataFilter).then(listOfDevices => {
	listOfDevices[0].connect().then(connection => {
		connection.onmessage = () => {};
		connection.postMessage(...) //like websocket/broadcast channel etc.
	})
})

Anyway I haven’t seen any proposals so far for something like this but I feel it must have at least come up at some point, is there anything out there right now? Now that WebBluetooth and WebUSB are paving the way for more hardware based APIs it sounds like much less of jump to have something like this in the Web toolbox. What would be the interest level?


#2

You might want to take a look at: https://flyweb.github.io/spec/

This seems to have similar goals to what you are after, it’s not currently in the WICG but perhaps it could be? /cc @marcosc


#3

Flyweb is a long way from ready at this stage, even for incubation. It turns out to be really hard to get the security and privacy aspects of this nailed down. @Somnid wants something less than what flyweb is looking at, but even that is very difficult to achieve on the web. Start with the question: how do I know that this is really my kettle?

It’s interesting how most of the pieces have been around for ages, but the security architecture remains an unsolved mystery.


#4

I’d be curious to know more about the particulars of the implementation pain points. Device identity seems to have been a mostly solved problem for Bluetooth typically via PIN codes, but QR and NFC should work as well. This may reduce some of the use-cases to initial line-of-sight and to devices of a certain complexity but if we did that does it help at all? I’d imagine a good starting demo feature set would be just the ability to ad-hoc pair two phones for a local chat app.


#5

Opera once upon a time shipped the Network Discovery API, which can tell you UPnP and ZeroConf services in the area.

In a smaller scope, I continue to work to giving a way for services to announce themselves within the browser, allowing them to be discovered by other web pages. I initially proposed discovery for navigator-connect (navigator-connect was replaced latter by foreign-fetch), and have recently been doing a follow-up implementation on that idea.