colyseus
Options
All
  • Public
  • Public/Protected
  • All
Menu

colyseus

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

Minimalist Multiplayer Game Server for Node.js. View documentation.

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

Live demos:

Features

  • WebSocket-based communication
  • Room instantiation
  • Binary data transfer (through msgpack)
  • Delta-encoded state broadcasts (through fast-json-patch - RFC6902)
  • Lag compensation (using timeframe, a Timeline implementation)
    • (Not automatic. You should apply the technique as you need, in the client and/or the server.)

TODO:

  • "area of interest" updates/broadcasts

Room instantiation diagram:

Room instantiation diagram

Room state diagram:

Room state diagram

Room API

Properties

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

Methods you should implement

  • 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

Available methods

  • 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.

Production usage

It's recommended to use a process manager to ensure the server will reload in case your application goes down.

pm2 start server.js --node-args="--harmony"

Redirect port 80 to target deployment port (e.g. 3000), to avoid running harmful code as sudoer: (read more)

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

License

MIT

Index

Enumerations

Classes

Interfaces

Type aliases

Functions

Type aliases

Client

Client: Client

Functions

logError

  • logError(err: Error): void
  • Parameters

    • err: Error

    Returns void

merge

  • merge(a: any, b: any): any
  • Parameters

    • a: any
    • b: any

    Returns any

spliceOne

  • spliceOne(arr: Array<any>, index: number): void
  • Parameters

    • arr: Array<any>
    • index: number

    Returns void

toJSON

  • toJSON(obj: any): any
  • Parameters

    • obj: any

    Returns any

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc