Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including colyseus with all npm packages installed. Try it out:

var colyseus = require("colyseus")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

colyseus v0.4.18

Multiplayer Game Server for Node.js.

colyseus

Multiplayer Game Server for Node.js. View documentation.

Join the chat at https://gitter.im/gamestdio/colyseus Donate Build Status OpenCollective OpenCollective

Read the blog post to understand the motivation behind this project.

Features / Characteristics

  • WebSocket-based communication
  • Binary delta compressed state (through msgpack / fossil-delta-js)
  • Match-making
  • Custom room handlers
  • Lag compensation (using timeframe, a Timeline implementation) - Not automatic. You should apply the technique as you need, in the client and/or the server.

Official client integration

Community client integration

Usage examples


Room handler API

Room properties

  • clock - A ClockTimer instance
  • timeline - A Timeline instance (see useTimeline)
  • clients - Array of connected clients

Abstract methods

Room handlers must implement all these methods.

  • onJoin (client) - When a client joins the room
  • onLeave (client) - When a client leaves the room
  • onMessage (client, data) - When a client send a message
  • onDispose () - Cleanup callback, called after there's no more clients on the room

Methods:

Room handlers have these methods available.

  • setState( object ) - Set the current state to be broadcasted / patched.
  • setSimulationInterval( callback[, milliseconds=16.6] ) - (Optional) Create the simulation interval that will change the state of the game. Default simulation interval: 16.6ms (60fps)
  • setPatchRate( milliseconds ) - Set frequency the patched state should be sent to all clients. Default is 50ms (20fps).
  • useTimeline([ maxSnapshots=10 ]) - (Optional) Keep state history between broadcatesd patches.
  • send( client, data ) - Send data to a particular client.
  • lock() - Lock the room to new clients.
  • unlock() - Unlock the room to new clients.
  • broadcast( data ) - Send data to all connected clients.
  • disconnect() - Disconnect all clients then dispose.

Contributing

We encourage you to contribute to Colyseus! Please check out the Contributing guide for guidelines about how to proceed. Join us!

Everyone interacting in Colyseus and its sub-projects' codebases, issue trackers and chat rooms is expected to follow the code of conduct.

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free