mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
namespace
This commit is contained in:
@@ -73,7 +73,7 @@ export function useExcalidrawCollab(
|
||||
};
|
||||
|
||||
const json = JSON.stringify(data);
|
||||
socket.emit("server-volatile-broadcast", [roomId, json, null]);
|
||||
socket.emit("ex-server-volatile-broadcast", [roomId, json, null]);
|
||||
},
|
||||
50,
|
||||
),
|
||||
@@ -114,7 +114,7 @@ export function useExcalidrawCollab(
|
||||
}
|
||||
|
||||
const json = JSON.stringify(data);
|
||||
socket.emit("server-broadcast", [roomId, json, null]);
|
||||
socket.emit("ex-server-broadcast", [roomId, json, null]);
|
||||
lastBroadcastedVersion.current = sceneVersion;
|
||||
},
|
||||
[socket, roomId],
|
||||
@@ -218,16 +218,16 @@ export function useExcalidrawCollab(
|
||||
}
|
||||
|
||||
console.log("Joining room:", roomId);
|
||||
socket.emit("join-room", roomId);
|
||||
socket.emit("ex-join-room", roomId);
|
||||
isInitialized.current = true;
|
||||
|
||||
// Set up listeners
|
||||
socket.on("client-broadcast", handleClientBroadcast);
|
||||
socket.on("room-user-change", handleRoomUserChange);
|
||||
socket.on("first-in-room", () => {
|
||||
socket.on("ex-client-broadcast", handleClientBroadcast);
|
||||
socket.on("ex-room-user-change", handleRoomUserChange);
|
||||
socket.on("ex-first-in-room", () => {
|
||||
console.log("First in excalidraw room");
|
||||
});
|
||||
socket.on("new-user", (socketId: string) => {
|
||||
socket.on("ex-new-user", (socketId: string) => {
|
||||
console.log("New user joined:", socketId);
|
||||
if (excalidrawAPI) {
|
||||
// Send full scene to new user (syncAll = true)
|
||||
@@ -237,11 +237,11 @@ export function useExcalidrawCollab(
|
||||
|
||||
return () => {
|
||||
console.log("Leaving room:", roomId);
|
||||
socket.emit("leave-room", roomId);
|
||||
socket.off("client-broadcast", handleClientBroadcast);
|
||||
socket.off("room-user-change", handleRoomUserChange);
|
||||
socket.off("first-in-room");
|
||||
socket.off("new-user");
|
||||
socket.emit("ex-leave-room", roomId);
|
||||
socket.off("ex-client-broadcast", handleClientBroadcast);
|
||||
socket.off("ex-room-user-change", handleRoomUserChange);
|
||||
socket.off("ex-first-in-room");
|
||||
socket.off("ex-new-user");
|
||||
isInitialized.current = false;
|
||||
lastBroadcastedVersion.current = -1;
|
||||
broadcastedElementVersions.current = new Map();
|
||||
|
||||
@@ -24,13 +24,13 @@ export class ExcalidrawCollabService {
|
||||
const sockets = await server.in(roomId).fetchSockets();
|
||||
|
||||
if (sockets.length <= 1) {
|
||||
server.to(client.id).emit('first-in-room');
|
||||
server.to(client.id).emit('ex-first-in-room');
|
||||
} else {
|
||||
client.broadcast.to(roomId).emit('new-user', client.id);
|
||||
client.broadcast.to(roomId).emit('ex-new-user', client.id);
|
||||
}
|
||||
|
||||
server.in(roomId).emit(
|
||||
'room-user-change',
|
||||
'ex-room-user-change',
|
||||
sockets.map((socket) => socket.id),
|
||||
);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export class ExcalidrawCollabService {
|
||||
const sockets = await server.in(roomId).fetchSockets();
|
||||
if (sockets.length > 0) {
|
||||
server.in(roomId).emit(
|
||||
'room-user-change',
|
||||
'ex-room-user-change',
|
||||
sockets.map((socket) => socket.id),
|
||||
);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export class ExcalidrawCollabService {
|
||||
encryptedData: ArrayBuffer,
|
||||
iv: Uint8Array,
|
||||
): void {
|
||||
client.broadcast.to(roomId).emit('client-broadcast', encryptedData, iv);
|
||||
client.broadcast.to(roomId).emit('ex-client-broadcast', encryptedData, iv);
|
||||
}
|
||||
|
||||
handleServerVolatileBroadcast(
|
||||
@@ -72,7 +72,7 @@ export class ExcalidrawCollabService {
|
||||
): void {
|
||||
client.volatile.broadcast
|
||||
.to(roomId)
|
||||
.emit('client-broadcast', encryptedData, iv);
|
||||
.emit('ex-client-broadcast', encryptedData, iv);
|
||||
}
|
||||
|
||||
async handleUserFollow(
|
||||
@@ -92,7 +92,7 @@ export class ExcalidrawCollabService {
|
||||
const followedBy = sockets.map((socket) => socket.id);
|
||||
|
||||
server.to(payload.userToFollow.socketId).emit(
|
||||
'user-follow-room-change',
|
||||
'ex-user-follow-room-change',
|
||||
followedBy,
|
||||
);
|
||||
}
|
||||
@@ -110,14 +110,14 @@ export class ExcalidrawCollabService {
|
||||
|
||||
if (!isFollowRoom && otherClients.length > 0) {
|
||||
server.to(roomId).emit(
|
||||
'room-user-change',
|
||||
'ex-room-user-change',
|
||||
otherClients.map((socket) => socket.id),
|
||||
);
|
||||
}
|
||||
|
||||
if (isFollowRoom && otherClients.length === 0) {
|
||||
const socketId = roomId.replace('follow@', '');
|
||||
server.to(socketId).emit('broadcast-unfollow');
|
||||
server.to(socketId).emit('ex-broadcast-unfollow');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,21 @@ export class WsGateway
|
||||
}
|
||||
|
||||
@SubscribeMessage('join-room')
|
||||
async handleJoinRoom(
|
||||
handleJoinRoom(client: Socket, @MessageBody() roomName: string): void {
|
||||
// if room is a space, check if user has permissions
|
||||
//client.join(roomName);
|
||||
}
|
||||
|
||||
@SubscribeMessage('leave-room')
|
||||
handleLeaveRoom(client: Socket, @MessageBody() roomName: string): void {
|
||||
client.leave(roomName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Excalidraw Sync
|
||||
@SubscribeMessage('ex-join-room')
|
||||
async handleExJoinRoom(
|
||||
@ConnectedSocket() client: Socket,
|
||||
@MessageBody() roomId: string,
|
||||
): Promise<void> {
|
||||
@@ -87,8 +101,8 @@ export class WsGateway
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeMessage('leave-room')
|
||||
async handleLeaveRoom(
|
||||
@SubscribeMessage('ex-leave-room')
|
||||
async handleExLeaveRoom(
|
||||
@ConnectedSocket() client: Socket,
|
||||
@MessageBody() roomId: string,
|
||||
): Promise<void> {
|
||||
@@ -99,7 +113,7 @@ export class WsGateway
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeMessage('server-broadcast')
|
||||
@SubscribeMessage('ex-server-broadcast')
|
||||
handleServerBroadcast(
|
||||
@ConnectedSocket() client: Socket,
|
||||
@MessageBody() [roomId, encryptedData, iv]: [string, ArrayBuffer, Uint8Array],
|
||||
@@ -112,7 +126,7 @@ export class WsGateway
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeMessage('server-volatile-broadcast')
|
||||
@SubscribeMessage('ex-server-volatile-broadcast')
|
||||
handleServerVolatileBroadcast(
|
||||
@ConnectedSocket() client: Socket,
|
||||
@MessageBody() [roomId, encryptedData, iv]: [string, ArrayBuffer, Uint8Array],
|
||||
@@ -125,7 +139,7 @@ export class WsGateway
|
||||
);
|
||||
}
|
||||
|
||||
@SubscribeMessage('user-follow')
|
||||
@SubscribeMessage('ex-user-follow')
|
||||
async handleUserFollow(
|
||||
@ConnectedSocket() client: Socket,
|
||||
@MessageBody() payload: ExcalidrawFollowPayload,
|
||||
|
||||
Reference in New Issue
Block a user