Like todd said an existing library exists, this is the site for the spec https://webxdc.org
The gist is that you get no internet / threading whatsoever, but you get additional API's to get someone's username for example. Then you also get an API for a realtime channel with the other people in the chat who have the app open.
With that you can do a lot, so people can send chess data over the realtime, submit match replays to chat, even do it slow turn based over chat, etc.
One of the most advanced ones is a fully functional runescape server and client. You open the app, it loads the character progress from the chat and if nobody is hosting yet it begins to automatically host the world for the others.