fix(games): send room state directly to joining client
Some checks failed
Deploy to Production / test (push) Failing after 35s

Bun's ws.publish() excludes the sender, so the joining client never
received the PLAYER_JOINED message and stayed stuck on the connecting
spinner. Now sends the message directly to the joiner via ctx.send
in addition to publishing to other room subscribers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
syntaxbullet
2026-04-02 13:56:24 +02:00
parent cac9fae142
commit 9f105ada5e

View File

@@ -37,11 +37,15 @@ export function handleGameMessage(msg: GameWsClientMessage, ctx: WsContext): voi
ctx.subscribe(`room:${msg.roomId}`);
const playerInfo: PlayerInfo = { discordId: ctx.playerId, username: ctx.username };
ctx.publish(`room:${msg.roomId}`, JSON.stringify({ type: "PLAYER_JOINED", roomId: msg.roomId, player: playerInfo, as: msg.as }));
const joinedMsg = JSON.stringify({ type: "PLAYER_JOINED", roomId: msg.roomId, player: playerInfo, as: msg.as });
ctx.publish(`room:${msg.roomId}`, joinedMsg);
ctx.send(joinedMsg);
if (result.started) {
const spectatorView = roomManager.getSpectatorView(msg.roomId);
ctx.publish(`room:${msg.roomId}`, JSON.stringify({ type: "GAME_STARTED", roomId: msg.roomId, state: spectatorView }));
const startedMsg = JSON.stringify({ type: "GAME_STARTED", roomId: msg.roomId, state: spectatorView });
ctx.publish(`room:${msg.roomId}`, startedMsg);
ctx.send(startedMsg);
} else {
const room = roomManager.getRoom(msg.roomId);
if (room && room.status === "playing") {