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