@gitorial/sync
Version:
Universal sync library for real-time tutorial state synchronization between websites and VS Code extensions with built-in relay server orchestration
98 lines • 3.42 kB
TypeScript
/**
* Sync message types for WebSocket communication
*/
export declare enum SyncMessageType {
/** Tutorial state update from extension to clients */
STATE_UPDATE = "state_update",
/** Request for current tutorial state from client to extension */
REQUEST_SYNC = "request_sync",
/** Notification that a client has connected */
CLIENT_CONNECTED = "client_connected",
/** Notification that a client has disconnected */
CLIENT_DISCONNECTED = "client_disconnected",
/** Offer to give control to the other peer */
OFFER_CONTROL = "offer_control",
/** Accept control offered by the other peer */
ACCEPT_CONTROL = "accept_control",
/** Decline control offered by the other peer */
DECLINE_CONTROL = "decline_control",
/** Return control back to the original peer */
RETURN_CONTROL = "return_control",
/** Error message */
ERROR = "error",
/** Protocol version handshake from client to server */
PROTOCOL_HANDSHAKE = "protocol_handshake",
/** Protocol version acknowledgment from server to client */
PROTOCOL_ACK = "protocol_ack",
/** Request to take control of the other peer */
REQUEST_CONTROL = "request_control",
/** Release control back to the original peer */
RELEASE_CONTROL = "release_control",
/** Confirm transfer of control */
CONFIRM_TRANSFER = "confirm_transfer",
/** Role changed notification */
ROLE_CHANGED = "role_changed",
/** Request sync direction coordination (want to be ACTIVE/PASSIVE) */
COORDINATE_SYNC_DIRECTION = "coordinate_sync_direction",
/** Server assigns sync direction to client */
ASSIGN_SYNC_DIRECTION = "assign_sync_direction"
}
/**
* Shared fields for all sync messages (except `CLIENT_CONNECTED` and handshake messages)
*/
export interface SyncMessageBase {
type: Exclude<SyncMessageType, SyncMessageType.CLIENT_CONNECTED | SyncMessageType.PROTOCOL_HANDSHAKE | SyncMessageType.PROTOCOL_ACK>;
clientId: string;
data: any;
timestamp: number;
protocol_version: number;
}
/**
* Special case: initial connection handshake
*/
export interface SyncMessageClientConnected {
type: SyncMessageType.CLIENT_CONNECTED;
clientId: string;
timestamp: number;
protocol_version: number;
}
/**
* Protocol handshake message sent by client immediately upon connection
*/
export interface SyncMessageProtocolHandshake {
type: SyncMessageType.PROTOCOL_HANDSHAKE;
protocol_version: number;
timestamp: number;
}
/**
* Protocol acknowledgment message sent by server in response to handshake
*/
export interface SyncMessageProtocolAck {
type: SyncMessageType.PROTOCOL_ACK;
protocol_version: number;
timestamp: number;
accepted: boolean;
error?: string;
}
/**
* Unified message type for all sync messages
*/
export type SyncMessage = SyncMessageBase | SyncMessageClientConnected | SyncMessageProtocolHandshake | SyncMessageProtocolAck;
export interface StateTransferPackage {
tutorialState: any;
metadata: {
transferTimestamp: number;
fromClientId: string;
toClientId: string;
stateChecksum: string;
};
}
export interface SyncDirectionRequest {
preferredDirection: 'ACTIVE' | 'PASSIVE';
reason: string;
}
export interface SyncDirectionAssignment {
assignedDirection: 'ACTIVE' | 'PASSIVE';
reason: string;
}
//# sourceMappingURL=messages.d.ts.map