Advanced: Implement Your Own Callback System
The @colyseus/schema version 3.0 introduced a way to bring your own callback system during decoding.
The standard way of attaching callbacks uses the same “flavor” as Colyseus is used to from previous versions. However, you can bring your own callback system by overriding the Decoder’s triggerChanges method.
The following example shows how to bring your own callback system:
client.ts
import { getRawChangesCallback } from "@colyseus/schema";
// Also available on the decoder root:
// - decoder.root.refs => map of all Schema instances by refId
// - decoder.root.refCount => map of reference counts by refId
// - instance[$refId] => a ref's id, stored on the instance itself
// ($refId is exported from @colyseus/schema)
const room = await client.joinOrCreate("my_room");
getRawChangesCallback(room['serializer']['decoder'], (changes) => {
console.log("raw list of changes", changes);
});On the above example, the raw list of changes is being printed to the console.
Each SDK has its own way of handling the callback system.