Looking at
- Are there any Webxdc runtime which works directly in browser?
- WofWca/webxdc-yjs-provider: Sync webxdc app state automatically with Yjs - webxdc-yjs-provider - Codeberg.org
- #45 - Make a web-version (with WebRTC) - editor - Codeberg.org
I came up with way to make a webxdc app usable on the web (with peers - not just locally), with only a few extra lines of build configuration, or just a file copy-paste.
And that is, by making the webxdc API work on the web, by implementing it with WebRTC.
Implementation
The approach is similar to how we currently use webxdc.js
files. That is, when the app is bundled for deployment as a website (and not a .xdc
file), we include a webxdc.js
file that implements webxdc API with WebRTC under the hood.
The y-webrtc
library can be taken as a reference. I have some experience (hehe) with WebRTC myself, so I guess I’ll go be working on it.
Rooms, passwords
Since there is no “chat group” that you send the message to, we would have to make sure that peers can join the peers they want to join, and keep out the peers they want to keep out. Initially, without requiring any code changes to the app, we can achieve this by adding a room name and password to the URL, and letting people share that URL between each other. The same way, say, CryptPad does it, like this: https://cryptpad.fr/code/#/2/code/edit/-1PGMmcztxKb3h3hCWFtS/
.
Later we could add API to control this (the password, the room name, the signaling servers).
Data sync
What I’m trying to figure out right now is the implementation details of how to get this “chat-like” webxdc update stream, to make sure that it’s consistent enough. It feels like there must be a library that does this, but I haven’t looked hard enough. I don’t think we need CRDTs for this as the messages thing has to be just (based on @Simon 's info) a grow-only set of immutable elements (messages), therefore there can’t be any conflicts in such a structure, it’s just about making sure that all peers eventually have all the members of the set. There is no need to ensure that, say, the order of the messages is the same for all the members.
About
Of course the guarantees of “no exfiltration even if the app is malicious” go away if you use a regular web version hosted on something like gh-pages. And even with CSP, WebRTC is required, and for now CSP in the field of WebRTC is only advanced enough to turn it on or off (here’s some more).
But if we decide to go for a proper web runtime that can also run .xdc
files some day, this library should be of some help.