Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colyseus.js

Package Overview
Dependencies
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colyseus.js

Multiplayer Game Client for the Browser

  • 0.6.0-alpha.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
decreased by-18.27%
Maintainers
1
Weekly downloads
 
Created
Source

colyseus.js

Colyseus.js - Multiplayer Game Client for the Browser.

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

JavaScript/TypeScript client for Colyseus Multiplayer Game Server.

The version 0.6.0 is still in beta. Expect some changes before the final release.

Usage

Connecting to server:

import * as Colyseus from "colyseus.js";

var client = new Colyseus.Client('ws://localhost:2657');

Joining to a room:

var room = client.join("room_name");
room.onJoin.add(function() {
    console.log(client.id, "joined", room.name);
});

Listening to room state change:

Here comes the most powerful feature of the client. You can listen to every state update in the server-side, and bind them into client-side functions.

The first parameter is the path of the variable you want to listen to. When you provide placeholders (such as :number, :id, :string) to the path, they will populate the function with the value found on it. See examples below.

Listening to entities being added in the room:

room.state.listen("entities/:id", "add", (entityId: string, value: any) => {
    console.log(`new entity ${entityId}`, value);
});

Listening to entity attributes being replaced:

room.state.listen("entities/:id/:attribute", "replace", (entityId: string, attribute: string, value: any) => {
    console.log(`entity ${entityId} changed attribute ${attribute} to ${value}`);
});

Listening to entities being removed:

room.state.listen("entities/:id", "remove", (entityId: string) => {
    console.log(`entity ${entityId} has been removed`);
});

Other room events

Room state has been updated:

room.onUpdate.add(function(state) {
  console.log(room.name, "has new state:", state)
})

Data coming from server directly to this client:

room.onData.add(function(data) {
  console.log(client.id, "received on", room.name, data)
});

Server error occurred:

room.onError.add(function() {
  console.log(client.id, "couldn't join", room.name)
});

The client left the room:

room.onLeave.add(function() {
  console.log(client.id, "left", room.name)
});

License

MIT

Keywords

FAQs

Package last updated on 08 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc