fix broadcast

This commit is contained in:
Rizky 2023-11-05 22:23:25 +07:00
parent 79a70e6c8d
commit 6154d13202
3 changed files with 19 additions and 2 deletions

View File

@ -41,6 +41,8 @@ export const RoomList = class<T extends Record<string, string>> {
room.set({ ws }, (ws, data) => {
return fn(data);
});
room.broadcastState("set", ws);
}
}
@ -147,8 +149,8 @@ export class Room<T extends Record<string, any>> {
this.clients.forEach((_, ws) => {
sendWS(ws, {
type: SyncType.Event,
event: `${this.id}_${event_name}`,
data: { clients },
event: `activity`,
data: { activity: event_name, room_id: this.id, clients },
});
});
};

View File

@ -61,6 +61,9 @@ export const edInitSync = (p: PG) => {
site_id: params.site_id,
page_id: params.page_id,
events: {
activity(arg) {
console.log(arg);
},
opened() {
if (w.offline) {
console.log("reconnected!");

View File

@ -75,6 +75,18 @@ export const clientStartSync = async (arg: {
site_id?: string;
page_id?: string;
events: {
activity: (arg: {
activity: string;
room_id: string;
clients: {
user: {
client_id: string;
user_id: string;
username: string;
};
data: any;
}[];
}) => void;
editor_start: (arg: UserConf) => void;
remote_svlocal: (arg: {
type: "page" | "comp";