Ver3.0 ๐ ์ค์๊ฐ ํ์ ๋๊ตฌ ๊ฐ๋ฐ: ์์ ๋ณํ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ์ผ๋ก ์์ฑํ๋ ๋์ ํธ์ง ์์คํ

๐ ์ค์๊ฐ ํ์ ๋๊ตฌ ๊ฐ๋ฐ: ์์ ๋ณํ ์๊ณ ๋ฆฌ์ฆ ๊ตฌํ์ผ๋ก ์์ฑํ๋ ๋์ ํธ์ง ์์คํ
์ฌ๋ฌ ์ฌ๋์ด ๋์์ ๋ฌธ์๋ฅผ ํธ์งํด๋ ์ถฉ๋ ์์ด ์๋ํ๋ ๋ง๋ฒ ๊ฐ์ ๊ธฐ์ ์ ๋น๋ฐ ๐ฏ
์๋ ! ์ค๋์ ์ ๋ง ํฅ๋ฏธ์ง์งํ ์ฃผ์ ๋ฅผ ๊ฐ์ง๊ณ ์์ด. ๐ ๊ตฌ๊ธ ๋ ์ค๋ ๋ ธ์ ๊ฐ์ ๋๊ตฌ๋ฅผ ์ฌ์ฉํด๋ณธ ์ ์์ง? ์ฌ๋ฌ ๋ช ์ด ๋์์ ๊ฐ์ ๋ฌธ์๋ฅผ ํธ์งํ๋๋ฐ๋ ์ ๊ธฐํ๊ฒ ์ถฉ๋์ด ์ ๋๊ณ ๋ชจ๋ ๋ณ๊ฒฝ์ฌํญ์ด ์ค์๊ฐ์ผ๋ก ๋ฐ์๋์์. ์ด๊ฒ ์ด๋ป๊ฒ ๊ฐ๋ฅํ์ง ๊ถ๊ธํ์ง ์์์ด? ๋ฐ๋ก ์์ ๋ณํ(Operational Transformation) ์๊ณ ๋ฆฌ์ฆ ๋๋ถ์ด์ผ!
์ด ๊ธฐ์ ์ ๋จ์ํด ๋ณด์ด์ง๋ง ์ค์ ๋ก๋ ์์ฒญ๋๊ฒ ๋ณต์กํ ์ํ์ ์๋ฆฌ์ ์๊ณ ๋ฆฌ์ฆ์ด ์จ์ด์์ด. ํ์ง๋ง ๊ฑฑ์ ๋ง! ์น๊ตฌํํ ์ค๋ช ํ๋ฏ์ด ์ฝ๊ณ ์ฌ๋ฏธ์๊ฒ ํ์ด์ ์ค๋ช ํด์ค๊ฒ. ์ด ๊ธ์ ๋ค ์ฝ๊ณ ๋๋ฉด ๋๋ ์ค์๊ฐ ํ์ ๋๊ตฌ๋ฅผ ๋ง๋ค ์ ์์ ๊ฑฐ์ผ! ๐
๐ค ์ ์์ ๋ณํ ์๊ณ ๋ฆฌ์ฆ์ด ํ์ํ ๊น?
๋จผ์ ๋ฌธ์ ์ํฉ๋ถํฐ ์ดํดํด๋ณด์. ์์ํด๋ด, ์ฒ ์์ ์ํฌ๊ฐ ๋์์ ๊ฐ์ ๋ฌธ์๋ฅผ ํธ์งํ๊ณ ์์ด. ๋ฌธ์์ ์ด๊ธฐ ์ํ๋ "Hello"์ผ.
์ฒ ์์ ์์ : ์์น 5์ " World" ์ฝ์ โ "Hello World"
์ํฌ์ ์์ : ์์น 0์ "Hi " ์ฝ์ โ "Hi Hello"
๋ฌธ์ ๋ ์ด ๋ ์์ ์ด ๊ฑฐ์ ๋์์ ๋ฐ์ํ๋ค๋ ๊ฑฐ์ผ. ๋คํธ์ํฌ ์ง์ฐ ๋๋ฌธ์ ์ฒ ์์ ์์ ์ด ์ํฌ์๊ฒ ๋์ฐฉํ๊ณ , ์ํฌ์ ์์ ์ด ์ฒ ์์๊ฒ ๋์ฐฉํ๋๋ฐ ์๊ฐ์ด ๊ฑธ๋ ค. ์ด๋ ๋จ์ํ ์์ ์ ๊ทธ๋๋ก ์ ์ฉํ๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
์ํฌ ์ ์ฅ์์๋: "Hello" โ "Hi Hello" โ "Hi Hello World" (์ฒ ์ ์์ ์ ์ฉ)
๊ฒฐ๊ณผ๋ ๊ฐ์ง๋ง, ๋ง์ฝ ์์น ์ ๋ณด๊ฐ ์๋ชป๋๋ฉด ์์ ํ ๋ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ ๋์ฌ ์ ์์ด!
๋ฐ๋ก ์ด๋ฐ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์์ ๋ณํ ์๊ณ ๋ฆฌ์ฆ์ด ํ์ํ ๊ฑฐ์ผ. ์ด ์๊ณ ๋ฆฌ์ฆ์ ๋์์ ๋ฐ์ํ ์์ ๋ค์ ์ ์ ํ ๋ณํํด์ ๋ชจ๋ ํด๋ผ์ด์ธํธ๊ฐ ๋์ผํ ์ต์ข ์ํ์ ๋๋ฌํ๋๋ก ๋ณด์ฅํด์ค. ๐ฏ
๐ง ์์ ๋ณํ(OT) ์๊ณ ๋ฆฌ์ฆ์ ํต์ฌ ๊ฐ๋
์์ ๋ณํ ์๊ณ ๋ฆฌ์ฆ์ 1989๋ Ellis์ Gibbs๊ฐ ์ฒ์ ์ ์ํ์ด. ํต์ฌ ์์ด๋์ด๋ ๊ฐ๋จํด: "๋์์ ๋ฐ์ํ ์์ ๋ค์ ์๋ก์ ์ปจํ ์คํธ์ ๋ง๊ฒ ๋ณํํ์!" ๐
๋๋ถ๋ถ์ OT ์์คํ ์ ๋ ๊ฐ์ง ๊ธฐ๋ณธ ์์ ์ผ๋ก ์์ํด:
| ์์ ํ์ | ์ค๋ช | ์์ |
|---|---|---|
| Insert(pos, char) | ํน์ ์์น์ ๋ฌธ์ ์ฝ์ | Insert(5, "!") โ "Hello" โ "Hello!" |
| Delete(pos, length) | ํน์ ์์น์์ ๋ฌธ์ ์ญ์ | Delete(0, 2) โ "Hello" โ "llo" |
โ๏ธ ๋ณํ ํจ์์ ๊ตฌํ ์๋ฆฌ
์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๋ณํ ํจ์๋ฅผ ๊ตฌํํด๋ณด์! ๋ณํ ํจ์๋ ๋ ๊ฐ์ ๋์ ์์ ์ ๋ฐ์์, ํ ์์ ์ ๋ค๋ฅธ ์์ ์ ํจ๊ณผ๋ฅผ ๊ณ ๋ คํ์ฌ ๋ณํํด์ค. ์ํ์ ์ผ๋ก ํํํ๋ฉด ์ด๋ ๊ฒ ๋ผ:
Op1๊ณผ Op2๊ฐ ๋์์ ๋ฐ์ํ์ ๋, Op2์ ํจ๊ณผ๋ฅผ ๊ณ ๋ คํ์ฌ Op1์ Op1'๋ก ๋ณํ
๋ ๊ฐ์ ์ฝ์ ์์ ์ด ๋์์ ๋ฐ์ํ ๊ฒฝ์ฐ๋ฅผ ์๊ฐํด๋ณด์:
function transformInsertInsert(op1, op2) {
// op1: Insert(pos1, char1)
// op2: Insert(pos2, char2)
if (op1.position < op2.position) {
// op1์ด op2๋ณด๋ค ์์์ ๋ฐ์
// op2์ ์์น๋ฅผ ์กฐ์ ํ ํ์ ์์
return op1;
} else if (op1.position > op2.position) {
// op1์ด op2๋ณด๋ค ๋ค์์ ๋ฐ์
// op2๊ฐ ์ฝ์
๋๋ฉด์ op1์ ์์น๊ฐ ๋ฐ๋ฆผ
return Insert(op1.position + op2.length, op1.char);
} else {
// ๊ฐ์ ์์น์์ ๋ฐ์
// ํ์ด๋ธ๋ ์ด์ปค ๊ท์น ์ ์ฉ (์: ํด๋ผ์ด์ธํธ ID ๋น๊ต)
if (op1.clientId < op2.clientId) {
return op1;
} else {
return Insert(op1.position + op2.length, op1.char);
}
}
}
์ฝ์ ๊ณผ ์ญ์ ๊ฐ ๋์์ ๋ฐ์ํ๋ ๊ฒฝ์ฐ๊ฐ ๊ฐ์ฅ ๋ณต์กํด. ์ฌ๋ฌ ์ผ์ด์ค๋ฅผ ๊ณ ๋ คํด์ผ ํ๊ฑฐ๋ :
function transformInsertDelete(insert, delete) {
// insert: Insert(pos, char)
// delete: Delete(pos, length)
if (insert.position <= delete.position) {
// ์ฝ์
์ด ์ญ์ ๋ฒ์๋ณด๋ค ์์์ ๋ฐ์
return insert;
} else if (insert.position >= delete.position + delete.length) {
// ์ฝ์
์ด ์ญ์ ๋ฒ์๋ณด๋ค ๋ค์์ ๋ฐ์
// ์ญ์ ๋ ๋งํผ ์์น๋ฅผ ์์ผ๋ก ๋น๊น
return Insert(insert.position - delete.length, insert.char);
} else {
// ์ฝ์
์ด ์ญ์ ๋ฒ์ ์์์ ๋ฐ์
// ์ญ์ ์์ ์์น๋ก ์ด๋
return Insert(delete.position, insert.char);
}
}
function transformDeleteInsert(delete, insert) {
// delete: Delete(pos, length)
// insert: Insert(pos, char)
if (delete.position >= insert.position + insert.length) {
// ์ญ์ ๊ฐ ์ฝ์
๋ณด๋ค ๋ค์์ ๋ฐ์
// ์ฝ์
๋ ๋งํผ ์์น๋ฅผ ๋ค๋ก ๋ฐ๋ฆผ
return Delete(delete.position + insert.length, delete.length);
} else if (delete.position + delete.length <= insert.position) {
// ์ญ์ ๊ฐ ์ฝ์
๋ณด๋ค ์์์ ๋ฐ์
return delete;
} else {
// ์ญ์ ๋ฒ์์ ์ฝ์
์์น๊ฐ ๊ฒน์นจ
// ์ฝ์
๋ ๋งํผ ์ญ์ ๊ธธ์ด ์กฐ์
return Delete(delete.position, delete.length + insert.length);
}
}
๋ ๊ฐ์ ์ญ์ ์์ ์ด ๋์์ ๋ฐ์ํ๋ฉด ๋ฒ์๊ฐ ๊ฒน์น ์ ์์ด. ์ด ๊ฒฝ์ฐ ์กฐ์ฌ์ค๋ฝ๊ฒ ์ฒ๋ฆฌํด์ผ ํด:
function transformDeleteDelete(op1, op2) {
// op1: Delete(pos1, len1)
// op2: Delete(pos2, len2)
if (op1.position + op1.length <= op2.position) {
// op1์ด op2๋ณด๋ค ์์ ํ ์์ ์์
return op1;
} else if (op1.position >= op2.position + op2.length) {
// op1์ด op2๋ณด๋ค ์์ ํ ๋ค์ ์์
return Delete(op1.position - op2.length, op1.length);
} else {
// ๋ฒ์๊ฐ ๊ฒน์นจ - ๋ณต์กํ ์ผ์ด์ค!
let newPos = Math.min(op1.position, op2.position);
let end1 = op1.position + op1.length;
let end2 = op2.position + op2.length;
// ๊ฒน์น์ง ์๋ ๋ถ๋ถ๋ง ์ญ์
if (op1.position < op2.position) {
let newLength = op2.position - op1.position;
return Delete(newPos, newLength);
} else if (end1 > end2) {
let newLength = end1 - end2;
return Delete(op2.position, newLength);
} else {
// ์์ ํ ํฌํจ๋์ด ์ญ์ ํ ๊ฒ์ด ์์
return null; // ์์
์ทจ์
}
}
}
๐๏ธ ์ค์ ๊ตฌํ: OT ์์คํ ์ํคํ ์ฒ
์ด๋ก ์ ์ถฉ๋ถํ ๋ดค์ผ๋ ์ด์ ์ค์ ๋ก ๋์ํ๋ ์์คํ ์ ๋ง๋ค์ด๋ณด์! ์ค์๊ฐ ํ์ ์์คํ ์ ํฌ๊ฒ ์ธ ๊ฐ์ง ์ปดํฌ๋ํธ๋ก ๊ตฌ์ฑ๋ผ:
ํด๋ผ์ด์ธํธ๋ ์ฌ์ฉ์์ ์ ๋ ฅ์ ๋ฐ์ ์์ ์ ์์ฑํ๊ณ , ์๋ฒ๋ก๋ถํฐ ๋ฐ์ ์์ ์ ๋ณํํด์ ์ ์ฉํด์ผ ํด:
class OTClient {
constructor(documentId, userId) {
this.documentId = documentId;
this.userId = userId;
this.document = "";
this.revision = 0;
this.pendingOperations = [];
this.buffer = [];
}
// ๋ก์ปฌ ์์
์์ฑ
applyLocalOperation(operation) {
// 1. ๋ฌธ์์ ์ฆ์ ์ ์ฉ (๋๊ด์ ์
๋ฐ์ดํธ)
this.document = this.applyOperation(this.document, operation);
// 2. ์์
์ ๋๊ธฐ ํ์ ์ถ๊ฐ
operation.revision = this.revision;
this.pendingOperations.push(operation);
// 3. ์๋ฒ๋ก ์ ์ก
this.sendToServer(operation);
}
// ์๋ฒ๋ก๋ถํฐ ์์
์์
receiveRemoteOperation(operation) {
// 1. ๋๊ธฐ ์ค์ธ ์์
๋ค์ ๋ํด ๋ณํ
let transformedOp = operation;
for (let pending of this.pendingOperations) {
transformedOp = this.transform(transformedOp, pending);
}
// 2. ๋ฒํผ์ ์๋ ์์
๋ค์ ๋ํด์๋ ๋ณํ
for (let buffered of this.buffer) {
transformedOp = this.transform(transformedOp, buffered);
}
// 3. ๋ณํ๋ ์์
์ ๋ฌธ์์ ์ ์ฉ
this.document = this.applyOperation(this.document, transformedOp);
this.revision++;
}
// ์๋ฒ ํ์ธ ์์
receiveAcknowledgement(operationId) {
// ํ์ธ๋ ์์
์ ๋๊ธฐ ํ์์ ์ ๊ฑฐ
this.pendingOperations = this.pendingOperations.filter(
op => op.id !== operationId
);
}
// ์์
์ ์ฉ
applyOperation(document, operation) {
if (operation.type === 'insert') {
return document.slice(0, operation.position) +
operation.char +
document.slice(operation.position);
} else if (operation.type === 'delete') {
return document.slice(0, operation.position) +
document.slice(operation.position + operation.length);
}
return document;
}
// ๋ณํ ํจ์ (์์์ ๊ตฌํํ ๋ก์ง ์ฌ์ฉ)
transform(op1, op2) {
if (op1.type === 'insert' && op2.type === 'insert') {
return this.transformInsertInsert(op1, op2);
} else if (op1.type === 'insert' && op2.type === 'delete') {
return this.transformInsertDelete(op1, op2);
} else if (op1.type === 'delete' && op2.type === 'insert') {
return this.transformDeleteInsert(op1, op2);
} else if (op1.type === 'delete' && op2.type === 'delete') {
return this.transformDeleteDelete(op1, op2);
}
return op1;
}
}
์๋ฒ๋ ๋ชจ๋ ํด๋ผ์ด์ธํธ์ ์์ ์ ์กฐ์จํ๋ ์ค์ ํ๋ธ ์ญํ ์ ํด. ์๋ฒ์ ์ฃผ์ ์ฑ ์์:
class OTServer {
constructor() {
this.documents = new Map(); // documentId -> DocumentState
this.clients = new Map(); // clientId -> WebSocket
}
// ๋ฌธ์ ์ํ ๊ด๋ฆฌ
class DocumentState {
constructor() {
this.content = "";
this.revision = 0;
this.history = [];
}
}
// ํด๋ผ์ด์ธํธ ์์
์์
handleOperation(clientId, operation) {
const doc = this.documents.get(operation.documentId);
// 1. ์์
๊ฒ์ฆ
if (operation.revision !== doc.revision) {
// ๋ฆฌ๋น์ ์ด ๋ง์ง ์์ผ๋ฉด ์ฌ๋๊ธฐํ ํ์
this.requestResync(clientId, operation.documentId);
return;
}
// 2. ์์
์ ๋ฌธ์์ ์ ์ฉ
doc.content = this.applyOperation(doc.content, operation);
doc.revision++;
doc.history.push(operation);
// 3. ์์
์ ์์ฑํ ํด๋ผ์ด์ธํธ์๊ฒ ํ์ธ ์ ์ก
this.sendAcknowledgement(clientId, operation.id);
// 4. ๋ค๋ฅธ ๋ชจ๋ ํด๋ผ์ด์ธํธ์๊ฒ ๋ธ๋ก๋์บ์คํธ
this.broadcastOperation(operation, clientId);
}
// ๋ค๋ฅธ ํด๋ผ์ด์ธํธ๋ค์๊ฒ ๋ธ๋ก๋์บ์คํธ
broadcastOperation(operation, excludeClientId) {
for (let [clientId, socket] of this.clients) {
if (clientId !== excludeClientId) {
socket.send(JSON.stringify({
type: 'operation',
operation: operation
}));
}
}
}
// ์ ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ
handleNewClient(clientId, documentId) {
const doc = this.documents.get(documentId);
// ํ์ฌ ๋ฌธ์ ์ํ ์ ์ก
this.clients.get(clientId).send(JSON.stringify({
type: 'init',
content: doc.content,
revision: doc.revision
}));
}
// ์ฌ๋๊ธฐํ ์์ฒญ
requestResync(clientId, documentId) {
const doc = this.documents.get(documentId);
this.clients.get(clientId).send(JSON.stringify({
type: 'resync',
content: doc.content,
revision: doc.revision,
history: doc.history
}));
}
}
๐ WebSocket์ ํ์ฉํ ์ค์๊ฐ ํต์
์ค์๊ฐ ํ์ ์ ์ํด์๋ ๋น ๋ฅธ ์๋ฐฉํฅ ํต์ ์ด ํ์์ผ. WebSocket์ด ์๋ฒฝํ ์ ํ์ด์ง! HTTP ํด๋ง๋ณด๋ค ํจ์ฌ ํจ์จ์ ์ด๊ฑฐ๋ . ๐
class CollaborationClient {
constructor(serverUrl, documentId, userId) {
this.serverUrl = serverUrl;
this.documentId = documentId;
this.userId = userId;
this.otClient = new OTClient(documentId, userId);
this.ws = null;
this.reconnectAttempts = 0;
this.maxReconnectAttempts = 5;
}
connect() {
this.ws = new WebSocket(this.serverUrl);
this.ws.onopen = () => {
console.log('WebSocket ์ฐ๊ฒฐ ์ฑ๊ณต! ๐');
this.reconnectAttempts = 0;
// ๋ฌธ์ ์ฐธ์ฌ ์์ฒญ
this.ws.send(JSON.stringify({
type: 'join',
documentId: this.documentId,
userId: this.userId
}));
};
this.ws.onmessage = (event) => {
const message = JSON.parse(event.data);
this.handleMessage(message);
};
this.ws.onerror = (error) => {
console.error('WebSocket ์๋ฌ:', error);
};
this.ws.onclose = () => {
console.log('WebSocket ์ฐ๊ฒฐ ์ข
๋ฃ');
this.attemptReconnect();
};
}
handleMessage(message) {
switch(message.type) {
case 'init':
// ์ด๊ธฐ ๋ฌธ์ ์ํ ์์
this.otClient.document = message.content;
this.otClient.revision = message.revision;
this.renderDocument();
break;
case 'operation':
// ์๊ฒฉ ์์
์์
this.otClient.receiveRemoteOperation(message.operation);
this.renderDocument();
break;
case 'acknowledgement':
// ์์
ํ์ธ ์์
this.otClient.receiveAcknowledgement(message.operationId);
break;
case 'resync':
// ์ฌ๋๊ธฐํ
this.otClient.document = message.content;
this.otClient.revision = message.revision;
this.otClient.pendingOperations = [];
this.renderDocument();
break;
case 'cursor':
// ๋ค๋ฅธ ์ฌ์ฉ์์ ์ปค์ ์์น
this.updateRemoteCursor(message.userId, message.position);
break;
}
}
// ๋ก์ปฌ ํธ์ง ์ฒ๋ฆฌ
handleLocalEdit(operation) {
this.otClient.applyLocalOperation(operation);
this.renderDocument();
// ์๋ฒ๋ก ์ ์ก
this.ws.send(JSON.stringify({
type: 'operation',
operation: operation
}));
}
// ์ฌ์ฐ๊ฒฐ ์๋
attemptReconnect() {
if (this.reconnectAttempts < this.maxReconnectAttempts) {
this.reconnectAttempts++;
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
console.log(`${delay}ms ํ ์ฌ์ฐ๊ฒฐ ์๋... (${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
setTimeout(() => {
this.connect();
}, delay);
} else {
console.error('์ต๋ ์ฌ์ฐ๊ฒฐ ์๋ ํ์ ์ด๊ณผ');
this.showReconnectError();
}
}
// ๋ฌธ์ ๋ ๋๋ง
renderDocument() {
const editor = document.getElementById('editor');
editor.value = this.otClient.document;
}
// ์๊ฒฉ ์ปค์ ์
๋ฐ์ดํธ
updateRemoteCursor(userId, position) {
// ๋ค๋ฅธ ์ฌ์ฉ์์ ์ปค์๋ฅผ ํ๋ฉด์ ํ์
const cursorElement = document.getElementById(`cursor-${userId}`);
if (cursorElement) {
cursorElement.style.left = this.calculateCursorPosition(position);
}
}
}
์ด์ ์ค์ ํ ์คํธ ์๋ํฐ์ ํตํฉํด๋ณด์. ์ฌ์ฉ์์ ์ ๋ ฅ์ ๊ฐ์งํ๊ณ ์์ ์ผ๋ก ๋ณํํด์ผ ํด:
class CollaborativeEditor {
constructor(editorElement, client) {
this.editor = editorElement;
this.client = client;
this.lastContent = "";
this.setupEventListeners();
}
setupEventListeners() {
// ์
๋ ฅ ์ด๋ฒคํธ ๊ฐ์ง
this.editor.addEventListener('input', (e) => {
this.handleInput(e);
});
// ์ปค์ ์ด๋ ๊ฐ์ง
this.editor.addEventListener('selectionchange', () => {
this.handleCursorMove();
});
// ๋ถ์ฌ๋ฃ๊ธฐ ์ฒ๋ฆฌ
this.editor.addEventListener('paste', (e) => {
e.preventDefault();
const text = e.clipboardData.getData('text/plain');
this.handlePaste(text);
});
}
handleInput(event) {
const currentContent = this.editor.value;
const operations = this.diffContent(this.lastContent, currentContent);
// ๊ฐ ์์
์ ํด๋ผ์ด์ธํธ๋ก ์ ์ก
for (let op of operations) {
this.client.handleLocalEdit(op);
}
this.lastContent = currentContent;
}
// ๋ด์ฉ ์ฐจ์ด ๊ณ์ฐ (๊ฐ๋จํ diff ์๊ณ ๋ฆฌ์ฆ)
diffContent(oldContent, newContent) {
const operations = [];
// ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ: ํ ๊ธ์์ฉ ๋น๊ต
let i = 0;
while (i < Math.min(oldContent.length, newContent.length) &&
oldContent[i] === newContent[i]) {
i++;
}
// ์ญ์ ๊ฐ์ง
if (oldContent.length > newContent.length) {
const deleteLength = oldContent.length - newContent.length;
operations.push({
type: 'delete',
position: i,
length: deleteLength,
id: this.generateOperationId(),
userId: this.client.userId,
timestamp: Date.now()
});
}
// ์ฝ์
๊ฐ์ง
if (newContent.length > oldContent.length) {
const insertedText = newContent.slice(i, i + (newContent.length - oldContent.length));
for (let char of insertedText) {
operations.push({
type: 'insert',
position: i,
char: char,
id: this.generateOperationId(),
userId: this.client.userId,
timestamp: Date.now()
});
i++;
}
}
return operations;
}
handleCursorMove() {
const position = this.editor.selectionStart;
// ์ปค์ ์์น๋ฅผ ์๋ฒ๋ก ์ ์ก
this.client.ws.send(JSON.stringify({
type: 'cursor',
position: position,
userId: this.client.userId
}));
}
handlePaste(text) {
const position = this.editor.selectionStart;
// ๋ถ์ฌ๋ฃ๊ธฐ๋ฅผ ์ฌ๋ฌ ๊ฐ์ ์ฝ์
์์
์ผ๋ก ๋ถํ
for (let i = 0; i < text.length; i++) {
const operation = {
type: 'insert',
position: position + i,
char: text[i],
id: this.generateOperationId(),
userId: this.client.userId,
timestamp: Date.now()
};
this.client.handleLocalEdit(operation);
}
}
generateOperationId() {
return `${this.client.userId}-${Date.now()}-${Math.random()}`;
}
}
๐จ ๊ณ ๊ธ ๊ธฐ๋ฅ: ๋ฆฌ์น ํ ์คํธ ํธ์ง ์ง์
์ง๊ธ๊น์ง๋ ํ๋ฌธ ํ ์คํธ๋ง ๋ค๋ค๋๋ฐ, ์ค์ ํ์ ๋๊ตฌ๋ ๋ณผ๋, ์ดํค๋ฆญ, ์์ ๊ฐ์ ์์๋ ์ง์ํด์ผ ํ์ง? ์ด๊ฑธ ์ํด ์์ ํ์ ์ ํ์ฅํด๋ณด์! โจ
// ์์ ์์
ํ์
class FormatOperation {
constructor(start, end, format, value) {
this.type = 'format';
this.start = start;
this.end = end;
this.format = format; // 'bold', 'italic', 'color', 'fontSize' ๋ฑ
this.value = value; // true/false ๋๋ ์์๊ฐ, ํฌ๊ธฐ๊ฐ ๋ฑ
this.id = generateId();
}
}
// ์์ ๋ณํ ํจ์
function transformFormatInsert(formatOp, insertOp) {
if (insertOp.position < formatOp.start) {
// ์ฝ์
์ด ์์ ๋ฒ์๋ณด๋ค ์์์ ๋ฐ์
return new FormatOperation(
formatOp.start + 1,
formatOp.end + 1,
formatOp.format,
formatOp.value
);
} else if (insertOp.position > formatOp.end) {
// ์ฝ์
์ด ์์ ๋ฒ์๋ณด๋ค ๋ค์์ ๋ฐ์
return formatOp;
} else {
// ์ฝ์
์ด ์์ ๋ฒ์ ์์์ ๋ฐ์
return new FormatOperation(
formatOp.start,
formatOp.end + 1, // ๋ฒ์ ํ์ฅ
formatOp.format,
formatOp.value
);
}
}
function transformFormatDelete(formatOp, deleteOp) {
const deleteEnd = deleteOp.position + deleteOp.length;
if (deleteEnd <= formatOp.start) {
// ์ญ์ ๊ฐ ์์ ๋ฒ์๋ณด๋ค ์์์ ๋ฐ์
return new FormatOperation(
formatOp.start - deleteOp.length,
formatOp.end - deleteOp.length,
formatOp.format,
formatOp.value
);
} else if (deleteOp.position >= formatOp.end) {
// ์ญ์ ๊ฐ ์์ ๋ฒ์๋ณด๋ค ๋ค์์ ๋ฐ์
return formatOp;
} else {
// ์ญ์ ๊ฐ ์์ ๋ฒ์์ ๊ฒน์นจ
const newStart = Math.min(formatOp.start, deleteOp.position);
const newEnd = Math.max(
newStart,
formatOp.end - Math.min(deleteOp.length, formatOp.end - deleteOp.position)
);
if (newEnd <= newStart) {
return null; // ์์ ๋ฒ์๊ฐ ์์ ํ ์ญ์ ๋จ
}
return new FormatOperation(
newStart,
newEnd,
formatOp.format,
formatOp.value
);
}
}
์์์ ์ง์ํ๋ ค๋ฉด ๋ฌธ์๋ฅผ ๋จ์ ๋ฌธ์์ด์ด ์๋ ๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ๋ก ๊ด๋ฆฌํด์ผ ํด:
class RichTextDocument {
constructor() {
this.text = "";
this.formats = []; // ์์ ์ ๋ณด ๋ฐฐ์ด
}
// ์์ ์ ๋ณด ๊ตฌ์กฐ
class FormatSpan {
constructor(start, end, attributes) {
this.start = start;
this.end = end;
this.attributes = attributes; // {bold: true, color: '#ff0000', ...}
}
}
// ์์ ์ ์ฉ
applyFormat(start, end, format, value) {
// ๊ธฐ์กด ์์๊ณผ ๋ณํฉ
const newSpan = new FormatSpan(start, end, {[format]: value});
this.formats.push(newSpan);
this.mergeOverlappingFormats();
}
// ๊ฒน์น๋ ์์ ๋ณํฉ
mergeOverlappingFormats() {
// ์์น ์์ผ๋ก ์ ๋ ฌ
this.formats.sort((a, b) => a.start - b.start);
const merged = [];
let current = null;
for (let span of this.formats) {
if (!current) {
current = span;
continue;
}
if (span.start <= current.end) {
// ๊ฒน์นจ - ๋ณํฉ
current.end = Math.max(current.end, span.end);
current.attributes = {...current.attributes, ...span.attributes};
} else {
merged.push(current);
current = span;
}
}
if (current) {
merged.push(current);
}
this.formats = merged;
}
// HTML๋ก ๋ ๋๋ง
toHTML() {
let html = "";
let lastPos = 0;
for (let span of this.formats) {
// ์์ ์๋ ๋ถ๋ถ
if (span.start > lastPos) {
html += this.escapeHTML(this.text.slice(lastPos, span.start));
}
// ์์ ์๋ ๋ถ๋ถ
const styles = this.attributesToCSS(span.attributes);
html += `<span style="${styles}">`;
html += this.escapeHTML(this.text.slice(span.start, span.end));
html += '</span>';
lastPos = span.end;
}
// ๋๋จธ์ง ๋ถ๋ถ
if (lastPos < this.text.length) {
html += this.escapeHTML(this.text.slice(lastPos));
}
return html;
}
attributesToCSS(attributes) {
const css = [];
if (attributes.bold) css.push('font-weight: bold');
if (attributes.italic) css.push('font-style: italic');
if (attributes.underline) css.push('text-decoration: underline');
if (attributes.color) css.push(`color: ${attributes.color}`);
if (attributes.fontSize) css.push(`font-size: ${attributes.fontSize}px`);
if (attributes.backgroundColor) css.push(`background-color: ${attributes.backgroundColor}`);
return css.join('; ');
}
escapeHTML(text) {
return text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
}
โก ์ฑ๋ฅ ์ต์ ํ ์ ๋ต
์ค์๊ฐ ํ์ ์์คํ ์ ์ฑ๋ฅ์ด ์๋ช ์ด์ผ! ์ฌ์ฉ์๊ฐ ํ์ดํํ ๋๋ง๋ค ์์ ์ด ์์ฑ๋๊ณ ์ ์ก๋๋๊น ์ต์ ํ๊ฐ ํ์์ง. ๋ช ๊ฐ์ง ํต์ฌ ์ ๋ต์ ์์๋ณด์! ๐
์ฌ์ฉ์๊ฐ ๋น ๋ฅด๊ฒ ํ์ดํํ๋ฉด ์์ ์ด ํญ๋ฐ์ ์ผ๋ก ์ฆ๊ฐํด. ์ด๊ฑธ ๋ฌถ์ด์ ์ฒ๋ฆฌํ๋ฉด ๋คํธ์ํฌ ๋ถํ๋ฅผ ํฌ๊ฒ ์ค์ผ ์ ์์ด:
class OperationBatcher {
constructor(client, batchInterval = 50) {
this.client = client;
this.batchInterval = batchInterval;
this.pendingBatch = [];
this.batchTimer = null;
}
addOperation(operation) {
this.pendingBatch.push(operation);
// ํ์ด๋จธ๊ฐ ์์ผ๋ฉด ์์
if (!this.batchTimer) {
this.batchTimer = setTimeout(() => {
this.flush();
}, this.batchInterval);
}
}
flush() {
if (this.pendingBatch.length === 0) return;
// ์ฐ์๋ ์ฝ์
์์
์ ํ๋๋ก ํฉ์น๊ธฐ
const optimized = this.optimizeBatch(this.pendingBatch);
// ์๋ฒ๋ก ์ ์ก
this.client.ws.send(JSON.stringify({
type: 'batch',
operations: optimized
}));
this.pendingBatch = [];
this.batchTimer = null;
}
optimizeBatch(operations) {
const optimized = [];
let currentInsert = null;
for (let op of operations) {
if (op.type === 'insert') {
if (currentInsert &&
op.position === currentInsert.position + currentInsert.text.length) {
// ์ฐ์๋ ์ฝ์
- ํฉ์น๊ธฐ
currentInsert.text += op.char;
} else {
if (currentInsert) {
optimized.push(currentInsert);
}
currentInsert = {
type: 'insert',
position: op.position,
text: op.char,
id: op.id,
userId: op.userId
};
}
} else {
if (currentInsert) {
optimized.push(currentInsert);
currentInsert = null;
}
optimized.push(op);
}
}
if (currentInsert) {
optimized.push(currentInsert);
}
return optimized;
}
// ์ฆ์ ์ ์ก (์ค์ํ ์์
์ ๊ฒฝ์ฐ)
flushImmediate() {
if (this.batchTimer) {
clearTimeout(this.batchTimer);
this.batchTimer = null;
}
this.flush();
}
}
ํฐ ๋ฌธ์๋ฅผ ๋ค๋ฃฐ ๋๋ ์ ์ฒด ๋ด์ฉ ๋์ ๋ณ๊ฒฝ์ฌํญ๋ง ์ ์กํ๋ ๊ฒ ํจ์จ์ ์ด์ผ:
class DeltaCompressor {
// Myers diff ์๊ณ ๋ฆฌ์ฆ์ ๊ฐ๋จํ ๊ตฌํ
static computeDiff(oldText, newText) {
const n = oldText.length;
const m = newText.length;
const max = n + m;
const v = new Array(2 * max + 1);
const trace = [];
for (let d = 0; d <= max; d++) {
trace.push([...v]);
for (let k = -d; k <= d; k += 2) {
let x;
if (k === -d || (k !== d && v[k - 1] < v[k + 1])) {
x = v[k + 1];
} else {
x = v[k - 1] + 1;
}
let y = x - k;
while (x < n && y < m && oldText[x] === newText[y]) {
x++;
y++;
}
v[k] = x;
if (x >= n && y >= m) {
return this.backtrack(trace, oldText, newText, d);
}
}
}
return [];
}
static backtrack(trace, oldText, newText, d) {
const operations = [];
let x = oldText.length;
let y = newText.length;
for (let i = d; i >= 0; i--) {
const v = trace[i];
const k = x - y;
let prevK;
if (k === -i || (k !== i && v[k - 1] < v[k + 1])) {
prevK = k + 1;
} else {
prevK = k - 1;
}
const prevX = v[prevK];
const prevY = prevX - prevK;
while (x > prevX && y > prevY) {
x--;
y--;
// ์ผ์นํ๋ ๋ถ๋ถ - ์์
์์
}
if (i > 0) {
if (x === prevX) {
// ์ฝ์
operations.unshift({
type: 'insert',
position: x,
char: newText[y - 1]
});
y--;
} else {
// ์ญ์
operations.unshift({
type: 'delete',
position: x - 1,
length: 1
});
x--;
}
}
}
return operations;
}
// ๋ธํ๋ฅผ ๋ฐ์ด๋๋ฆฌ๋ก ์์ถ
static compressDelta(operations) {
const buffer = [];
for (let op of operations) {
if (op.type === 'insert') {
buffer.push(0x01); // ์ฝ์
๋ง์ปค
this.writeVarInt(buffer, op.position);
this.writeString(buffer, op.char);
} else if (op.type === 'delete') {
buffer.push(0x02); // ์ญ์ ๋ง์ปค
this.writeVarInt(buffer, op.position);
this.writeVarInt(buffer, op.length);
}
}
return new Uint8Array(buffer);
}
static writeVarInt(buffer, value) {
while (value > 127) {
buffer.push((value & 0x7F) | 0x80);
value >>= 7;
}
buffer.push(value & 0x7F);
}
static writeString(buffer, str) {
const bytes = new TextEncoder().encode(str);
this.writeVarInt(buffer, bytes.length);
buffer.push(...bytes);
}
}
์์ ํ์คํ ๋ฆฌ๊ฐ ๊ณ์ ์์ด๋ฉด ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋ถ์กฑํด์ง ์ ์์ด. ์ฃผ๊ธฐ์ ์ผ๋ก ์ ๋ฆฌํด์ผ ํด:
class HistoryManager {
constructor(maxHistorySize = 1000) {
this.history = [];
this.maxHistorySize = maxHistorySize;
this.snapshots = [];
this.snapshotInterval = 100; // 100๊ฐ ์์
๋ง๋ค ์ค๋
์ท
}
addOperation(operation) {
this.history.push(operation);
// ์ค๋
์ท ์์ฑ ์์ ์ฒดํฌ
if (this.history.length % this.snapshotInterval === 0) {
this.createSnapshot();
}
// ํ์คํ ๋ฆฌ ํฌ๊ธฐ ์ ํ
if (this.history.length > this.maxHistorySize) {
this.compactHistory();
}
}
createSnapshot() {
const snapshot = {
revision: this.history.length,
document: this.getCurrentDocument(),
timestamp: Date.now()
};
this.snapshots.push(snapshot);
// ์ค๋๋ ์ค๋
์ท ์ ๊ฑฐ (์ต๊ทผ 5๊ฐ๋ง ์ ์ง)
if (this.snapshots.length > 5) {
this.snapshots.shift();
}
}
compactHistory() {
// ๊ฐ์ฅ ์ต๊ทผ ์ค๋
์ท ์ด์ ์ ํ์คํ ๋ฆฌ ์ ๊ฑฐ
if (this.snapshots.length > 0) {
const lastSnapshot = this.snapshots[this.snapshots.length - 1];
const cutoff = lastSnapshot.revision;
this.history = this.history.slice(cutoff);
console.log(`ํ์คํ ๋ฆฌ ์์ถ: ${cutoff}๊ฐ ์์
์ ๊ฑฐ`);
}
}
// ํน์ ์์ ์ผ๋ก ๋ณต์
restoreToRevision(targetRevision) {
// ๊ฐ์ฅ ๊ฐ๊น์ด ์ค๋
์ท ์ฐพ๊ธฐ
let baseSnapshot = null;
for (let snapshot of this.snapshots) {
if (snapshot.revision <= targetRevision) {
baseSnapshot = snapshot;
} else {
break;
}
}
if (!baseSnapshot) {
// ์ค๋
์ท์ด ์์ผ๋ฉด ์ฒ์๋ถํฐ ์ฌ์
return this.replayOperations(0, targetRevision);
}
// ์ค๋
์ท๋ถํฐ ์ฌ์
let document = baseSnapshot.document;
const operations = this.history.slice(
baseSnapshot.revision,
targetRevision
);
for (let op of operations) {
document = this.applyOperation(document, op);
}
return document;
}
}
๐ ์ถฉ๋ ํด๊ฒฐ๊ณผ ์ผ๊ด์ฑ ๋ณด์ฅ
์๋ฌด๋ฆฌ ์ข์ ์๊ณ ๋ฆฌ์ฆ์ด๋ผ๋ ์์ธ ์ํฉ์ ๋ฐ์ํด. ๋คํธ์ํฌ ํํฐ์ , ์๋ฒ ์ฅ์ , ํด๋ผ์ด์ธํธ ๋ฒ๊ทธ ๋ฑ๋ฑ... ์ด๋ฐ ์ํฉ์์๋ ๋ฐ์ดํฐ ์ผ๊ด์ฑ์ ์ ์งํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐ก๏ธ
์์ ์ ์ธ๊ณผ ๊ด๊ณ๋ฅผ ์ถ์ ํ๊ธฐ ์ํด ๋ฒกํฐ ํด๋ก์ ์ฌ์ฉํ ์ ์์ด:
class VectorClock {
constructor(clientId) {
this.clientId = clientId;
this.clock = {};
}
// ๋ก์ปฌ ์ด๋ฒคํธ ๋ฐ์
tick() {
if (!this.clock[this.clientId]) {
this.clock[this.clientId] = 0;
}
this.clock[this.clientId]++;
return this.getCopy();
}
// ์๊ฒฉ ์ด๋ฒคํธ ์์
update(remoteClock) {
for (let clientId in remoteClock) {
if (!this.clock[clientId] || this.clock[clientId] < remoteClock[clientId]) {
this.clock[clientId] = remoteClock[clientId];
}
}
this.tick();
}
// ์ธ๊ณผ ๊ด๊ณ ๋น๊ต
happensBefore(otherClock) {
let allLessOrEqual = true;
let someLess = false;
for (let clientId in this.clock) {
if (!otherClock[clientId] || this.clock[clientId] > otherClock[clientId]) {
allLessOrEqual = false;
break;
}
if (this.clock[clientId] < otherClock[clientId]) {
someLess = true;
}
}
return allLessOrEqual && someLess;
}
// ๋์ ๋ฐ์ ์ฌ๋ถ
isConcurrent(otherClock) {
return !this.happensBefore(otherClock) &&
!this.happensAfter(otherClock);
}
happensAfter(otherClock) {
return new VectorClock().update(otherClock).happensBefore(this.clock);
}
getCopy() {
return {...this.clock};
}
}
// ์์
์ ๋ฒกํฐ ํด๋ก ์ถ๊ฐ
class TimestampedOperation {
constructor(operation, vectorClock) {
this.operation = operation;
this.vectorClock = vectorClock;
this.id = generateId();
}
}
// OT ํด๋ผ์ด์ธํธ์ ๋ฒกํฐ ํด๋ก ํตํฉ
class OTClientWithVC extends OTClient {
constructor(documentId, userId) {
super(documentId, userId);
this.vectorClock = new VectorClock(userId);
}
applyLocalOperation(operation) {
// ๋ฒกํฐ ํด๋ก ์ฆ๊ฐ
const clock = this.vectorClock.tick();
// ํ์์คํฌํ ์ถ๊ฐ
const timestamped = new TimestampedOperation(operation, clock);
// ๊ธฐ์กด ๋ก์ง ์คํ
super.applyLocalOperation(timestamped);
}
receiveRemoteOperation(timestampedOp) {
// ๋ฒกํฐ ํด๋ก ์
๋ฐ์ดํธ
this.vectorClock.update(timestampedOp.vectorClock);
// ์ธ๊ณผ ๊ด๊ณ ํ์ธ
if (this.checkCausality(timestampedOp)) {
super.receiveRemoteOperation(timestampedOp.operation);
} else {
// ์ธ๊ณผ์ฑ ์๋ฐ - ๋ฒํผ์ ์ ์ฅ
this.bufferOperation(timestampedOp);
}
}
checkCausality(timestampedOp) {
// ๋ชจ๋ ์์กด์ฑ์ด ์ถฉ์กฑ๋์๋์ง ํ์ธ
for (let clientId in timestampedOp.vectorClock) {
if (clientId === this.userId) continue;
const required = timestampedOp.vectorClock[clientId];
const current = this.vectorClock.clock[clientId] || 0;
if (current < required - 1) {
return false; // ์์กด์ฑ ๋ฏธ์ถฉ์กฑ
}
}
return true;
}
bufferOperation(timestampedOp) {
this.buffer.push(timestampedOp);
// ๋ฒํผ ์ ๋ ฌ (๋ฒกํฐ ํด๋ก ์์)
this.buffer.sort((a, b) => {
if (a.vectorClock.happensBefore(b.vectorClock)) return -1;
if (b.vectorClock.happensBefore(a.vectorClock)) return 1;
return 0;
});
// ์ ์ฉ ๊ฐ๋ฅํ ์์
์ฒ๋ฆฌ
this.processBuffer();
}
processBuffer() {
let processed = 0;
for (let timestampedOp of this.buffer) {
if (this.checkCausality(timestampedOp)) {
this.receiveRemoteOperation(timestampedOp);
processed++;
} else {
break; // ์์๋๋ก ์ฒ๋ฆฌํด์ผ ํ๋ฏ๋ก ์ค๋จ
}
}
this.buffer = this.buffer.slice(processed);
}
}
๋๋ก๋ ์๋ ๋ณํ์ผ๋ก ํด๊ฒฐํ ์ ์๋ ์๋ฏธ์ ์ถฉ๋์ด ๋ฐ์ํ ์ ์์ด. ์๋ฅผ ๋ค์ด, ํ ์ฌ์ฉ์๊ฐ ๋ฌธ๋จ์ ์ญ์ ํ๊ณ ๋ค๋ฅธ ์ฌ์ฉ์๊ฐ ๊ฐ์ ๋ฌธ๋จ์ ํธ์งํ๋ ๊ฒฝ์ฐ:
class ConflictDetector {
constructor() {
this.conflicts = [];
}
// ์ถฉ๋ ๊ฐ์ง
detectConflict(op1, op2) {
// ์๋ฏธ์ ์ถฉ๋ ์ฒดํฌ
if (this.isSemanticConflict(op1, op2)) {
const conflict = {
id: generateId(),
operations: [op1, op2],
type: this.classifyConflict(op1, op2),
timestamp: Date.now(),
resolved: false
};
this.conflicts.push(conflict);
return conflict;
}
return null;
}
isSemanticConflict(op1, op2) {
// ์ญ์ ์ ํธ์ง์ด ๊ฐ์ ์์ญ์์ ๋ฐ์
if (op1.type === 'delete' && op2.type === 'insert') {
const deleteEnd = op1.position + op1.length;
if (op2.position >= op1.position && op2.position < deleteEnd) {
return true;
}
}
// ์๋ก ๋ค๋ฅธ ์์์ ๊ฐ์ ์์ญ์ ์ ์ฉ
if (op1.type === 'format' && op2.type === 'format') {
if (this.rangesOverlap(op1, op2) && op1.format === op2.format) {
return true;
}
}
return false;
}
classifyConflict(op1, op2) {
if (op1.type === 'delete' && op2.type === 'insert') {
return 'delete-edit';
}
if (op1.type === 'format' && op2.type === 'format') {
return 'format-format';
}
return 'unknown';
}
// ์ถฉ๋ ํด๊ฒฐ ์ ๋ต
resolveConflict(conflict, strategy = 'last-write-wins') {
switch(strategy) {
case 'last-write-wins':
return this.resolveByTimestamp(conflict);
case 'user-priority':
return this.resolveByUserPriority(conflict);
case 'manual':
return this.requestManualResolution(conflict);
default:
return this.resolveByTimestamp(conflict);
}
}
resolveByTimestamp(conflict) {
// ๊ฐ์ฅ ์ต๊ทผ ์์
์ ์ฐ์
const sorted = conflict.operations.sort((a, b) =>
b.timestamp - a.timestamp
);
conflict.resolved = true;
conflict.winner = sorted[0];
return sorted[0];
}
resolveByUserPriority(conflict) {
// ์ฌ์ฉ์ ๊ถํ์ ๋ฐ๋ผ ํด๊ฒฐ
const sorted = conflict.operations.sort((a, b) =>
this.getUserPriority(b.userId) - this.getUserPriority(a.userId)
);
conflict.resolved = true;
conflict.winner = sorted[0];
return sorted[0];
}
requestManualResolution(conflict) {
// UI์ ์ถฉ๋ ์๋ฆผ ํ์
this.showConflictDialog(conflict);
return null; // ์ฌ์ฉ์ ์ ํ ๋๊ธฐ
}
getUserPriority(userId) {
// ์ฌ์ฉ์ ์ญํ ์ ๋ฐ๋ฅธ ์ฐ์ ์์
const priorities = {
'admin': 100,
'editor': 50,
'viewer': 10
};
const role = this.getUserRole(userId);
return priorities[role] || 0;
}
rangesOverlap(op1, op2) {
return !(op1.end <= op2.start || op2.end <= op1.start);
}
}
๐ ์ค์ ์์ : ๊ฐ๋จํ ํ์ ์๋ํฐ ๋ง๋ค๊ธฐ
์ด์ ์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ ๋ชจ๋ ํฉ์ณ์ ์ค์ ๋ก ๋์ํ๋ ํ์ ์๋ํฐ๋ฅผ ๋ง๋ค์ด๋ณด์! ์์ ํ ์ฝ๋๋ฅผ ๋จ๊ณ๋ณ๋ก ๊ตฌํํด๋ณผ๊ฒ. ๐
โโโ client/
โ โโโ index.html
โ โโโ editor.js
โ โโโ ot-client.js
โ โโโ styles.css
โโโ server/
โ โโโ server.js
โ โโโ ot-server.js
โ โโโ document-manager.js
โโโ shared/
โโโ operations.js
โโโ transform.js
// server/server.js
const WebSocket = require('ws');
const http = require('http');
const OTServer = require('./ot-server');
const server = http.createServer();
const wss = new WebSocket.Server({ server });
const otServer = new OTServer();
wss.on('connection', (ws, req) => {
const clientId = generateClientId();
console.log(`์ ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ: ${clientId}`);
ws.on('message', (message) => {
try {
const data = JSON.parse(message);
handleMessage(ws, clientId, data);
} catch (error) {
console.error('๋ฉ์์ง ์ฒ๋ฆฌ ์ค๋ฅ:', error);
ws.send(JSON.stringify({
type: 'error',
message: error.message
}));
}
});
ws.on('close', () => {
console.log(`ํด๋ผ์ด์ธํธ ์ฐ๊ฒฐ ์ข
๋ฃ: ${clientId}`);
otServer.removeClient(clientId);
});
ws.on('error', (error) => {
console.error('WebSocket ์ค๋ฅ:', error);
});
});
function handleMessage(ws, clientId, data) {
switch(data.type) {
case 'join':
otServer.addClient(clientId, ws, data.documentId);
// ํ์ฌ ๋ฌธ์ ์ํ ์ ์ก
const doc = otServer.getDocument(data.documentId);
ws.send(JSON.stringify({
type: 'init',
content: doc.content,
revision: doc.revision,
clients: otServer.getActiveClients(data.documentId)
}));
// ๋ค๋ฅธ ํด๋ผ์ด์ธํธ๋ค์๊ฒ ์๋ฆผ
otServer.broadcast(data.documentId, {
type: 'client-joined',
clientId: clientId
}, clientId);
break;
case 'operation':
const result = otServer.handleOperation(clientId, data.operation);
if (result.success) {
// ์์
์์ฑ์์๊ฒ ํ์ธ
ws.send(JSON.stringify({
type: 'acknowledgement',
operationId: data.operation.id
}));
// ๋ค๋ฅธ ํด๋ผ์ด์ธํธ๋ค์๊ฒ ๋ธ๋ก๋์บ์คํธ
otServer.broadcast(data.operation.documentId, {
type: 'operation',
operation: result.operation
}, clientId);
} else {
// ์ค๋ฅ ๋ฐ์
ws.send(JSON.stringify({
type: 'error',
message: result.error
}));
}
break;
case 'cursor':
// ์ปค์ ์์น ๋ธ๋ก๋์บ์คํธ
otServer.broadcast(data.documentId, {
type: 'cursor',
clientId: clientId,
position: data.position,
selection: data.selection
}, clientId);
break;
case 'ping':
ws.send(JSON.stringify({ type: 'pong' }));
break;
}
}
server.listen(8080, () => {
console.log('์๋ฒ ์์: http://localhost:8080');
});
function generateClientId() {
return `client-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
// server/ot-server.js
class OTServer {
constructor() {
this.documents = new Map();
this.clients = new Map();
}
addClient(clientId, ws, documentId) {
this.clients.set(clientId, {
ws: ws,
documentId: documentId
});
// ๋ฌธ์๊ฐ ์์ผ๋ฉด ์์ฑ
if (!this.documents.has(documentId)) {
this.documents.set(documentId, {
content: "",
revision: 0,
history: [],
activeClients: new Set()
});
}
this.documents.get(documentId).activeClients.add(clientId);
}
removeClient(clientId) {
const client = this.clients.get(clientId);
if (client) {
const doc = this.documents.get(client.documentId);
if (doc) {
doc.activeClients.delete(clientId);
// ๋ค๋ฅธ ํด๋ผ์ด์ธํธ๋ค์๊ฒ ์๋ฆผ
this.broadcast(client.documentId, {
type: 'client-left',
clientId: clientId
});
}
}
this.clients.delete(clientId);
}
getDocument(documentId) {
return this.documents.get(documentId);
}
getActiveClients(documentId) {
const doc = this.documents.get(documentId);
return doc ? Array.from(doc.activeClients) : [];
}
handleOperation(clientId, operation) {
const doc = this.documents.get(operation.documentId);
if (!doc) {
return {
success: false,
error: '๋ฌธ์๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค'
};
}
// ๋ฆฌ๋น์ ํ์ธ
if (operation.revision !== doc.revision) {
return {
success: false,
error: '๋ฆฌ๋น์ ๋ถ์ผ์น'
};
}
try {
// ์์
์ ์ฉ
doc.content = this.applyOperation(doc.content, operation);
doc.revision++;
doc.history.push({
operation: operation,
clientId: clientId,
timestamp: Date.now()
});
// ํ์คํ ๋ฆฌ ํฌ๊ธฐ ์ ํ
if (doc.history.length > 1000) {
doc.history = doc.history.slice(-500);
}
return {
success: true,
operation: operation
};
} catch (error) {
return {
success: false,
error: error.message
};
}
}
applyOperation(content, operation) {
if (operation.type === 'insert') {
return content.slice(0, operation.position) +
operation.char +
content.slice(operation.position);
} else if (operation.type === 'delete') {
return content.slice(0, operation.position) +
content.slice(operation.position + operation.length);
}
return content;
}
broadcast(documentId, message, excludeClientId = null) {
const doc = this.documents.get(documentId);
if (!doc) return;
for (let clientId of doc.activeClients) {
if (clientId === excludeClientId) continue;
const client = this.clients.get(clientId);
if (client && client.ws.readyState === 1) { // OPEN
client.ws.send(JSON.stringify(message));
}
}
}
}
module.exports = OTServer;
// client/editor.js
class CollaborativeEditor {
constructor(editorElement, documentId) {
this.editor = editorElement;
this.documentId = documentId;
this.client = null;
this.remoteCursors = new Map();
this.init();
}
async init() {
// WebSocket ์ฐ๊ฒฐ
this.client = new OTClient(
`ws://localhost:8080`,
this.documentId,
this.generateUserId()
);
await this.client.connect();
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ค์
this.setupEventListeners();
// UI ์ด๊ธฐํ
this.setupUI();
}
setupEventListeners() {
// ์
๋ ฅ ์ด๋ฒคํธ
this.editor.addEventListener('input', (e) => {
this.handleInput(e);
});
// ์ ํ ๋ณ๊ฒฝ
this.editor.addEventListener('select', () => {
this.handleSelectionChange();
});
// ํค๋ณด๋ ์ด๋ฒคํธ
this.editor.addEventListener('keydown', (e) => {
this.handleKeyDown(e);
});
// ๋ฌธ์ ์
๋ฐ์ดํธ ์ด๋ฒคํธ
this.client.on('document-updated', () => {
this.renderDocument();
});
// ์๊ฒฉ ์ปค์ ์ด๋ฒคํธ
this.client.on('remote-cursor', (data) => {
this.updateRemoteCursor(data.clientId, data.position);
});
// ํด๋ผ์ด์ธํธ ์ฐธ์ฌ/ํด์ฅ
this.client.on('client-joined', (clientId) => {
this.showNotification(`์ฌ์ฉ์๊ฐ ์ฐธ์ฌํ์ต๋๋ค`);
});
this.client.on('client-left', (clientId) => {
this.removeRemoteCursor(clientId);
this.showNotification(`์ฌ์ฉ์๊ฐ ๋๊ฐ์ต๋๋ค`);
});
}
handleInput(event) {
const currentContent = this.editor.value;
const cursorPosition = this.editor.selectionStart;
// ๋ณ๊ฒฝ์ฌํญ ๊ฐ์ง
const operations = this.detectChanges(
this.client.document,
currentContent,
cursorPosition
);
// ๊ฐ ์์
์ ์ฉ
for (let op of operations) {
this.client.applyLocalOperation(op);
}
}
detectChanges(oldContent, newContent, cursorPosition) {
const operations = [];
// ๊ฐ๋จํ diff (์ค์ ๋ก๋ ๋ ์ ๊ตํ ์๊ณ ๋ฆฌ์ฆ ํ์)
if (newContent.length > oldContent.length) {
// ์ฝ์
const insertedText = newContent.slice(
cursorPosition - (newContent.length - oldContent.length),
cursorPosition
);
for (let i = 0; i < insertedText.length; i++) {
operations.push({
type: 'insert',
position: cursorPosition - insertedText.length + i,
char: insertedText[i],
id: this.generateOperationId(),
userId: this.client.userId,
timestamp: Date.now(),
revision: this.client.revision
});
}
} else if (newContent.length < oldContent.length) {
// ์ญ์
const deleteLength = oldContent.length - newContent.length;
operations.push({
type: 'delete',
position: cursorPosition,
length: deleteLength,
id: this.generateOperationId(),
userId: this.client.userId,
timestamp: Date.now(),
revision: this.client.revision
});
}
return operations;
}
handleSelectionChange() {
const position = this.editor.selectionStart;
const selection = {
start: this.editor.selectionStart,
end: this.editor.selectionEnd
};
// ์ปค์ ์์น ์ ์ก
this.client.sendCursorPosition(position, selection);
}
renderDocument() {
const cursorPosition = this.editor.selectionStart;
this.editor.value = this.client.document;
this.editor.setSelectionRange(cursorPosition, cursorPosition);
}
updateRemoteCursor(clientId, position) {
let cursor = this.remoteCursors.get(clientId);
if (!cursor) {
cursor = this.createCursorElement(clientId);
this.remoteCursors.set(clientId, cursor);
}
// ์ปค์ ์์น ๊ณ์ฐ ๋ฐ ์
๋ฐ์ดํธ
const coords = this.getCoordinatesForPosition(position);
cursor.style.left = `${coords.x}px`;
cursor.style.top = `${coords.y}px`;
}
createCursorElement(clientId) {
const cursor = document.createElement('div');
cursor.className = 'remote-cursor';
cursor.style.position = 'absolute';
cursor.style.width = '2px';
cursor.style.height = '20px';
cursor.style.backgroundColor = this.getColorForClient(clientId);
cursor.style.zIndex = '1000';
const label = document.createElement('div');
label.className = 'cursor-label';
label.textContent = `User ${clientId.substr(0, 8)}`;
cursor.appendChild(label);
this.editor.parentElement.appendChild(cursor);
return cursor;
}
removeRemoteCursor(clientId) {
const cursor = this.remoteCursors.get(clientId);
if (cursor) {
cursor.remove();
this.remoteCursors.delete(clientId);
}
}
getColorForClient(clientId) {
// ํด๋ผ์ด์ธํธ๋ณ ๊ณ ์ ์์ ์์ฑ
const colors = [
'#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A',
'#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E2'
];
const hash = clientId.split('').reduce((acc, char) =>
acc + char.charCodeAt(0), 0
);
return colors[hash % colors.length];
}
getCoordinatesForPosition(position) {
// ํ
์คํธ ์์น๋ฅผ ํ๋ฉด ์ขํ๋ก ๋ณํ
// ์ค์ ๊ตฌํ์ ๋ ๋ณต์กํจ
const lineHeight = 20;
const charWidth = 8;
const lines = this.editor.value.substr(0, position).split('\n');
const line = lines.length - 1;
const col = lines[lines.length - 1].length;
return {
x: col * charWidth,
y: line * lineHeight
};
}
setupUI() {
// ํด๋ฐ ์ถ๊ฐ
const toolbar = document.createElement('div');
toolbar.className = 'toolbar';
toolbar.innerHTML = `
<button onclick="editor.formatText('bold')">Bold</button>
<button onclick="editor.formatText('italic')">Italic</button>
<button onclick="editor.undo()">Undo</button>
<button onclick="editor.redo()">Redo</button>
<span class="status">์ฐ๊ฒฐ๋จ โ</span>
`;
this.editor.parentElement.insertBefore(toolbar, this.editor);
}
showNotification(message) {
const notification = document.createElement('div');
notification.className = 'notification';
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 3000);
}
generateUserId() {
return `user-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
generateOperationId() {
return `op-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
}
}
// ์ด๊ธฐํ
document.addEventListener('DOMContentLoaded', () => {
const editor = document.getElementById('editor');
const documentId = new URLSearchParams(window.location.search).get('doc') || 'default';
window.editor = new CollaborativeEditor(editor, documentId);
});
- ์ธ์ฆ ๋ฐ ๊ถํ ๊ด๋ฆฌ
- ๋ฌธ์ ์ ์ฅ ๋ฐ ๋ก๋ฉ
- ์คํ๋ผ์ธ ์ง์
- ๋ ์ ๊ตํ diff ์๊ณ ๋ฆฌ์ฆ
- ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
- ์๋ฌ ๋ณต๊ตฌ ๋ฉ์ปค๋์ฆ
๐ ๊ณ ๊ธ ์ฃผ์ : CRDT์์ ๋น๊ต
OT ๋ง๊ณ ๋ ์ค์๊ฐ ํ์ ์ ๊ตฌํํ๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ด ์์ด. ๋ฐ๋ก CRDT(Conflict-free Replicated Data Types)์ผ! ๋ ์ ๊ทผ ๋ฐฉ์์ ๋น๊ตํด๋ณด์. ๐ค
| ํน์ฑ | OT (Operational Transformation) | CRDT |
|---|---|---|
| ์ค์ ์๋ฒ | ํ์ (์์ ์์ ์กฐ์จ) | ๋ถํ์ (P2P ๊ฐ๋ฅ) |
| ๋ณต์ก๋ | ๋ณํ ํจ์ ๊ตฌํ์ด ๋ณต์ก | ๋ฐ์ดํฐ ๊ตฌ์กฐ๊ฐ ๋ณต์ก |
| ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ | ์๋์ ์ผ๋ก ์ ์ | ๋ฉํ๋ฐ์ดํฐ๋ก ์ธํด ๋ง์ |
| ์๋ ด ๋ณด์ฅ | ๋ณํ ํจ์๊ฐ ์ ํํด์ผ ํจ | ์ํ์ ์ผ๋ก ๋ณด์ฅ๋จ |
| ์คํ๋ผ์ธ ์ง์ | ์ด๋ ค์ | ์์ฐ์ค๋ฝ๊ฒ ์ง์ |
| ์ฑ๋ฅ | ๋น ๋ฆ | ์๋์ ์ผ๋ก ๋๋ฆผ |
CRDT์ ๊ธฐ๋ณธ ์์ด๋์ด๋ฅผ ์ดํดํ๊ธฐ ์ํด ๊ฐ๋จํ ์์ ๋ฅผ ๋ด๋ณด์:
// CRDT ๊ธฐ๋ฐ ํ
์คํธ ์๋ํฐ (๊ฐ๋จํ ๋ฒ์ )
class CRDTText {
constructor(siteId) {
this.siteId = siteId;
this.chars = []; // ๊ฐ ๋ฌธ์๋ ๊ณ ์ ID๋ฅผ ๊ฐ์ง
this.clock = 0;
}
// ๋ฌธ์ ์ฝ์
insert(position, char) {
this.clock++;
// ๊ณ ์ ID ์์ฑ (์ฌ์ดํธ ID + ๋
ผ๋ฆฌ์ ์๊ณ)
const id = {
site: this.siteId,
clock: this.clock,
position: position
};
const charObj = {
id: id,
char: char,
visible: true
};
// ์์น์ ์ฝ์
this.chars.splice(position, 0, charObj);
return {
type: 'insert',
char: charObj
};
}
// ๋ฌธ์ ์ญ์ (์ค์ ๋ก๋ ์จ๊น ์ฒ๋ฆฌ)
delete(position) {
if (position < this.chars.length) {
this.chars[position].visible = false;
return {
type: 'delete',
id: this.chars[position].id
};
}
return null;
}
// ์๊ฒฉ ์์
์ ์ฉ
applyRemoteOperation(operation) {
if (operation.type === 'insert') {
// ID ๊ธฐ๋ฐ์ผ๋ก ์ฌ๋ฐ๋ฅธ ์์น ์ฐพ๊ธฐ
const position = this.findInsertPosition(operation.char.id);
this.chars.splice(position, 0, operation.char);
} else if (operation.type === 'delete') {
// ID๋ก ๋ฌธ์ ์ฐพ์์ ์จ๊น ์ฒ๋ฆฌ
const char = this.chars.find(c =>
this.compareIds(c.id, operation.id)
);
if (char) {
char.visible = false;
}
}
}
findInsertPosition(newId) {
// ID ์์์ ๋ฐ๋ผ ์์น ๊ฒฐ์
for (let i = 0; i < this.chars.length; i++) {
if (this.compareIds(newId, this.chars[i].id) < 0) {
return i;
}
}
return this.chars.length;
}
compareIds(id1, id2) {
// ์ฌ์ดํธ ID ๋น๊ต
if (id1.site !== id2.site) {
return id1.site - id2.site;
}
// ์๊ณ ๋น๊ต
if (id1.clock !== id2.clock) {
return id1.clock - id2.clock;
}
// ์์น ๋น๊ต
return id1.position - id2.position;
}
// ํ
์คํธ๋ก ๋ณํ
toString() {
return this.chars
.filter(c => c.visible)
.map(c => c.char)
.join('');
}
}
// ์ฌ์ฉ ์์
const site1 = new CRDTText('site1');
const site2 = new CRDTText('site2');
// Site 1์์ "Hello" ์
๋ ฅ
const op1 = site1.insert(0, 'H');
const op2 = site1.insert(1, 'e');
const op3 = site1.insert(2, 'l');
const op4 = site1.insert(3, 'l');
const op5 = site1.insert(4, 'o');
// Site 2์ ์์
์ ํ
site2.applyRemoteOperation(op1);
site2.applyRemoteOperation(op2);
site2.applyRemoteOperation(op3);
site2.applyRemoteOperation(op4);
site2.applyRemoteOperation(op5);
console.log(site1.toString()); // "Hello"
console.log(site2.toString()); // "Hello"
// ๋์ ํธ์ง
const op6 = site1.insert(5, '!'); // Site 1: "Hello!"
const op7 = site2.insert(0, 'Oh '); // Site 2: "Oh Hello"
// ์๋ก ์์
์ ํ
site1.applyRemoteOperation(op7);
site2.applyRemoteOperation(op6);
console.log(site1.toString()); // "Oh Hello!"
console.log(site2.toString()); // "Oh Hello!"
// ์๋์ผ๋ก ์๋ ด!
2. P2P ์ง์: ์ค์ ์๋ฒ ์์ด๋ ๋์
3. ์คํ๋ผ์ธ ์นํ์ : ๋์ค์ ๋๊ธฐํ ๊ฐ๋ฅ
4. ๋จ์ํ ๋ณํฉ: ๋ณต์กํ ๋ณํ ๋ก์ง ๋ถํ์
2. ์ฑ๋ฅ: ํฐ ๋ฌธ์์์ ๋๋ ค์ง ์ ์์
3. ์๋ ๋ณด์กด: ์ฌ์ฉ์ ์๋๊ฐ ํญ์ ์ ํํ ๋ฐ์๋์ง ์์ ์ ์์
4. ๊ฐ๋น์ง ์ปฌ๋ ์ : ์ญ์ ๋ ๋ฌธ์๋ ๋ฉ๋ชจ๋ฆฌ์ ๋จ์
๐ ์ค๋ฌด์์์ ํ์ฉ ์ฌ๋ก
์ด๋ก ์ ์ถฉ๋ถํ ๋ดค์ผ๋ ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉ๋๋์ง ์ดํด๋ณด์! ์ ๋ช ํ ์๋น์ค๋ค์ ์ฌ๋ก๋ฅผ ํตํด ๋ฐฐ์๋ณด์. ๐ผ
1. ๊ณ์ธต์ OT: ๋ฌธ์๋ฅผ ์์ ๋ธ๋ก์ผ๋ก ๋๋ ์ ๊ฐ๊ฐ ๋ ๋ฆฝ์ ์ผ๋ก OT ์ ์ฉ
2. ์ค๋ ์ท ์์คํ : ์ฃผ๊ธฐ์ ์ผ๋ก ๋ฌธ์ ์ค๋ ์ท์ ์ ์ฅํด์ ๋ณต๊ตฌ ์๋ ํฅ์
3. ์ง๋ฅํ ๋ฐฐ์นญ: ์ฌ์ฉ์ ํ๋ ํจํด์ ํ์ตํด์ ์ต์ ์ ๋ฐฐ์นญ ์ ๋ต ์ ์ฉ
4. ํด๋ผ์ด์ธํธ ์์ธก: ์๋ฒ ์๋ต ์ ์ ๊ฒฐ๊ณผ๋ฅผ ์์ธกํด์ ํ์
1. WebAssembly ํ์ฉ: ๋ณต์กํ ๋ณํ ๋ก์ง์ WASM์ผ๋ก ๊ตฌํํด์ ์ฑ๋ฅ ํฅ์
2. ๋ ์ด์ด ๊ธฐ๋ฐ OT: ๊ฐ ๋์์ธ ๋ ์ด์ด๋ฅผ ๋ ๋ฆฝ์ ์ผ๋ก ์ฒ๋ฆฌ
3. ๋ฒกํฐ ๊ทธ๋ํฝ ์ต์ ํ: ๋ฒกํฐ ๋ฐ์ดํฐ์ ํนํ๋ ๋ณํ ์๊ณ ๋ฆฌ์ฆ
4. ์ค์๊ฐ ์ปค์: ๋ค๋ฅธ ์ฌ์ฉ์์ ๋ง์ฐ์ค ์์ง์๊น์ง ์ค์๊ฐ ํ์
1. ๋ธ๋ก ๋จ์ CRDT: ๊ฐ ๋ธ๋ก์ CRDT๋ก ๊ด๋ฆฌ
2. ํ ์คํธ OT: ๋ธ๋ก ๋ด ํ ์คํธ๋ OT๋ก ์ฒ๋ฆฌ
3. ์คํ๋ผ์ธ ์ฐ์ : ๋ก์ปฌ์์ ๋จผ์ ์์ ํ๊ณ ๋์ค์ ๋๊ธฐํ
4. ์ถฉ๋ UI: ์๋ ํด๊ฒฐ์ด ์ด๋ ค์ด ๊ฒฝ์ฐ ์ฌ์ฉ์์๊ฒ ์ ํ๊ถ ์ ๊ณต
๐ ๋๋ฒ๊น ๊ณผ ํ ์คํธ ์ ๋ต
์ค์๊ฐ ํ์ ์์คํ ์ ๋๋ฒ๊น ์ด ์ ๋ง ์ด๋ ค์. ํ์ด๋ฐ ์ด์, ๋คํธ์ํฌ ์ง์ฐ, ๋์์ฑ ๋ฌธ์ ๋ฑ๋ฑ... ํจ๊ณผ์ ์ธ ๋๋ฒ๊น ์ ๋ต์ ์์๋ณด์! ๐
class OTLogger {
constructor(level = 'info') {
this.level = level;
this.logs = [];
this.maxLogs = 1000;
}
log(level, category, message, data = {}) {
const logEntry = {
timestamp: Date.now(),
level: level,
category: category,
message: message,
data: data,
stackTrace: new Error().stack
};
this.logs.push(logEntry);
// ๋ก๊ทธ ํฌ๊ธฐ ์ ํ
if (this.logs.length > this.maxLogs) {
this.logs.shift();
}
// ์ฝ์ ์ถ๋ ฅ
if (this.shouldLog(level)) {
console.log(`[${level}] ${category}: ${message}`, data);
}
// ์๋ฒ๋ก ์ ์ก (์ค์ํ ๋ก๊ทธ๋ง)
if (level === 'error' || level === 'warning') {
this.sendToServer(logEntry);
}
}
debug(category, message, data) {
this.log('debug', category, message, data);
}
info(category, message, data) {
this.log('info', category, message, data);
}
warning(category, message, data) {
this.log('warning', category, message, data);
}
error(category, message, data) {
this.log('error', category, message, data);
}
shouldLog(level) {
const levels = ['debug', 'info', 'warning', 'error'];
const currentIndex = levels.indexOf(this.level);
const logIndex = levels.indexOf(level);
return logIndex >= currentIndex;
}
// ์์
์ถ์
traceOperation(operation, stage) {
this.debug('operation', `Operation ${stage}`, {
operationId: operation.id,
type: operation.type,
position: operation.position,
revision: operation.revision,
stage: stage
});
}
// ๋ณํ ์ถ์
traceTransform(op1, op2, result) {
this.debug('transform', 'Operation transformed', {
original: {
type: op1.type,
position: op1.position
},
against: {
type: op2.type,
position: op2.position
},
result: {
type: result.type,
position: result.position
}
});
}
// ์ํ ์ค๋
์ท
captureState(client) {
return {
document: client.document,
revision: client.revision,
pendingOps: client.pendingOperations.length,
bufferSize: client.buffer.length,
timestamp: Date.now()
};
}
// ๋ก๊ทธ ๋ถ์
analyzeConflicts() {
const conflicts = this.logs.filter(log =>
log.category === 'conflict'
);
return {
total: conflicts.length,
byType: this.groupBy(conflicts, 'data.type'),
timeline: this.createTimeline(conflicts)
};
}
groupBy(array, key) {
return array.reduce((result, item) => {
const value = key.split('.').reduce((obj, k) => obj[k], item);
(result[value] = result[value] || []).push(item);
return result;
}, {});
}
createTimeline(logs) {
return logs.map(log => ({
time: new Date(log.timestamp).toISOString(),
message: log.message
}));
}
// ๋ก๊ทธ ๋ด๋ณด๋ด๊ธฐ
exportLogs(format = 'json') {
if (format === 'json') {
return JSON.stringify(this.logs, null, 2);
} else if (format === 'csv') {
return this.logsToCSV();
}
}
logsToCSV() {
const headers = ['timestamp', 'level', 'category', 'message'];
const rows = this.logs.map(log =>
headers.map(h => log[h]).join(',')
);
return [headers.join(','), ...rows].join('\n');
}
sendToServer(logEntry) {
// ์๋ฒ๋ก ๋ก๊ทธ ์ ์ก (์ค์ ๊ตฌํ ํ์)
fetch('/api/logs', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(logEntry)
}).catch(err => {
console.error('๋ก๊ทธ ์ ์ก ์คํจ:', err);
});
}
}
// ์ฌ์ฉ ์์
const logger = new OTLogger('debug');
// ์์
๋ก๊น
logger.traceOperation(operation, 'created');
logger.traceOperation(operation, 'sent');
logger.traceOperation(operation, 'acknowledged');
// ๋ณํ ๋ก๊น
logger.traceTransform(op1, op2, transformedOp);
// ์๋ฌ ๋ก๊น
logger.error('network', 'WebSocket connection failed', {
url: wsUrl,
error: error.message
});
// ๋ณํ ํจ์ ํ
์คํธ
class OTTestSuite {
constructor() {
this.tests = [];
this.results = [];
}
// ๊ธฐ๋ณธ ๋ณํ ํ
์คํธ
testInsertInsert() {
const op1 = { type: 'insert', position: 5, char: 'A' };
const op2 = { type: 'insert', position: 3, char: 'B' };
const transformed = transform(op1, op2);
// op2๊ฐ op1๋ณด๋ค ์์์ ๋ฐ์ํ์ผ๋ฏ๋ก op1์ ์์น๊ฐ ๋ฐ๋ ค์ผ ํจ
this.assert(
transformed.position === 6,
'Insert-Insert: ์์น๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์กฐ์ ๋์ด์ผ ํจ'
);
}
// ์๋ ด์ฑ ํ
์คํธ
testConvergence() {
const doc1 = "Hello";
const doc2 = "Hello";
const op1 = { type: 'insert', position: 5, char: '!' };
const op2 = { type: 'insert', position: 0, char: 'Oh ' };
// ํด๋ผ์ด์ธํธ 1: op1 ์ ์ฉ ํ op2 ๋ณํ ์ ์ฉ
let result1 = applyOperation(doc1, op1);
const op2_transformed = transform(op2, op1);
result1 = applyOperation(result1, op2_transformed);
// ํด๋ผ์ด์ธํธ 2: op2 ์ ์ฉ ํ op1 ๋ณํ ์ ์ฉ
let result2 = applyOperation(doc2, op2);
const op1_transformed = transform(op1, op2);
result2 = applyOperation(result2, op1_transformed);
this.assert(
result1 === result2,
`์๋ ด์ฑ: ์ต์ข
๊ฒฐ๊ณผ๊ฐ ๋์ผํด์ผ ํจ (${result1} === ${result2})`
);
}
// ์๋ ๋ณด์กด ํ
์คํธ
testIntentionPreservation() {
const doc = "Hello World";
const op1 = { type: 'delete', position: 5, length: 6 }; // " World" ์ญ์
const op2 = { type: 'insert', position: 11, char: '!' }; // ๋์ ! ์ถ๊ฐ
// op1 ์ ์ฉ ํ op2 ๋ณํ
const result = applyOperation(doc, op1);
const op2_transformed = transform(op2, op1);
const final = applyOperation(result, op2_transformed);
// ์๋: ๋ฌธ์ฅ ๋์ !๋ฅผ ์ถ๊ฐํ๋ ค ํ์
this.assert(
final === "Hello!",
`์๋ ๋ณด์กด: ๋์ !๊ฐ ์ถ๊ฐ๋์ด์ผ ํจ (${final})`
);
}
// ๋๋ค ํ
์คํธ (Fuzzing)
testRandomOperations(iterations = 1000) {
for (let i = 0; i < iterations; i++) {
const doc = this.generateRandomDocument();
const op1 = this.generateRandomOperation(doc);
const op2 = this.generateRandomOperation(doc);
try {
// ์๋ฐฉํฅ ๋ณํ ํ
์คํธ
const op1_t = transform(op1, op2);
const op2_t = transform(op2, op1);
// ๊ฒฐ๊ณผ ์ ์ฉ
let result1 = applyOperation(applyOperation(doc, op1), op2_t);
let result2 = applyOperation(applyOperation(doc, op2), op1_t);
this.assert(
result1 === result2,
`๋๋ค ํ
์คํธ ${i}: ์๋ ด์ฑ ์คํจ`
);
} catch (error) {
this.recordFailure(`๋๋ค ํ
์คํธ ${i}`, error, { doc, op1, op2 });
}
}
}
// ๋์์ฑ ํ
์คํธ
async testConcurrency() {
const numClients = 10;
const numOperations = 100;
const clients = Array.from({ length: numClients }, (_, i) =>
new OTClient(`doc-test`, `client-${i}`)
);
// ๋ชจ๋ ํด๋ผ์ด์ธํธ๊ฐ ๋์์ ์์
์ํ
const promises = clients.map(client =>
this.performRandomOperations(client, numOperations)
);
await Promise.all(promises);
// ๋ชจ๋ ํด๋ผ์ด์ธํธ์ ๋ฌธ์๊ฐ ๋์ผํ์ง ํ์ธ
const documents = clients.map(c => c.document);
const allSame = documents.every(doc => doc === documents[0]);
this.assert(
allSame,
'๋์์ฑ ํ
์คํธ: ๋ชจ๋ ํด๋ผ์ด์ธํธ๊ฐ ๋์ผํ ๋ฌธ์๋ฅผ ๊ฐ์ ธ์ผ ํจ'
);
}
// ๋คํธ์ํฌ ์ง์ฐ ์๋ฎฌ๋ ์ด์
async testWithNetworkDelay() {
const client1 = new OTClient('doc-test', 'client-1');
const client2 = new OTClient('doc-test', 'client-2');
// ์์
์์ฑ
const op1 = client1.createOperation('insert', 0, 'A');
const op2 = client2.createOperation('insert', 0, 'B');
// ์ง์ฐ ์๋ฎฌ๋ ์ด์
await this.delay(Math.random() * 100);
client2.receiveRemoteOperation(op1);
await this.delay(Math.random() * 100);
client1.receiveRemoteOperation(op2);
this.assert(
client1.document === client2.document,
'๋คํธ์ํฌ ์ง์ฐ ํ
์คํธ: ๋ฌธ์๊ฐ ์๋ ดํด์ผ ํจ'
);
}
// ํฌํผ ํจ์๋ค
generateRandomDocument() {
const length = Math.floor(Math.random() * 100);
return Array.from({ length }, () =>
String.fromCharCode(65 + Math.floor(Math.random() * 26))
).join('');
}
generateRandomOperation(doc) {
const type = Math.random() > 0.5 ? 'insert' : 'delete';
const position = Math.floor(Math.random() * (doc.length + 1));
if (type === 'insert') {
const char = String.fromCharCode(65 + Math.floor(Math.random() * 26));
return { type, position, char };
} else {
const length = Math.min(
Math.floor(Math.random() * 5) + 1,
doc.length - position
);
return { type, position, length };
}
}
async performRandomOperations(client, count) {
for (let i = 0; i < count; i++) {
const op = this.generateRandomOperation(client.document);
client.applyLocalOperation(op);
await this.delay(Math.random() * 10);
}
}
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
assert(condition, message) {
this.results.push({
passed: condition,
message: message,
timestamp: Date.now()
});
if (!condition) {
console.error(`โ ํ
์คํธ ์คํจ: ${message}`);
} else {
console.log(`โ
ํ
์คํธ ํต๊ณผ: ${message}`);
}
}
recordFailure(testName, error, context) {
this.results.push({
passed: false,
testName: testName,
error: error.message,
context: context,
timestamp: Date.now()
});
}
// ํ
์คํธ ์คํ ๋ฐ ๋ฆฌํฌํธ
async runAll() {
console.log('๐งช OT ํ
์คํธ ์์...\n');
this.testInsertInsert();
this.testConvergence();
this.testIntentionPreservation();
this.testRandomOperations(100);
await this.testConcurrency();
await this.testWithNetworkDelay();
this.printReport();
}
printReport() {
const passed = this.results.filter(r => r.passed).length;
const failed = this.results.filter(r => !r.passed).length;
const total = this.results.length;
console.log('\n๐ ํ
์คํธ ๊ฒฐ๊ณผ:');
console.log(`์ด ํ
์คํธ: ${total}`);
console.log(`โ
ํต๊ณผ: ${passed}`);
console.log(`โ ์คํจ: ${failed}`);
console.log(`์ฑ๊ณต๋ฅ : ${((passed / total) * 100).toFixed(2)}%`);
if (failed > 0) {
console.log('\n์คํจํ ํ
์คํธ:');
this.results.filter(r => !r.passed).forEach(r => {
console.log(`- ${r.message || r.testName}`);
if (r.context) {
console.log(` ์ปจํ
์คํธ:`, r.context);
}
});
}
}
}
// ํ
์คํธ ์คํ
const testSuite = new OTTestSuite();
testSuite.runAll();
๐ฏ ์ฑ๋ฅ ๋ฒค์น๋งํฌ์ ์ต์ ํ
์ค์๊ฐ ํ์ ์์คํ ์ ์ฑ๋ฅ์ ์ธก์ ํ๊ณ ๊ฐ์ ํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐
class PerformanceMonitor {
constructor() {
this.metrics = {
operationLatency: [],
transformTime: [],
renderTime: [],
networkLatency: [],
memoryUsage: []
};
this.startTime = Date.now();
}
// ์์
์ง์ฐ์๊ฐ ์ธก์
measureOperationLatency(startTime) {
const latency = Date.now() - startTime;
this.metrics.operationLatency.push(latency);
if (latency > 100) {
console.warn(`โ ๏ธ ๋์ ์์
์ง์ฐ: ${latency}ms`);
}
return latency;
}
// ๋ณํ ์๊ฐ ์ธก์
measureTransform(fn, ...args) {
const start = performance.now();
const result = fn(...args);
const duration = performance.now() - start;
this.metrics.transformTime.push(duration);
return result;
}
// ๋ ๋๋ง ์๊ฐ ์ธก์
measureRender(fn) {
const start = performance.now();
fn();
const duration = performance.now() - start;
this.metrics.renderTime.push(duration);
if (duration > 16.67) { // 60fps ๊ธฐ์ค
console.warn(`โ ๏ธ ๋๋ฆฐ ๋ ๋๋ง: ${duration.toFixed(2)}ms`);
}
}
// ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ์ธก์
measureMemory() {
if (performance.memory) {
const usage = {
used: performance.memory.usedJSHeapSize,
total: performance.memory.totalJSHeapSize,
limit: performance.memory.jsHeapSizeLimit,
timestamp: Date.now()
};
this.metrics.memoryUsage.push(usage);
return usage;
}
return null;
}
// ํต๊ณ ๊ณ์ฐ
getStatistics(metricName) {
const data = this.metrics[metricName];
if (!data || data.length === 0) return null;
const sorted = [...data].sort((a, b) => a - b);
const sum = data.reduce((a, b) => a + b, 0);
return {
count: data.length,
min: sorted[0],
max: sorted[sorted.length - 1],
mean: sum / data.length,
median: sorted[Math.floor(sorted.length / 2)],
p95: sorted[Math.floor(sorted.length * 0.95)],
p99: sorted[Math.floor(sorted.length * 0.99)]
};
}
// ๋ฆฌํฌํธ ์์ฑ
generateReport() {
const report = {
duration: Date.now() - this.startTime,
metrics: {}
};
for (let metricName in this.metrics) {
report.metrics[metricName] = this.getStatistics(metricName);
}
return report;
}
// ์ค์๊ฐ ๋ชจ๋ํฐ๋ง
startRealTimeMonitoring(interval = 1000) {
setInterval(() => {
const memory = this.measureMemory();
const stats = this.getStatistics('operationLatency');
console.log('๐ ์ค์๊ฐ ๋ฉํธ๋ฆญ:');
console.log(` ์์
์ง์ฐ (ํ๊ท ): ${stats?.mean.toFixed(2)}ms`);
console.log(` ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ: ${(memory?.used / 1024 / 1024).toFixed(2)}MB`);
}, interval);
}
// ์ฑ๋ฅ ๊ฒฝ๊ณ
checkPerformance() {
const warnings = [];
// ์์
์ง์ฐ ์ฒดํฌ
const latencyStats = this.getStatistics('operationLatency');
if (latencyStats && latencyStats.p95 > 100) {
warnings.push(`๋์ ์์
์ง์ฐ: P95 = ${latencyStats.p95.toFixed(2)}ms`);
}
// ๋ ๋๋ง ์๊ฐ ์ฒดํฌ
const renderStats = this.getStatistics('renderTime');
if (renderStats && renderStats.mean > 16.67) {
warnings.push(`๋๋ฆฐ ๋ ๋๋ง: ํ๊ท = ${renderStats.mean.toFixed(2)}ms`);
}
// ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ ์ฒดํฌ
const memory = this.measureMemory();
if (memory && memory.used / memory.limit > 0.9) {
warnings.push(`๋์ ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ: ${(memory.used / memory.limit * 100).toFixed(2)}%`);
}
return warnings;
}
}
// ์ฌ์ฉ ์์
const monitor = new PerformanceMonitor();
// ์์
์ธก์
const opStart = Date.now();
client.applyLocalOperation(operation);
monitor.measureOperationLatency(opStart);
// ๋ณํ ์ธก์
const transformed = monitor.measureTransform(
transform,
op1,
op2
);
// ๋ ๋๋ง ์ธก์
monitor.measureRender(() => {
editor.renderDocument();
});
// ์ฃผ๊ธฐ์ ์ฒดํฌ
setInterval(() => {
const warnings = monitor.checkPerformance();
if (warnings.length > 0) {
console.warn('โ ๏ธ ์ฑ๋ฅ ๊ฒฝ๊ณ :', warnings);
}
}, 5000);
// ์ต์ข
๋ฆฌํฌํธ
window.addEventListener('beforeunload', () => {
const report = monitor.generateReport();
console.log('๐ ์ต์ข
์ฑ๋ฅ ๋ฆฌํฌํธ:', report);
});
โ ๋ธํ ์์ถ์ผ๋ก ์ ์ก ๋ฐ์ดํฐ ํฌ๊ธฐ ์ค์ด๊ธฐ
โ ๊ฐ์ ์คํฌ๋กค๋ง์ผ๋ก ํฐ ๋ฌธ์ ๋ ๋๋ง ์ต์ ํ
โ Web Worker๋ก ๋ณํ ๋ก์ง ์คํ๋ก๋
โ IndexedDB๋ก ๋ก์ปฌ ์บ์ฑ
โ ๋๋ฐ์ด์ฑ์ผ๋ก ๋ถํ์ํ ์ ๋ฐ์ดํธ ๋ฐฉ์ง
โ ๋ฉ๋ชจ๋ฆฌ ๋์ ๋ฐฉ์ง (์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ ๋ฆฌ)
๐ ๋ฏธ๋ ๊ธฐ์ ๊ณผ ๋ฐ์ ๋ฐฉํฅ
์ค์๊ฐ ํ์ ๊ธฐ์ ์ ๊ณ์ ๋ฐ์ ํ๊ณ ์์ด. ์์ผ๋ก ์ด๋ค ๋ฐฉํฅ์ผ๋ก ๋์๊ฐ์ง ์ดํด๋ณด์! ๐ฎ
๐ผ ์ค๋ฌด ํ๋ก์ ํธ ์์ํ๊ธฐ
์ด์ ์ค์ ๋ก ํ๋ก์ ํธ๋ฅผ ์์ํ ์ค๋น๊ฐ ๋์ด! ๋จ๊ณ๋ณ๋ก ์ด๋ป๊ฒ ์งํํ๋ฉด ์ข์์ง ์ ๋ฆฌํด๋ณผ๊ฒ. ๐ฏ
โ ๋ฌธ์ ํฌ๊ธฐ ๋ฒ์
โ ํ์ํ ๊ธฐ๋ฅ (ํ ์คํธ, ์์, ์ด๋ฏธ์ง ๋ฑ)
โ ์คํ๋ผ์ธ ์ง์ ํ์ ์ฌ๋ถ
โ ์ฑ๋ฅ ์๊ตฌ์ฌํญ (์ง์ฐ์๊ฐ, ์ฒ๋ฆฌ๋)
โ ๋ณด์ ์๊ตฌ์ฌํญ
๋ฐฑ์๋: Node.js/Go/Rust + Redis/PostgreSQL
์ธํ๋ผ: AWS/GCP/Azure + CDN
๋ชจ๋ํฐ๋ง: Prometheus + Grafana
โ ์ค์๊ฐ ๋๊ธฐํ
โ ๊ฐ๋จํ ์ถฉ๋ ํด๊ฒฐ
โ ์ฌ์ฉ์ ์ธ์ฆ
โ ๊ธฐ๋ณธ UI/UX
โ ํตํฉ ํ ์คํธ
โ ๋ถํ ํ ์คํธ
โ ์ฑ๋ฅ ํ๋กํ์ผ๋ง
โ ๋ณด์ ๊ฐ์ฌ
โ ์คํ ์ด์ง ํ๊ฒฝ ํ ์คํธ
โ ํ๋ก๋์ ๋ฐฐํฌ
โ ์ค์๊ฐ ๋ชจ๋ํฐ๋ง ์ค์
โ ์ฌ์ฉ์ ํผ๋๋ฐฑ ์์ง
๐ ํ์ต ๋ฆฌ์์ค์ ์ฐธ๊ณ ์๋ฃ
๋ ๊น์ด ๊ณต๋ถํ๊ณ ์ถ๋ค๋ฉด ์ด ์๋ฃ๋ค์ ์ฐธ๊ณ ํด๋ด! ๐
2. "Consistency Maintenance in Real-Time Collaborative Graphics Editing Systems" - Sun et al. (1998)
3. "A Comprehensive Study of Convergent and Commutative Replicated Data Types" - Shapiro et al. (2011)
4. "Conflict-free Replicated Data Types" - Shapiro et al. (2011)
Yjs: CRDT ๊ธฐ๋ฐ ํ์ ํ๋ ์์ํฌ
Automerge: JSON CRDT ๋ผ์ด๋ธ๋ฌ๋ฆฌ
Quill: ๋ฆฌ์น ํ ์คํธ ์๋ํฐ
ProseMirror: ํ์ฅ ๊ฐ๋ฅํ ํ ์คํธ ์๋ํฐ
- "Real-Time Collaboration" - Frontend Masters
- "Building Collaborative Applications" - Pluralsight
- Collaborative Editing Research Group
- WebRTC Community
- Real-Time Web Technologies Forum
๐ฏ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ ๋ง ๊ธด ์ฌ์ ์ด์์ง? ๐ ์ค์๊ฐ ํ์ ๋๊ตฌ ๊ฐ๋ฐ์ ์ฝ์ง ์์ง๋ง, ์ ๋ง ํฅ๋ฏธ์ง์งํ ๋ถ์ผ์ผ. ์ฐ๋ฆฌ๊ฐ ์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ ์ ๋ฆฌํด๋ณด์:
2. ๋ณํ ํจ์: Insert-Insert, Insert-Delete, Delete-Delete ๋ฑ์ ์ผ์ด์ค ์ฒ๋ฆฌ
3. ์๋ ด์ฑ ๋ณด์ฅ: ๋ชจ๋ ํด๋ผ์ด์ธํธ๊ฐ ๋์ผํ ์ต์ข ์ํ ๋๋ฌ
4. ์ฑ๋ฅ ์ต์ ํ: ๋ฐฐ์นญ, ์์ถ, ์บ์ฑ ๋ฑ์ ๊ธฐ๋ฒ ํ์ฉ
5. ์ถฉ๋ ํด๊ฒฐ: ์๋ ํด๊ฒฐ๊ณผ ์๋ ํด๊ฒฐ์ ๊ท ํ
6. ํ ์คํธ: ์ฒ ์ ํ ํ ์คํธ๋ก ์์ ์ฑ ํ๋ณด
์ค์๊ฐ ํ์ ๊ธฐ์ ์ ์์ผ๋ก ๋์ฑ ์ค์ํด์ง ๊ฑฐ์ผ. ์๊ฒฉ ๊ทผ๋ฌด๊ฐ ์ผ์ํ๋๊ณ , ์ ์ธ๊ณ ์ฌ๋๋ค์ด ํจ๊ป ์ผํ๋ ์๋๋๊น. ์ด ๊ธฐ์ ์ ๋ง์คํฐํ๋ฉด ์ ๋ง ๋ง์ ๊ธฐํ๊ฐ ์ด๋ฆด ๊ฑฐ์ผ! ๐ช
์ฒ์์๋ ๋ณต์กํด ๋ณด์ด์ง๋ง, ํ๋์ฉ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ตฌํํ๋ค ๋ณด๋ฉด ์ด๋์ ์์ฑ๋ ํ์ ๋๊ตฌ๋ฅผ ๋ง๋ค ์ ์์ ๊ฑฐ์ผ. ํฌ๊ธฐํ์ง ๋ง๊ณ ๊ณ์ ๋์ ํด๋ด! ๐
์ด ๊ธ์ด ๋์์ด ๋๋ค๋ฉด ์ ๋ง ๊ธฐ์ ๊ฒ ๊ฐ์! ๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋ ํ๋ก์ ํธ๋ฅผ ์งํํ๋ฉด์ ์ด๋ ค์์ด ์๋ค๋ฉด ์ธ์ ๋ ์ง ์ปค๋ฎค๋ํฐ์ ์ง๋ฌธํด๋ด. ์ฐ๋ฆฌ ๋ชจ๋ ํจ๊ป ์ฑ์ฅํ๋ ๊ฑฐ๋๊น! ๐
๊ทธ๋ผ ํ์ด์ ๋น์ด! ๋ฉ์ง ํ์ ๋๊ตฌ๋ฅผ ๋ง๋ค์ด๋ณด์! ํ์ดํ ! ๐โจ
๐ ๋น์ ์ ํ์ ๋๊ตฌ ๊ฐ๋ฐ ์ฌ์ ์ ์์ํฉ๋๋ค! ๐
Keep coding, keep collaborating! ๐ป๐ค
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.