본문 내용으로 건너뛰기

Realtime

clepit에는 두 개의 실시간 표면이 있습니다. 문서 변경용 Socket.IO /content 네임스페이스와 공동 편집용 원시 WebSocket입니다.

SurfaceAddressCarries
Socket.IOwss://ws.clepit.com/contentpageChanged and other document events
Raw WebSocketwss://ws.clepit.com/collab/pages/{pageId}Collaborative editing (CRDT updates)

Document events

A connection is authenticated at handshake and joined to the rooms its tenant owns. Fan-out is filtered per subscriber: a socket only receives an event for a page it is permitted to see, checked at emit time rather than at subscribe time.

TypeScript
import { io } from 'socket.io-client';

const socket = io('https://ws.clepit.com/content', {
  auth: { token: accessToken },
});

socket.on('pageChanged', ({ pageId, data }) => {
  // data is the serialised change for pageId
});

Collaborative editing

The collab socket is a separate, binary channel carrying CRDT updates for one page. It is not Socket.IO, it is a raw WebSocket, because the payload is binary and the protocol is the CRDT’s own.

TypeScript
const socket = new WebSocket(
  `wss://ws.clepit.com/collab/pages/${pageId}?token=${accessToken}`,
);

socket.binaryType = 'arraybuffer';
socket.onmessage = event => applyUpdate(doc, new Uint8Array(event.data));