Skip to content

Commit

Permalink
chore: debug broadcastMessage on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ynwd committed Dec 6, 2024
1 parent cbd3e84 commit c8ce7ea
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions modules/socket/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export default function socketModule(s: Fastro) {

for (const key in entries) {
const [, { value: { socket } }] = entries[key];
if (socket.readyState === WebSocket.OPEN) {
socket.send(JSON.stringify(connected));
}
socket.send(JSON.stringify(connected));
}
}

Expand All @@ -58,8 +56,8 @@ export default function socketModule(s: Fastro) {
data: Data,
) {
const connected = ctx.stores.get("connected");
console.log("joinRoom-connected", connected);
console.log("joinRoom-data", data);
// console.log("joinRoom-connected", connected);
// console.log("joinRoom-data", data);
if (data.user) {
connected?.set(data.user, { data, socket });
}
Expand Down Expand Up @@ -89,6 +87,10 @@ export default function socketModule(s: Fastro) {
};

socket.onmessage = async (event) => {
if (socket.readyState !== WebSocket.OPEN) {
console.log("socket.readyState", socket.readyState);
return;
}
const data: Data = JSON.parse(event.data);
if (data.type === "ping") {
await joinRoom(ctx, socket, data);
Expand Down

0 comments on commit c8ce7ea

Please sign in to comment.