diff --git a/app/srv/ws/sync/actions/activity.ts b/app/srv/ws/sync/actions/activity.ts index 46535a2d..f1935943 100644 --- a/app/srv/ws/sync/actions/activity.ts +++ b/app/srv/ws/sync/actions/activity.ts @@ -1,41 +1,9 @@ -import { validate } from "uuid"; import { SAction } from "../actions"; -import { actstore, broadcastActivity } from "../entity/actstore"; -import { Activity, SyncConnection } from "../type"; +import { SyncConnection } from "../type"; export const activity: SAction["activity"] = async function ( this: SyncConnection, target, kind, act -) { - const key = (target.page_id ? "page_id" : "comp_id") as "page_id" | "comp_id"; - const type = (target.page_id ? "page" : "comp") as "page" | "comp"; - const tkey = target[key]; - if (!tkey) return; - if (validate(tkey)) { - if (!actstore[type][tkey]) actstore[type][tkey] = {}; - - if (!actstore[type][tkey][target.item_id]) - actstore[type][tkey][target.item_id] = {}; - - if (!actstore[type][tkey][target.item_id][kind]) - actstore[type][tkey][target.item_id][kind] = {}; - - const obj = actstore[type][tkey][target.item_id][kind]; - if (obj) { - if (act === Activity.Null) { - delete obj[this.client_id]; - if (Object.keys(obj).length === 0) { - delete actstore[type][tkey][target.item_id][kind]; - - if (Object.keys(actstore[type][tkey][target.item_id]).length === 0) { - delete actstore[type][tkey][target.item_id]; - } - } - } else obj[this.client_id] = act; - } - - broadcastActivity({ [key]: tkey }); - } -}; +) {}; diff --git a/app/srv/ws/sync/actions/page_load.ts b/app/srv/ws/sync/actions/page_load.ts index 57e0fc6c..64a6d0df 100644 --- a/app/srv/ws/sync/actions/page_load.ts +++ b/app/srv/ws/sync/actions/page_load.ts @@ -7,7 +7,6 @@ import { user } from "../entity/user"; import { gzipAsync } from "../entity/zlib"; import { sendWS } from "../sync-handler"; import { Activity, SyncConnection, SyncType } from "../type"; -import { actstore, broadcastActivity } from "../entity/actstore"; export const page_load: SAction["page"]["load"] = async function ( this: SyncConnection, @@ -19,34 +18,6 @@ export const page_load: SAction["page"]["load"] = async function ( const conf = this.conf; if (!conf) return undefined; - if (!actstore.page[id]) { - actstore.page[id] = { - load: { - root: { - [this.client_id]: Activity.Open, - }, - }, - }; - } else { - const load = actstore.page[id]["load"]; - if (load && load.root) { - load.root[this.client_id] = Activity.Open; - } - } - if (conf.page_id !== id && actstore.page[conf.page_id]) { - const load = actstore.page[conf.page_id]["load"]; - if (load && load.root) { - delete load.root[this.client_id]; - } - - broadcastActivity( - { - page_id: conf.page_id, - }, - [this.client_id] - ); - } - conf.page_id = id; const createUndoManager = async (root: Y.Map) => { @@ -120,10 +91,6 @@ export const page_load: SAction["page"]["load"] = async function ( page_id: page.id, }); - broadcastActivity({ - page_id: id, - }); - return { id: id, url: page.url, @@ -154,10 +121,6 @@ export const page_load: SAction["page"]["load"] = async function ( page_id: snap.id, }); - broadcastActivity({ - page_id: id, - }); - return { id: id, url: snap.url, @@ -173,10 +136,6 @@ export const page_load: SAction["page"]["load"] = async function ( page_id: snap.id, }); - broadcastActivity({ - page_id: id, - }); - return { id: snap.id, url: snap.url, diff --git a/app/srv/ws/sync/entity/activity.ts b/app/srv/ws/sync/entity/activity.ts index d4b4af41..3ca99f44 100644 --- a/app/srv/ws/sync/entity/activity.ts +++ b/app/srv/ws/sync/entity/activity.ts @@ -1,5 +1,5 @@ -import { Room } from "./room"; +import { Room, RoomList } from "./room"; export const activity = { - site: {} as Record>, + site: new RoomList<{ code: { name: string } }>(), }; diff --git a/app/srv/ws/sync/entity/actstore.ts b/app/srv/ws/sync/entity/actstore.ts deleted file mode 100644 index 3ab9739e..00000000 --- a/app/srv/ws/sync/entity/actstore.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { ServerWebSocket } from "bun"; -import { WSData } from "../../../../../pkgs/core/server/create"; -import { sendWS } from "../sync-handler"; -import { ActivityList, CLIENT_ID, COMP_ID, PAGE_ID, SyncType } from "../type"; -import { conns } from "./conn"; -import { user } from "./user"; - -export const actstore = { - page: {} as Record, - comp: {} as Record, -}; - -export const broadcastActivity = ( - arg: { page_id?: string; comp_id?: string }, - exclude?: CLIENT_ID[] -) => { - const wss = new Set>(); - const data = {} as any; - if (arg.page_id) { - data.page = actstore.page[arg.page_id] || {}; - user.active.findAll({ page_id: arg.page_id }).forEach((u) => { - if (u.client_id && (!exclude || !exclude.includes(u.client_id))) { - const ws = conns.get(u.client_id)?.ws; - if (ws) wss.add(ws); - } - }); - } - if (arg.comp_id) { - data.comp = actstore.page[arg.comp_id] || {}; - user.active.findAll({ comp_id: arg.comp_id }).forEach((u) => { - if (u.client_id && (!exclude || !exclude.includes(u.client_id))) { - const ws = conns.get(u.client_id)?.ws; - if (ws) { - wss.add(ws); - } - } - }); - } - wss.forEach((ws) => { - sendWS(ws, { - type: SyncType.Event, - event: "activity", - data, - }); - }); -}; diff --git a/app/srv/ws/sync/entity/room.ts b/app/srv/ws/sync/entity/room.ts index b45788ce..495b4568 100644 --- a/app/srv/ws/sync/entity/room.ts +++ b/app/srv/ws/sync/entity/room.ts @@ -2,6 +2,13 @@ import { ServerWebSocket } from "bun"; import { WSData } from "../../../../../pkgs/core/server/create"; import { conns } from "./conn"; +export const RoomList = class< + T extends Record>, +> { + rooms = new Map>(); + constructor() {} +}; + export class Room>> { name = ""; clients = new Map, Partial>(); @@ -30,12 +37,17 @@ export class Room>> { return clients; } - do( - where: Partial, - action: (ws: ServerWebSocket, data: Partial) => void + set( + client: { ws?: ServerWebSocket; id?: string }, + action: (ws: ServerWebSocket, data: Partial) => Partial ) { - for (const [ws, data] of this.findAll(where)) { - action(ws, data); + const ws = this.identify(client); + if (ws) { + const data = this.clients.get(ws); + if (data) { + const newdata = action(ws, data); + this.clients.set(ws, newdata); + } } } diff --git a/app/srv/ws/sync/sync-handler.ts b/app/srv/ws/sync/sync-handler.ts index cb636b67..b7a5fe6a 100644 --- a/app/srv/ws/sync/sync-handler.ts +++ b/app/srv/ws/sync/sync-handler.ts @@ -10,7 +10,6 @@ import { loadSitePage } from "./editor/load-sitepage"; import { conns, wconns } from "./entity/conn"; import { UserConf, user } from "./entity/user"; import { SyncType } from "./type"; -import { actstore, broadcastActivity } from "./entity/actstore"; const packr = new Packr({ structuredClone: true }); export const sendWS = (ws: ServerWebSocket, msg: any) => { @@ -34,21 +33,6 @@ export const syncHandler: WebSocketHandler = { if (client_id) { conns.delete(client_id); wconns.delete(ws); - - for (const p of Object.values(actstore)) { - for (const q of Object.values(p)) { - for (const r of Object.values(q)) { - for (const s of Object.values(r)) { - delete s[client_id]; - } - } - } - } - const u = user.active.find(client_id); - if (u) { - user.active.del(client_id); - broadcastActivity({ page_id: u.page_id, comp_id: u.comp_id }); - } } }, async message(ws, raw) { @@ -94,9 +78,7 @@ export const syncHandler: WebSocketHandler = { if (actionName) { const baseAction = (actions as any)[actionName]; if (!baseAction) { - console.log( - `app/srv/ws/sync/actions/${actionName}.ts not found` - ); + console.log(`app/srv/ws/sync/actions/${actionName}.ts not found`); } if (baseAction) { const action = baseAction.bind(conn); diff --git a/app/web/src/render/live/live.tsx b/app/web/src/render/live/live.tsx index e459169c..afb6b7c3 100644 --- a/app/web/src/render/live/live.tsx +++ b/app/web/src/render/live/live.tsx @@ -5,6 +5,7 @@ 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 { Loading } from "../../utils/ui/loading"; export const Live: FC<{ domain_or_siteid: string; @@ -34,6 +35,7 @@ export const Live: FC<{ } } } + const onResize = useCallback(() => { let newmode = p.mode; if (window.innerWidth < 600) newmode = "mobile"; @@ -63,6 +65,12 @@ export const Live: FC<{ routeLive(p, pathname); } + if (!p.mode) return ; + else { + w.isMobile = p.mode === "mobile"; + w.isDesktop = p.mode === "desktop"; + } + if (p.status === "not-found") return (
diff --git a/app/web/src/render/live/logic/init.tsx b/app/web/src/render/live/logic/init.tsx index f25f590d..18f17f08 100644 --- a/app/web/src/render/live/logic/init.tsx +++ b/app/web/src/render/live/logic/init.tsx @@ -37,8 +37,6 @@ export const initLive = async (p: PG, domain_or_siteid: string) => { w.isEditor = false; w.isLayout = true; - w.isMobile = p.mode === "mobile"; - w.isDesktop = p.mode === "desktop"; w.apiHeaders = {}; w.navigateOverride = (_href) => {