๐Ÿ† WebRTC

On the web, WebRTC is commonly used for peer-to-peer real-time audio or video streams and calls. It can also be used for games via data channels (opens in a new tab). The main difference between WebSocket and WebRTC is that WebSocket uses TCP and sends series of messages in blocking order, whereas WebRTC uses UDP and sends data in a non-blocking way with potential messages (or "packets") being lost. In the case of an authoritative server sending regular updates of a game state, we don't need all messages to arrive in order, we only need the latest state. You might be fine with WebSocket, but if you need the lowest latency possible for multiplayer games (for a fast-paced game like an FPS for instance), WebRTC is a better fit. Here is a good introduction to game networking (opens in a new tab).

It seems like the only library offering a simple client-server socket.io-like setup is Geckos.ioTypeScript1k160/w. I only tried the example (opens in a new tab) and it worked great. Geckos.io uses node-datachannelTypeScript1906k/w under the hood, so you might want to look into this if you need a more custom setup. Check out this video comparison of WebSocket and WebRTC (opens in a new tab) by the creator of Geckos.io.

There is also node-webrtcJavaScript3k9k/w but I was not able to try it due to a missing file (opens in a new tab) during installation, and web-udpTypeScript6010/w4y years.

For peer-to-peer WebRTC, there is PeerJSTypeScript12k24k/w and its PeerServer (opens in a new tab) signaling server, or SimplePeerDefinitely Typed7k37k/w1y year and the related signaling server (opens in a new tab) repository.