Giter Site home page Giter Site logo

weplay's Introduction

weplay

How to install

Install with

$ npm install

Then run it with the following ENV vars:

  • WEPLAY_PORT - pointing to the port you want to listen on (3001)
  • WEPLAY_REDIS - redis uri (localhost:6379)
  • WEPLAY_SERVER_UID - unique persistent identifier for this server's instance. Used for keeping track of # of clients in redis (defaults to WEPLAY_PORT)
  • WEPLAY_IP_THROTTLE - the least amount of time in ms that need to pass between moves from the same IP address (100)
$ node index

This will set up the IO server for weplay. It's necessary that you also launch the other services:

  • weplay-web serves the HTML pages and static assets to run the game. It also serves initial state from Redis with the page for optimal performance.
  • weplay-emulator runs an emulator and broadcasts the image data from it with socket.io-emitter to the IO instance(s) that users are connected to.
  • weplay-presence notifies all the IO instance(s) of the aggregate number of online users.

FAQ

How does this all work?

The weplay-emulator service runs a JavaScript-based gameboy color emulator that gets painted to an instance of node-canvas.

Upon each draw an event is emitted and the PNG buffer is piped through Redis to all the IO instances of weplay (this project).

With Socket.IO 1.0 binary support, we can seamlessly transfer the image data contained in the Buffer to all the connected clients, in addition to all the JSON datastructures to make chat and commands work.

This makes weplay a 100% JavaScript project!

What are the error handling scenarios?

  • In the event of a crash of a weplay IO node, clients can be rerouted to another instance and reconnect automatically thanks to socket.io-client.
    • Events that are broadcasted to other users (such as chat messages and "x moved y" events) get persisted upon broadcast into a Redis capped list, which means that upon reconnection users will get the latest events despite having been routed to a new server.
    • The connection count will be eventually consistent and correct thanks to the work of the weplay-presence service that aggregates the connection counts of all servers.
  • In the event of a crash of weplay-emulator, the next time it boots up it restores the virtual machine state that gets persisted by default every 60 seconds (for performance reasons).

Support

If you have ideas or contributions, join #weplay on Freenode.

License

MIT

weplay's People

Contributors

rauchg avatar kevin-roark avatar rase- avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.