set page
This commit is contained in:
parent
64fd838df2
commit
79a70e6c8d
|
|
@ -11,9 +11,9 @@ export const activity: SAction["activity"] = async function (
|
||||||
if (act.type === "code") {
|
if (act.type === "code") {
|
||||||
a.site.room(act.id).set(me, (ws, data) => {
|
a.site.room(act.id).set(me, (ws, data) => {
|
||||||
if (act.action === "open") {
|
if (act.action === "open") {
|
||||||
data.code = { name: act.name };
|
data.site_js = act.name;
|
||||||
} else {
|
} else {
|
||||||
delete data.code;
|
delete data.site_js;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { SAction } from "../actions";
|
import { SAction } from "../actions";
|
||||||
|
import { activity } from "../entity/activity";
|
||||||
import { conns } from "../entity/conn";
|
import { conns } from "../entity/conn";
|
||||||
import { docs } from "../entity/docs";
|
import { docs } from "../entity/docs";
|
||||||
import { snapshot } from "../entity/snapshot";
|
import { snapshot } from "../entity/snapshot";
|
||||||
|
|
@ -54,9 +55,19 @@ export const page_load: SAction["page"]["load"] = async function (
|
||||||
select: "" as "" | "comp" | "item" | "section" | "text",
|
select: "" as "" | "comp" | "item" | "section" | "text",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setActivityPage = (id_site: string, id_page: string) => {
|
||||||
|
activity.site.set(id_site, this.ws, (data) => {
|
||||||
|
data.page_id = id_page;
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (!snap && !ydoc) {
|
if (!snap && !ydoc) {
|
||||||
const page = await db.page.findFirst({ where: { id } });
|
const page = await db.page.findFirst({ where: { id } });
|
||||||
|
|
||||||
if (page) {
|
if (page) {
|
||||||
|
setActivityPage(page.id_site, page.id);
|
||||||
|
|
||||||
const doc = new Y.Doc();
|
const doc = new Y.Doc();
|
||||||
let root = doc.getMap("map");
|
let root = doc.getMap("map");
|
||||||
syncronize(root, { id, root: page.content_tree });
|
syncronize(root, { id, root: page.content_tree });
|
||||||
|
|
@ -100,6 +111,8 @@ export const page_load: SAction["page"]["load"] = async function (
|
||||||
} else if (snap && !ydoc) {
|
} else if (snap && !ydoc) {
|
||||||
const doc = new Y.Doc();
|
const doc = new Y.Doc();
|
||||||
snapshot.set("page", id, "id_doc", doc.clientID);
|
snapshot.set("page", id, "id_doc", doc.clientID);
|
||||||
|
setActivityPage(snap.id_site, id);
|
||||||
|
|
||||||
Y.applyUpdate(doc, snap.bin);
|
Y.applyUpdate(doc, snap.bin);
|
||||||
let root = doc.getMap("map");
|
let root = doc.getMap("map");
|
||||||
|
|
||||||
|
|
@ -127,6 +140,8 @@ export const page_load: SAction["page"]["load"] = async function (
|
||||||
snapshot: await gzipAsync(snap.bin),
|
snapshot: await gzipAsync(snap.bin),
|
||||||
};
|
};
|
||||||
} else if (snap && ydoc) {
|
} else if (snap && ydoc) {
|
||||||
|
setActivityPage(snap.id_site, id);
|
||||||
|
|
||||||
user.active.add({
|
user.active.add({
|
||||||
...defaultActive,
|
...defaultActive,
|
||||||
client_id: this.client_id,
|
client_id: this.client_id,
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,9 @@ import { RoomList } from "./room";
|
||||||
|
|
||||||
export const activity = {
|
export const activity = {
|
||||||
site: new RoomList<{
|
site: new RoomList<{
|
||||||
code: {
|
site_js: string;
|
||||||
name: string;
|
page_id: string;
|
||||||
};
|
item_id: string;
|
||||||
page: { id: string };
|
item_action: "select" | "js" | "css" | "html";
|
||||||
comp: { id: string };
|
|
||||||
item: { id: string; js: boolean; css: boolean; html: boolean };
|
|
||||||
}>("site"),
|
}>("site"),
|
||||||
};
|
};
|
||||||
|
|
@ -4,7 +4,7 @@ import { conns, wconns } from "./conn";
|
||||||
import { sendWS } from "../sync-handler";
|
import { sendWS } from "../sync-handler";
|
||||||
import { SyncType } from "../type";
|
import { SyncType } from "../type";
|
||||||
|
|
||||||
export const RoomList = class<T extends Record<string, any>> {
|
export const RoomList = class<T extends Record<string, string>> {
|
||||||
rooms = new Map<string, Room<T>>();
|
rooms = new Map<string, Room<T>>();
|
||||||
name = "";
|
name = "";
|
||||||
constructor(name: string) {
|
constructor(name: string) {
|
||||||
|
|
@ -20,7 +20,7 @@ export const RoomList = class<T extends Record<string, any>> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return rooms;
|
return rooms;
|
||||||
}
|
}
|
||||||
disconnect(ws: ServerWebSocket<WSData>) {
|
disconnect(ws: ServerWebSocket<WSData>) {
|
||||||
this.rooms.forEach((room) => {
|
this.rooms.forEach((room) => {
|
||||||
room.clients.forEach((_, roomws) => {
|
room.clients.forEach((_, roomws) => {
|
||||||
|
|
@ -30,6 +30,20 @@ export const RoomList = class<T extends Record<string, any>> {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set(
|
||||||
|
id: string,
|
||||||
|
ws: ServerWebSocket<WSData>,
|
||||||
|
fn: (data: Partial<T>) => Partial<T>
|
||||||
|
) {
|
||||||
|
const room = this.room(id);
|
||||||
|
if (room) {
|
||||||
|
room.set({ ws }, (ws, data) => {
|
||||||
|
return fn(data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
room(id: string) {
|
room(id: string) {
|
||||||
let room = this.rooms.get(id);
|
let room = this.rooms.get(id);
|
||||||
if (!room) {
|
if (!room) {
|
||||||
|
|
@ -56,16 +70,9 @@ export class Room<T extends Record<string, any>> {
|
||||||
for (const [ws, data] of this.clients) {
|
for (const [ws, data] of this.clients) {
|
||||||
let match = true;
|
let match = true;
|
||||||
for (const key in where) {
|
for (const key in where) {
|
||||||
if (where[key] === true) {
|
if (data[key] !== where[key]) {
|
||||||
if (!data[key]) {
|
match = false;
|
||||||
match = false;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (data[key] !== where[key]) {
|
|
||||||
match = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match) clients.set(ws, data);
|
if (match) clients.set(ws, data);
|
||||||
|
|
@ -122,6 +129,8 @@ export class Room<T extends Record<string, any>> {
|
||||||
this.clients.forEach((data, ws) => {
|
this.clients.forEach((data, ws) => {
|
||||||
const client_id = wconns.get(ws);
|
const client_id = wconns.get(ws);
|
||||||
if (client_id) {
|
if (client_id) {
|
||||||
|
console.log(event_name, client_id, data);
|
||||||
|
|
||||||
const client = conns.get(client_id);
|
const client = conns.get(client_id);
|
||||||
if (client)
|
if (client)
|
||||||
clients.push({
|
clients.push({
|
||||||
|
|
@ -135,7 +144,7 @@ export class Room<T extends Record<string, any>> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.clients.forEach((data, ws) => {
|
this.clients.forEach((_, ws) => {
|
||||||
sendWS(ws, {
|
sendWS(ws, {
|
||||||
type: SyncType.Event,
|
type: SyncType.Event,
|
||||||
event: `${this.id}_${event_name}`,
|
event: `${this.id}_${event_name}`,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { compress, decompress } from "wasm-gzip";
|
import { compress, decompress } from "wasm-gzip";
|
||||||
import { deepClone } from "web-utils";
|
import { deepClone } from "web-utils";
|
||||||
import { Y } from "../../../../../srv/ws/sync/entity/docs";
|
import * as Y from "yjs";
|
||||||
import { clientStartSync } from "../../../utils/sync/ws-client";
|
import { clientStartSync } from "../../../utils/sync/ws-client";
|
||||||
import { w } from "../../../utils/types/general";
|
import { w } from "../../../utils/types/general";
|
||||||
import { Loading } from "../../../utils/ui/loading";
|
import { Loading } from "../../../utils/ui/loading";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue