⚔ Multiplayer Framework for Node.js
The @colyseus/schema has received a major restructuring internally, here's what has changed at a glance:
@filter()
implementation, and the addition of @filterChildren()
. Although filters are still not recommended for fast-paced games, it should serve turn-based scenarios pretty well!MapSchema
now uses a real Map
underneath instead of plain objects.constructor()
inside your schemas. Use .assign({ ... })
instead.Besides the schema changes, here are some small changes in the framework itself:
simulateLatency()
: this utility has been included to help you simulate networking delays during development.broadcastPatch()
: this internal method has been exposed, so if you wanna have control over when to send state patches to connected clients, now you can!The website was re-branded to focus on the maintenance and development of the framework, as well as giving more exposure to the Discord community!
Thank you all for the support! ❤
See how to migrate from 0.12 to 0.13
Breaking changes
code
and message
in the client-side (317)On previous versions, there was no concept of a "message type". All messages were just data being sent back and forth. Although this was simple to understand, the disadvantage is that you'd need to parse these messages and perform certain actions depending on its contents on your own.
Now every message has a type, that can be either a string or number. You can now listen for messages by type, directly tied to a callback for them.
This change is particularly useful for C#/Unity.
Whenever you try to join into a room, many different errors can happen - the authentication may fail, the room may not exist anymore, or you may have an actual error in your "onJoin()" method in the server.
Previously, all these types of errors were returning just a "string", with the error message. Now, it returns an error object with both the error message and the proper "code" of the error. You can also throw your own custom codes if you'd like to.
Many people on Discord seem to be implementing their own version of a "realtime room listing lobby". The new built-in lobby room does exactly that. When rooms are created, updated, or destroyed - the lobby room is notified and sends the latest rooms for the clients in real-time. See docs for LobbyRoom.
Ok, this built-in room was actually available on version 0.12 - but it seems it has more value now that you can send and listen to messages by type on version 0.13. See docs for RelayRoom.
The "client" instance you see everywhere on the server-side used to be the raw WebSocket connection. Now, the WebSocket connection is wrapped in an internal structure from the framework. This was necessary to allow the new client.send() API, and it will be more useful in the future when we're going to implement new transport protocols, such as TCP while keeping the same APIs.
sismember
function to presence (#321, thanks @carlosfusion)onCreate()
argument type for gameServer.define()
client.auth
after reconnectionThe this.allowReconnection()
method now returns a Deferred
instance, which can be manually canceled. The second argument is now optional. You can still await
for the Deferred
instance to complete (no breaking change).
Documentation: https://docs.colyseus.io/server/room/#allowreconnection-client-seconds
Version 0.12.0
has a few bug fixes, and a major breaking change in the way messages are sent and parsed internally.
The server used to send TWO messages for all protocol messages. One with the protocol code (e.g. Protocol.ROOM_PATCH
), and a second with the actual data. As of version 0.12
, the first byte of the message is the protocol, and the rest is the actual data.
The broadcasts are slightly faster than before now.
TypeError: Cannot read property '_onJoin' of undefined
(https://github.com/colyseus/colyseus/issues/277)broadcast()
method has been fixed to include the client during onJoin
(https://github.com/colyseus/colyseus/issues/260).listen()
now returns a promise (https://github.com/colyseus/colyseus/issues/287)matchMaker
as a moduleYou can now import the matchMaker
singleton using:
import { matchMaker } from "colyseus";
This is useful for custom match-making routine when needed. E.g. custom ranked matchmaking as this example: https://github.com/endel/colyseus-ranked-matchmaking
If your code relies on gameServer.matchMaker
, please import matchMaker
from colyseus
module instead, as this has been refactored.
NIL
byte collision on @colyseus/schema (https://github.com/colyseus/schema/issues/44, https://github.com/colyseus/schema/pull/45)matchMaker.reserveSeatFor()
is now public (to allow custom ranked match making)RelayRoom
has been exposed as part of the package"seat reservation expired"
error instead of calling onJoin()
with undefined values if seat reservation has expired (default 8 seconds)Explicitly defining the metadata allowed values:
interface Metadata {
status: string;
}
class MyRoom extends Room<State, Metadata> {
// ...
}
Retrieving typed listing with metadata:
const rooms = await client.getAvailableRooms<Metadata>("myroom");
rooms.forEach(room => {
room.metadata.status // typescript knows this is a "string"
})
join
/ joinOrCreate
(https://github.com/colyseus/colyseus/commit/813cf986d31979b747706910a6be80ece4450042)onCreate
and onJoin
(https://github.com/colyseus/colyseus/commit/2f9e475da386b7971044380af719c96728024b90)-
on room ids (https://github.com/colyseus/colyseus/commit/fec67528166283f9c66cb616a364adafd443f1b6)Due to the buzz of the funding project, and seeing other packages such as nodemon, pixijs, and webpack fighting for attention on the terminal, I've decided to remove the "donate" message on Colyseus.