This commit is contained in:
Rizky 2023-10-19 04:28:10 +00:00
parent 6463a01ccb
commit ca925f4b26
3 changed files with 0 additions and 49 deletions

View File

@ -24,23 +24,6 @@ const site = {
const brotli = await brotliPromise;
export const wsHandler: Record<string, WebSocketHandler<WSData>> = {
"/live": {
async open(ws) {
ws.send(
brotli.compress(
Buffer.from(
JSON.stringify(
await db.page.findFirst({
where: { id: "324dde34-1e01-46ff-929c-124e5e01f585" },
})
)
),
{ quality: 11 }
)
);
},
message(ws, message) {},
},
"/edit": {
open(ws) {
eg.edit.ws.set(ws, {

View File

@ -5,7 +5,6 @@ import { LPage } from "./elements/l-page";
import { LiveGlobal, Loader } from "./logic/global";
import { initLive, w } from "./logic/init";
import { preload, routeLive } from "./logic/route";
import { liveSyncWS } from "./logic/ws-sync";
export const Live: FC<{
domain_or_siteid: string;
@ -57,9 +56,6 @@ export const Live: FC<{
}, [p.site.responsive]);
if (p.status === "init") {
if (liveSync) {
liveSyncWS(p);
}
initLive(p, domain_or_siteid);
}

View File

@ -1,28 +0,0 @@
import { PG } from "./global";
export const liveSyncWS = async (p: PG) => {
if (!p.liveSync.init) {
p.liveSync.init = true;
if (!p.liveSync.decompress) {
const brotliPromise = (await import("brotli-dec-wasm")).default;
p.liveSync.decompress = (await brotliPromise).decompress;
}
const decoder = new TextDecoder();
const url = new URL(location.href);
url.pathname = "/live";
url.protocol = url.protocol === "http:" ? "ws:" : "wss:";
const ws = new WebSocket(url);
p.liveSync.ws = ws;
ws.onmessage = async (e) => {
const decompress = p.liveSync.decompress;
if (decompress) {
const raw = e.data as Blob;
const extracted = decompress(new Uint8Array(await raw.arrayBuffer()));
const json = JSON.parse(decoder.decode(extracted));
console.log(json);
}
};
}
};