Using next-ws for better code structure

This commit is contained in:
2026-02-09 13:41:03 +01:00
parent 07156ec598
commit 6c9b703ed1
7 changed files with 99 additions and 176 deletions
+17
View File
@@ -4,6 +4,7 @@ import "server-only";
import { LiveRun, LiveRunMove } from "./types";
import { SupabaseClient } from "@supabase/supabase-js";
import { redis } from "@/lib/redis";
import Redis from "ioredis";
/** -------------------- Live Runs in Redis -------------------- */
@@ -43,6 +44,22 @@ export async function removeLiveRun(id: string) {
await redis.del(`liveRun:${id}`, `liveRunMoves:${id}`);
}
/** -------------------- Live Run Moves -------------------- */
/**
* Add moves to a live run (ephemeral)
*/
export async function addLiveRunMoves(runId: string, moves: LiveRunMove[]) {
const runExists = await redis.exists(`liveRun:${runId}`);
if (!runExists) throw "Invalid live run";
const publisher = new Redis();
// Send a message
await publisher.publish(`liveRunMoves:${runId}`, JSON.stringify(moves));
}
/** -------------------- Submit Run -------------------- */
/**