Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(walk): wildcard room relay no longer throws on every message

nirholas69d604afd538
diff --git a/src/walk-net.js b/src/walk-net.js
index 8358ad085..bd57e02ef 100644
--- a/src/walk-net.js
+++ b/src/walk-net.js
@@ -107,6 +107,7 @@ export class WalkNet {
change: new Set(), // (player, sessionId)
chat: new Set(), // ({ id, name, text, ts })
social: new Set(), // ({ type, ... }) — friends events: live DM, request/accept (Task 15)
+ message: new Set(), // (type, payload) — catch-all for every other room message
};
// Optional async presence-ticket supplier (Task 15). When provided, its
// resolved token rides the join so this coin world publishes the player's
@@ -132,7 +133,12 @@ export class WalkNet {
}
_emit(event, ...args) {
- for (const fn of this._handlers[event]) {
+ // A missing bucket must never throw: _emit runs inside colyseus message
+ // callbacks, so an unknown event would escape into the socket's dispatch
+ // loop and surface as an uncaught TypeError on every room message.
+ const bucket = this._handlers[event];
+ if (!bucket) return;
+ for (const fn of bucket) {
try { fn(...args); } catch (e) { log.error(`[walk-net] ${event} handler threw:`, e); }
}
}
diff --git a/tests/walk-net-emit.test.js b/tests/walk-net-emit.test.js
new file mode 100644
index 000000000..a9b554daf
--- /dev/null
+++ b/tests/walk-net-emit.test.js
@@ -0,0 +1,60 @@
+/**
+ * WalkNet's event emitter must never throw out of a colyseus callback.
+ *
+ * The shared WalkRoom broadcasts ~20 message types; walk-net registers a
+ * wildcard relay that re-emits everything it doesn't handle explicitly as a
+ * 'message' event. `_emit` runs INSIDE colyseus's message dispatch, so an
+ * event with no registered bucket must degrade to a no-op: a throw there
+ * escapes into the socket's dispatch loop and breaks message handling for the
+ * whole room (an uncaught "this._handlers[t] is not iterable" on every frame).
+ */
+
+import { describe, it, expect, vi } from 'vitest';
+
+vi.mock('colyseus.js', () => ({ Client: class {}, getStateCallbacks: () => () => ({}) }));
+
+const { WalkNet } = await import('../src/walk-net.js');
+
+// The constructor resolves a server URL from meta/env; a bare instance is all
+// these tests need (no connect() is called).
+function net() {
+ return new WalkNet({ url: 'wss://example.invalid' });
+}
+
+describe('WalkNet event buckets', () => {
+ it('exposes a "message" bucket for the wildcard relay', () => {
+ const n = net();
+ const seen = [];
+ const off = n.on('message', (type, payload) => seen.push([type, payload]));
+ n._emit('message', 'game:king', { king: 'abc' });
+ expect(seen).toEqual([['game:king', { king: 'abc' }]]);
+ off();
+ n._emit('message', 'quests', {});
+ expect(seen).toHaveLength(1);
+ });
+
+ it('emitting an event with no subscribers does not throw', () => {
+ const n = net();
+ expect(() => n._emit('message', 'floor:beat', { clip: 'x' })).not.toThrow();
+ expect(() => n._emit('chat', { text: 'hi' })).not.toThrow();
+ });
+
+ it('emitting an unknown event is a no-op, never a throw', () => {
+ const n = net();
+ expect(() => n._emit('totally-unknown-event', 1, 2)).not.toThrow();
+ });
+
+ it('a throwing subscriber cannot break delivery to the others', () => {
+ const n = net();
+ const got = [];
+ n.on('message', () => { throw new Error('boom'); });
+ n.on('message', (type) => got.push(type));
+ expect(() => n._emit('message', 'inv', {})).not.toThrow();
+ expect(got).toEqual(['inv']);
+ });
+
+ it('on() still rejects an unknown event name', () => {
+ const n = net();
+ expect(() => n.on('nope', () => {})).toThrow(/unknown event/);
+ });
+});