Text stability sync
This commit is contained in:
@@ -5,6 +5,7 @@ import { getSession } from "@/modules/account/core";
|
||||
import * as Core from "@/modules/live-run/core";
|
||||
import { ClientMessage } from "./types";
|
||||
import { NextRequest } from "next/server";
|
||||
import { redis } from "@/lib/redis";
|
||||
|
||||
export function GET(req: NextRequest) {
|
||||
const headers = new Headers();
|
||||
@@ -204,6 +205,19 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) {
|
||||
break;
|
||||
}
|
||||
|
||||
case "getText":
|
||||
const { runId } = msg;
|
||||
const data = await redis.get(`liveRunText:${runId}`);
|
||||
|
||||
client.send(
|
||||
JSON.stringify({
|
||||
requestId,
|
||||
ok: true,
|
||||
data,
|
||||
}),
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
client.send(
|
||||
JSON.stringify({
|
||||
|
||||
@@ -21,6 +21,10 @@ export type ClientMessage = { requestId: string } & (
|
||||
type: "delete";
|
||||
runId: string;
|
||||
}
|
||||
| {
|
||||
type: "getText";
|
||||
runId: string;
|
||||
}
|
||||
);
|
||||
|
||||
export type ServerMessage =
|
||||
|
||||
@@ -2,7 +2,8 @@ import { WebSocketServer, WebSocket } from "ws";
|
||||
import Redis from "ioredis";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
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) {
|
||||
const headers = new Headers();
|
||||
@@ -23,7 +24,7 @@ export function UPGRADE(client: WebSocket, server: WebSocketServer) {
|
||||
let lastEvent: LiveRunEvent | null = null;
|
||||
|
||||
const sendText = async () => {
|
||||
const text = await subscriber.get(`liveRunText:${runId}`);
|
||||
const text = await redis.get(`liveRunText:${runId}`);
|
||||
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(
|
||||
|
||||
Reference in New Issue
Block a user