3 ms·
The server works by using HTML5 Websockets (https://developer.mozilla.org/en-US/docs/WebSockets https://developer.mozilla.org/en-US/docs/WebSockets) which allow
by ola 11y ago
The server works by using HTML5 Websockets (https://developer.mozilla.org/en-US/docs/WebSockets https://developer.mozilla.org/en-US/docs/WebSockets) which allows browsers to do full duplex communication with the servers (they can push and receive messages without having to poll).
The implementation of the multiplayer itself is very simple and consists of these steps:
* Pair up players using a map from one session to another.
* Start an instance of https://github.com/bfirsh/jsnes https://github.com/bfirsh/jsnes on Player 1
* Screenshot the canvas of JSNES using toDataUrl.
* Send the screenshot to Player 2 and render it into a canvas.
* Send Player 2's keyup and keydown event's to Player 1.
The communication over the WebSocket is very fast, the screenshot is being sent at 30 frames per second.
Melody is just a small framework to make WebSockets easier to work with.
- edc117 11y agoThat's really neat - forgive my ignorance on the subject, but how possible is something like this for local multiplayer games in general (outside of NES)? With all the streaming options we've seen recently, I'm surprised something like this hasn't been developed.
- SpaceManNabs 11y agoThanks for explanation.