import { defineWebSocket, eventHandler } from "vinxi/http";// Array of peersexport const peers: any = [];export default eventHandler({ handler: () => {}, websocket: defineWebSocket({ async open(peer) { // Add peer to the list of active peers.push(peer); console.log("WebSocket opened"); }, async message(peer, event) { console.log("WebSocket message", event); peer.send("YOOO"); }, async close(peer) { console.log("WebSocket closed 3"); // Delete peer from the list of active const index = peers.indexOf(peer); if (index !== -1) { peers.splice(index, 1); } }, }),});
export const EmrErrorSchema = object({ id: optional(string()), hostname: string([minLength(1)]), emr: number(), errorMessage: string([minLength(1)]), nameErrorMessage: string([minLength(1)]), errorCategoryId: string(),});
<TextFieldInput name="emr" color="neutral" placeholder="1" type="number" variant="bordered" />
export async function updateOrCreateEmrErrorServerAction(form: FormData) { const decoded = decode(form); const parsed = await safeParseAsync(EmrErrorSchema, decoded); if (!parsed.success) { return rpcParseIssueResult(parsed.issues); } const { id, hostname, emr, errorMessage, nameErrorMessage, errorCategoryId } = parsed.output; if (id) { await db_client.emrError.update({ where: { id }, data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId } }); return reload({revalidate:EMR_ERRORS_CACHE_KEY}); } else { await db_client.emrError.create({ data: { hostname, emr, errorMessage, nameErrorMessage, errorCategoryId } }); return reload({revalidate:EMR_ERRORS_CACHE_KEY}); }}