For full release notes check out the release announcement.
New features
- New Room's
onBeforePatch
lifecycle hook. (#385) - Schema: single property callback is now available on all platforms!
- Possibility to access a client directly through its
sessionId
(#443) - Introduced log flag for incoming and outgoing messages (
DEBUG=colyseus:messages
) (#465) - Support for custom loggers (via
logger:
Server option) (#442) - Introduced support for raw byte message exchange (
room.sendBytes()
/client.sendBytes()
, see example project) - Introduced devMode for aiding iterative development process by caching and restoring state and client connections upon server reloading in developement.
Breaking changes
client.reconnect()
vulnerability fixed & API slightly changedallowReconnection()
: second argument is now mandatory@colyseus/loadtest
has been reworked!- Schema's
.triggerAll()
has been deprecated. - Schema callbacks API change
- Schema's
onChange
behaviour change MapSchema
is now strict on property accessors@colyseus/command
typings update
Bug fixes / Improvements
"redis"
module has been replaced by"ioredis"
for cluster support on bothRedisPresence
andRedisDriver
(#452)- Fixed an issue where matchmaking filter returning all available rooms when filtering criteria is
""
(empty string) ornull
when usingfilterBy
option. (#342) - Some room properties are now fully private (#441)
- Fixed issue with scaling when using uWebSockets transport (#458)
An additional callback has been added for calling before each time the room state is being sent to clients in particular room.
export class MyRoom extends Room<MyState> {
// ...
onBeforePatch(state: MyState) {
console.log(state);
}
// ...
}
You can now listen to a particular property change on all platforms. This used to be possible only on JavaScript/TypeScript:
player.position.listen("x", (value, previousValue) => {/* "x" property changed */})
player.position.listen("y", (value, previousValue) => {/* "y" property changed */})
C# equivalent:
player.position.OnXChange((value, previousValue) => {/* "x" property changed */});
player.position.OnYChange((value, previousValue) => {/* "y" property changed */});
For aiding debugging, logging incoming and outgoing messages functionality has been added. You can enable it by using DEBUG=colyseus:messages
environment variable. (See full documentation on debug messages)
DEBUG=colyseus:messages
Previously, to retrieve a particular client by its sessionId
, you'd need to filter it from the client list:
const opponent = this.clients.find((client) => client.sessionId === sessionId);
Now, you can access it directly:
const opponent = this.clients.get(sessionId);
Node.js has many full-featured loggers, such as winston, bunyan, pino, etc. You can now leverage their functionality on internal Colyseus logs. If left unspecified, console
is used as default logger.
See example below using winston
:
import { Server } from "@colyseus/core";
import * as winston from "winston";
const gameServer = new Server({
logger: winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json(),
),
level: 'info',
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'all.log' }),
],
})
});
Consuming the logger:
To consume it, you must import logger
from @colyseus/core
, see example below:
import { Client, logger } from "@colyseus/core";
export class YourGameRoom extends Room {
onCreate (options: any) {/* ... */}
onJoin(client: Client, options: any) {
logger.info(client.sessionId, "joined!");
}
onLeave (client: Client, consented: boolean) {
logger.info(client.sessionId, "left!");
}
onDispose() {
logger.info("room", this.roomId, "disposing...");
}
}