import type { PartySocketEvent, PartyState, } from "../api/src/party-types"; let ws: WebSocket | null = null; Bun.listen({ hostname: "0.0.0.0", port: 7070, socket: { data(socket, data) { // in1={} in2={} in3={} in4={} angle={} console.log("recv", data) }, // message received from client open(socket) { console.log("Connected"); ws = new WebSocket("ws://localhost:3000/api/dev-socket/ws"); ws.onmessage = e => { const data = JSON.parse(e.data) as PartySocketEvent; switch (data.type) { case "party_status": const { party: { data: { currentQuestion } } } = data; console.log(currentQuestion) let text = currentQuestion?.text if (text) { ws?.send(text) } break; } } }, // socket opened close(socket, error) { ws?.close(); ws = null; }, // socket closed drain(socket) {}, // socket ready for more data error(socket, error) {}, // error handler }, }); console.log("Started on :7070")