Fix BroadcastChannel sending Encoded bytes

This commit is contained in:
Ayane Satomi 2023-10-22 16:43:51 +00:00
parent 4ea19cd5a0
commit c6f3decb45

View file

@ -34,6 +34,7 @@ export const handler: Handlers = {
}; };
bc.addEventListener("message", (e) => { bc.addEventListener("message", (e) => {
console.log(e);
socket.send(JSON.stringify({ globalCount: e.data })); socket.send(JSON.stringify({ globalCount: e.data }));
}); });
@ -66,8 +67,10 @@ export const handler: Handlers = {
const body = await req.json(); const body = await req.json();
await setGlobalStatistics(body.data); await setGlobalStatistics(body.data);
const updatedCount = await getGlobalStatistics();
const bc = new BroadcastChannel("global-count"); const bc = new BroadcastChannel("global-count");
bc.postMessage(new TextEncoder().encode(getGlobalStatistics().toString())); bc.postMessage(updatedCount.toString());
return new Response("", { return new Response("", {
status: 200, status: 200,