for chatting
Screen.Recording.2022-04-03.at.12.18.16.PM.mov
Peer to peer chat app
Node server does the following:
- Serves a few static assets
- Server-renders a single root path
- Upgrades to a websocket server
- Serves as a signaling server for initiating p2p connections
Browser:
- Manages a websocket connection to the signaling server
- Creates or joins an existing chat session via websocket
- Connects to peer to send text messages
git clone micburks/chat micburks-chat
cd micburks-chat
yarn
yarn start
# cross fingers you don't hit a race condition
- obviously this only works on a local network, would need NAT traversal for public use
- the signaling server is a critical user flow, needs integration tests
- Use a proper database - lots of race conditions with current approach
- Ideally
chats
andusers
would have a one-to-many in the data model - Destroy chats when all users disconnect
- It doesn't make much sense to create new instances of Database class
- Better tracking of connected users
- More robust error handling for sockets/p2p
- Design a UI that isn't hideous
- Ask creator when another user tries to enter the chat, only share chatId when approved
- There are race conditions in the UI where you can send a message before p2p is established
- This is possible but requires keeping track of all peers, connecting to each, and sending messages to all
- messages should be batched in case websocket/p2p is temporarily lost
- service worker may also be able to store outgoing messages queue when offline