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?