Text stability sync

This commit is contained in:
2026-02-16 01:38:53 +01:00
parent d5cc2f47a3
commit af464fa3a1
3 changed files with 21 additions and 2 deletions
+14
View File
@@ -5,6 +5,7 @@ import { getSession } from "@/modules/account/core";
import * as Core from "@/modules/live-run/core"; import * as Core from "@/modules/live-run/core";
import { ClientMessage } from "./types"; import { ClientMessage } from "./types";
import { NextRequest } from "next/server"; import { NextRequest } from "next/server";
import { redis } from "@/lib/redis";
export function GET(req: NextRequest) { export function GET(req: NextRequest) {
const headers = new Headers(); const headers = new Headers();
@@ -204,6 +205,19 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) {
break; break;
} }
case "getText":
const { runId } = msg;
const data = await redis.get(`liveRunText:${runId}`);
client.send(
JSON.stringify({
requestId,
ok: true,
data,
}),
);
break;
default: default:
client.send( client.send(
JSON.stringify({ JSON.stringify({
+4
View File
@@ -21,6 +21,10 @@ export type ClientMessage = { requestId: string } & (
type: "delete"; type: "delete";
runId: string; runId: string;
} }
| {
type: "getText";
runId: string;
}
); );
export type ServerMessage = export type ServerMessage =
+3 -2
View File
@@ -2,7 +2,8 @@ import { WebSocketServer, WebSocket } from "ws";
import Redis from "ioredis"; import Redis from "ioredis";
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { LiveRunEvent } from "@/modules/live-run/types"; import { LiveRunEvent } from "@/modules/live-run/types";
import { getLiveRun, updateLiveRunViews } from "@/modules/live-run/core"; import { updateLiveRunViews } from "@/modules/live-run/core";
import { redis } from "@/lib/redis";
export function GET(req: NextRequest) { export function GET(req: NextRequest) {
const headers = new Headers(); const headers = new Headers();
@@ -23,7 +24,7 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) {
let lastEvent: LiveRunEvent | null = null; let lastEvent: LiveRunEvent | null = null;
const sendText = async () => { const sendText = async () => {
const text = await subscriber.get(`liveRunText:${runId}`); const text = await redis.get(`liveRunText:${runId}`);
if (client.readyState === WebSocket.OPEN) { if (client.readyState === WebSocket.OPEN) {
client.send( client.send(