Delta Chat introduces P2P networking for webxdc apps
November 17, 2024 by olgax
The rolling Delta Chat 1.48 app releases introduce the new
webxdc realtime API
which establishes a private P2P network between all users of a chat-shared app.
Web apps can now call webxdc.joinRealtimeChannel() and thereby instruct the hosting messenger to establish ephemeral
realtime channels with peers.
To implement webxdc realtime channels, Delta Chat uses the Iroh Networking library, driven by an experienced developer team with whom we enjoy collaboration for a longer time; big shoutout as Iroh is also behind the multi-device setup of Delta Chat!
The new webxdc realtime API is not only easier to use than the classic WebRTC Browser API. but it is also faster in some situations, according to preliminary measurements. Here is a little 30 second video showcasing the offline-first and realtime Pixel app between an iPhone and an old Android phone.
In the following sections, we provide technical details about “Pixel” and highlight a few other first realtime apps that are available through the webxdc app store.
Pixel app is small, offline-first and realtime
XXX add pixel image on the right side
The source code of the pixel app
-
consists of 241 lines of Javascript (including all dependencies),
-
offers collaborative realtime pixel-drawing
-
BUT does not require users to be online at the same time.
The pixel app achieves its hybrid offline-first and realtime connectivity by using two separate webxdc messaging APIs:
-
webxdc.sendUpdate to relay “application updates” through the regular host messenger channel (e-mail for Delta Chat, XMPP for Cheogram and Monocles).
-
realtimeChannel.send to relay ephemeral application messages to any P2P-connected chat partner
If you want to understand how the pixel app achieves “eventual synchronization for all users”, we suggest to dive into the Shared Web Application state chapter and then read the 241 lines of Javascript.
If you want to improve the app, please feel free to fork and submit your variant. There already is the ColorPixel app which is a Pixel fork where each participant draws pixels in a different color.
The “Pong” app is realtime-only and implements delay compensation
XXX provide 10-second Pong video of two players playing
The pong app
is a simple two-player implementation of the classic ping pong
experience back in the 1970ties.
It’s UX wise rudimentary but implements basic “clock synchronization”
which is an important consideration for any realtime networked gaming app.
Please see the pong source code
for details.
The Unix terminal app using a realtime channel to a chat bot
XXX provide screenshot of an xdcterminal in a messagelist
The xdcterm app demo requires a npm/node install to run a chat bot and then provides a Terminal app so that you (or a group member of a chat group) can open a realtime terminal to where the chat bot runs.
The LiveChat app providing true realtime ephemeral chatting
XXX provide a 10-second video of 3 people live chatting
The editor with offline-first optional realtime syncing
XXX provide a 20-second video of 3 people editing
Get ready, player one!
If you are interested in webxdc app development, we recommend the following readings:
Don’t hestitate to get back to our fediverse account or other contact addresses with any questions!