Skip to content

Commit

Permalink
feat: 서버 remote checkbox gateway 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pipisebastian committed Dec 2, 2024
1 parent 86c398d commit 4ef910e
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions server/src/workspace/workspace.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
RemoteBlockUpdateOperation,
RemotePageCreateOperation,
RemoteBlockReorderOperation,
RemoteBlockCheckboxOperation,
RemoteCharUpdateOperation,
CursorPosition,
} from "@noctaCrdt/Interfaces";
Expand Down Expand Up @@ -669,6 +670,50 @@ export class WorkspaceGateway implements OnGatewayInit, OnGatewayConnection, OnG
}
}

/**
* 블록 Checkbox 연산 처리
*/
@SubscribeMessage("checkbox/block")
async handleBlockCheckbox(
@MessageBody() data: RemoteBlockCheckboxOperation,
@ConnectedSocket() client: Socket,
): Promise<void> {
const clientInfo = this.clientMap.get(client.id);
try {
this.logger.debug(
`Block checkbox 연산 수신 - Client ID: ${clientInfo?.clientId}, Data:`,
JSON.stringify(data),
);
const { workspaceId } = client.data;
const currentBlock = await this.workSpaceService.getBlock(
workspaceId,
data.pageId,
data.blockId,
);

if (!currentBlock) {
throw new Error(`Block with id ${data.blockId} not found`);
}

currentBlock.isChecked = data.isChecked;

const operation = {
type: "blockCheckbox",
blockId: data.blockId,
pageId: data.pageId,
isChecked: data.isChecked,
};

client.broadcast.to(data.pageId).emit("checkbox/block", operation);
} catch (error) {
this.logger.error(
`Block Checkbox 연산 처리 중 오류 발생 - Client ID: ${clientInfo?.clientId}`,
error.stack,
);
throw new WsException(`Checkbox 연산 실패: ${error.message}`);
}
}

/**
* 글자 삽입 연산 처리
*/
Expand Down

0 comments on commit 4ef910e

Please sign in to comment.