Skip to content

Commit

Permalink
feat: 서버에서 reorder/block 연산 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludovico7 committed Nov 21, 2024
1 parent f5c8906 commit 5cf6b10
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions server/src/crdt/crdt.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
RemoteCharInsertOperation,
RemoteBlockUpdateOperation,
RemotePageCreateOperation,
RemoteBlockReorderOperation,
CursorPosition,
} from "@noctaCrdt/Interfaces";
import { Logger } from "@nestjs/common";
Expand Down Expand Up @@ -362,6 +363,43 @@ export class CrdtGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
}
}

@SubscribeMessage("reorder/block")
async handleBlockReorder(
@MessageBody() data: RemoteBlockReorderOperation,
@ConnectedSocket() client: Socket,
): Promise<void> {
const clientInfo = this.clientMap.get(client.id);
try {
this.logger.debug(
`블록 Reorder 연산 수신 - Client ID: ${clientInfo?.clientId}, Data:`,
JSON.stringify(data),
);
// 1. 워크스페이스 가져오기
const workspace = this.workSpaceService.getWorkspace();

Check failure on line 379 in server/src/crdt/crdt.gateway.ts

View workflow job for this annotation

GitHub Actions / Lint and Unit Test

Delete `······`
const currentPage = workspace.pageList.find((p) => p.id === data.pageId);
if (!currentPage) {
throw new Error(`Page with id ${data.pageId} not found`);
}
currentPage.crdt.remoteReorder(data);

// 5. 다른 클라이언트들에게 업데이트된 블록 정보 브로드캐스트
const operation = {
targetId: data.targetId,
beforeId: data.beforeId,
afterId: data.afterId,
pageId: data.pageId

Check failure on line 391 in server/src/crdt/crdt.gateway.ts

View workflow job for this annotation

GitHub Actions / Lint and Unit Test

Insert `,`
} as RemoteBlockReorderOperation;
client.broadcast.emit("reorder/block", operation);
} catch (error) {
this.logger.error(
`블록 Reorder 연산 처리 중 오류 발생 - Client ID: ${clientInfo?.clientId}`,
error.stack,
);
throw new WsException(`Update 연산 실패: ${error.message}`);
}
}

/**
* 커서 위치 업데이트 처리
*/
Expand Down

0 comments on commit 5cf6b10

Please sign in to comment.