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: ensure socket connection is open before sending messages in irl-net, stage-net, and walk-net

nirholas90b09ff1787e
diff --git a/src/irl-net.js b/src/irl-net.js
index 1152de435..3ab99aa64 100644
--- a/src/irl-net.js
+++ b/src/irl-net.js
@@ -265,7 +265,9 @@ export class IrlNet {
* @returns {boolean} whether the emit was actually sent over a live socket
*/
interaction(payload) {
- if (this.status !== 'online' || !this.room) return false;
+ // connection.isOpen catches the CLOSING/CLOSED window before onLeave flips
+ // status — ws.send() there logs a console warning instead of throwing.
+ if (this.status !== 'online' || !this.room || this.room.connection?.isOpen !== true) return false;
const type = payload?.type;
const pinId = payload?.pinId;
if (!type || !pinId) return false;
@@ -290,7 +292,7 @@ export class IrlNet {
* @param {number} headingDeg compass bearing 0–359 the viewer is facing
*/
heartbeat(headingDeg) {
- if (this.status !== 'online' || !this.room) return;
+ if (this.status !== 'online' || !this.room || this.room.connection?.isOpen !== true) return;
const heading = Number.isFinite(headingDeg) ? headingDeg : 0;
try { this.room.send('heartbeat', { heading }); } catch (e) {
log.warn('[irl-net] heartbeat send failed:', e?.message || e);
@@ -307,7 +309,7 @@ export class IrlNet {
setGhost(ghost, avatar) {
this.ghost = ghost === true;
if (avatar !== undefined) this.avatar = avatar || '';
- if (this.status !== 'online' || !this.room) return;
+ if (this.status !== 'online' || !this.room || this.room.connection?.isOpen !== true) return;
try {
this.room.send('set_ghost', { ghost: this.ghost, avatar: this.ghost ? this.avatar : '' });
} catch (e) {
diff --git a/src/stage-net.js b/src/stage-net.js
index 73b40fdc8..9c2b13050 100644
--- a/src/stage-net.js
+++ b/src/stage-net.js
@@ -177,7 +177,12 @@ export class StageNet {
this._emit('host', snapshotHost(this.room.state.host));
this._emitLeaderboard();
this._queueAudience();
- this._hb = setInterval(() => { try { this.room?.send('heartbeat'); } catch {} }, 15_000);
+ // connection.isOpen catches the CLOSING/CLOSED window before onLeave
+ // fires — ws.send() there logs a console warning instead of throwing.
+ this._hb = setInterval(() => {
+ if (this.room?.connection?.isOpen !== true) return;
+ try { this.room.send('heartbeat'); } catch {}
+ }, 15_000);
this._setStatus('online');
} catch (err) {
@@ -204,14 +209,14 @@ export class StageNet {
}
react(emoji) {
- if (this.status !== 'online' || !this.room) return;
+ if (this.status !== 'online' || this.room?.connection?.isOpen !== true) return;
try { this.room.send('reaction', { emoji: String(emoji) }); } catch (e) {
log.warn('[stage-net] reaction send failed:', e?.message || e);
}
}
ask(text) {
- if (this.status !== 'online' || !this.room) return false;
+ if (this.status !== 'online' || this.room?.connection?.isOpen !== true) return false;
try { this.room.send('question', { text: String(text) }); return true; } catch (e) {
log.warn('[stage-net] question send failed:', e?.message || e);
return false;
diff --git a/src/walk-net.js b/src/walk-net.js
index f30d8f417..6d007a05d 100644
--- a/src/walk-net.js
+++ b/src/walk-net.js
@@ -259,6 +259,18 @@ export class WalkNet {
*
* @param {{ x:number, y:number, z:number, yaw:number, motion:string }} state
*/
+ // Send a message only when the wire is actually open. `this.room` alone isn't
+ // enough: between the socket entering CLOSING and onLeave firing, the room
+ // reference is still live, and ws.send() on that socket logs a console
+ // warning per message ("WebSocket is already in CLOSING or CLOSED state").
+ // Returns true when the message reached an open socket.
+ _send(type, payload) {
+ const room = this.room;
+ if (!room || room.connection?.isOpen !== true) return false;
+ try { room.send(type, payload); } catch { return false; }
+ return true;
+ }
+
sendState(state) {
if (!this.room) return;
const now = performance.now();
@@ -276,36 +288,36 @@ export class WalkNet {
if (positionStill && yawStill && motionSame) return;
}
- this.room.send('move', {
+ if (!this._send('move', {
x: state.x,
y: state.y,
z: state.z,
yaw: state.yaw,
motion: state.motion,
- });
+ })) return;
this._lastSent = { ...state };
this._lastSentAt = now;
}
rename(name) {
this.name = name;
- this.room?.send('rename', { name });
+ this._send('rename', { name });
}
sendEmote(name) {
- this.room?.send('emote', { name });
+ this._send('emote', { name });
}
sendChat(text) {
const t = String(text || '').trim().slice(0, 200);
- if (t) this.room?.send('chat', { text: t });
+ if (t) this._send('chat', { text: t });
}
/** Swap this player's avatar mid-session (after picking a new one). */
sendAvatar(avatar, agent) {
this.avatar = avatar || this.avatar;
if (agent != null) this.agent = agent;
- this.room?.send('avatar', { avatar: this.avatar, agent: this.agent });
+ this._send('avatar', { avatar: this.avatar, agent: this.agent });
}
/** Force a reconnect (e.g. after the user clicks the offline pill). */
diff --git a/src/walk.js b/src/walk.js
index 3ab38c1a7..1ebcaa50c 100644
--- a/src/walk.js
+++ b/src/walk.js
@@ -1185,6 +1185,12 @@ window.addEventListener('keydown', (e) => {
e.preventDefault();
toggleMinimap();
break;
+ case 'KeyI':
+ // Inspect the nearest player (or yourself): identity, reputation,
+ // wallet. Press again to close.
+ e.preventDefault();
+ if (!e.repeat) inspectNearestPlayer();
+ break;
case 'KeyZ':
e.preventDefault();
toggleZen();
@@ -2912,6 +2918,56 @@ const REMOTE_YAW_LERP = 0.18;
/** @type {Map<string, RemotePlayer>} */
const remotePlayers = new Map();
+// ── Avatar inspector ──────────────────────────────────────────────────────
+// I (or clicking a nameplate) opens the shared inspector on a player: who they
+// are, the agent they pilot, their reputation and wallet — the same server
+// truth every other surface reads. See src/shared/avatar-inspector.js.
+function worldInspectFacts() {
+ if (COIN_PARAMS.coin) {
+ return [{
+ label: 'World',
+ value: COIN_PARAMS.symbol ? `$${COIN_PARAMS.symbol}` : COIN_PARAMS.name || 'Coin world',
+ href: `/temporary?coin=${encodeURIComponent(COIN_PARAMS.coin)}`,
+ }];
+ }
+ return [{ label: 'World', value: GALLERY_MODE ? 'Marketplace hall' : 'Mainland' }];
+}
+function inspectRemotePlayer(rp) {
+ if (!rp) return;
+ openAvatarInspector({
+ kind: 'peer',
+ name: rp.name,
+ world: COIN_PARAMS.coin ? 'coin world' : 'walk',
+ agentId: rp.agent || '',
+ wallet: rp.account || '',
+ avatarUrl: rp._avatarUrl,
+ facts: worldInspectFacts(),
+ }, { trigger: canvas });
+}
+function inspectSelfPlayer() {
+ openAvatarInspector({
+ kind: 'self',
+ name: nameInput?.value?.trim() || getStoredName() || 'You',
+ world: COIN_PARAMS.coin ? 'coin world' : 'walk',
+ agentId: COIN_PARAMS.agent || avatarMeta?.agent_id || '',
+ avatarUrl: resolvedAvatarUrl,
+ facts: worldInspectFacts(),
+ }, { trigger: canvas });
+}
+// Nearest player within reach of your avatar; yourself when alone — the I key
+// always answers.
+function inspectNearestPlayer() {
+ if (isAvatarInspectorOpen()) { closeAvatarInspector(); return; }
+ const MAX_M = 10;
+ let best = null;
+ for (const rp of remotePlayers.values()) {
+ const d = Math.hypot(rp.rig.position.x - avatarRig.position.x, rp.rig.position.z - avatarRig.position.z);
+ if (d <= MAX_M && (!best || d < best.d)) best = { d, rp };
+ }
+ if (best) inspectRemotePlayer(best.rp);
+ else inspectSelfPlayer();
+}
+
// In-world wallet reveal: walk up to a player piloting an agent and its wallet
// (vanity address, live value, tip) rises beside the nameplate. Frugal by design
// — one card, throttled proximity scan, cached embed reads. See walk-wallet.js.
@@ -3437,6 +3493,7 @@ function startNet() {
color: player.color,
avatar: player.avatar,
agent: player.agent,
+ account: player.account,
cosmetics: player.cosmetics,
}),
);