import type { AiChatMsg, BoardEventMsg, ConfirmationMsg, SnapshotRequestMsg, ModeMsg, SyncBoardEvent } from "microboard-temp"; import { Board, PresenceEventMsg, PresenceEventType, UserJoinMsg } from "microboard-temp"; import type { Account } from "../entities/account"; import { Storage } from "./Storage"; export interface BoardSubscriptionCompletedMsg { type: "BoardSubscriptionCompleted"; boardId: string; mode: "view" | "edit"; snapshot: any; eventsSinceLastSnapshot: SyncBoardEvent[]; initialSequenceNumber: number; } export interface AuthMsg { type: "Auth"; jwt: string; } export interface LogoutMsg { type: "Logout"; } export interface InvalidateRightsMsg { type: "InvalidateRights"; boardId: string; byUser: boolean; } export interface GetModeMsg { type: "GetMode"; boardId: string; } export interface SubscribeMsg { type: "Subscribe"; boardId: string; userId: string; index: number; accessKey?: string; } export interface UnsubscribeMsg { type: "Unsubscribe"; boardId: string; } export interface ErrorMsg { type: "Error"; message: string; deniedBoardId?: string; expectedSequence?: number; receivedSequence?: number; } export interface VersionCheckMsg { type: "VersionCheck"; version: string; } export interface AuthConfirmationMsg { type: "AuthConfirmation"; } export interface PingMsg { type: "ping" | "pong"; } export interface BoardAccessDeniedMsg { type: "BoardAccessDenied"; boardId: string; } export type EventsMsg = ModeMsg | BoardEventMsg | SnapshotRequestMsg | ConfirmationMsg | BoardSubscriptionCompletedMsg | UserJoinMsg | PresenceEventMsg | AiChatMsg; export type SocketMsg = EventsMsg | AuthMsg | AuthConfirmationMsg | LogoutMsg | GetModeMsg | InvalidateRightsMsg | UserJoinMsg | SubscribeMsg | UnsubscribeMsg | VersionCheckMsg | ErrorMsg | ModeMsg | PingMsg | AiChatMsg | BoardAccessDeniedMsg; export interface Connection { connectionId: string; getCurrentUser: () => string; connect(): Promise; subscribe(board: Board): void; unsubscribe(board: Board): void; publishPresenceEvent(boardId: string, event: PresenceEventType): void; publishAuth(): Promise; publishLogout(): void; onMessage?: (msg: SocketMsg) => void; onAccessDenied: (boardId: string, forceUpdate?: boolean) => void; notifyAboutLostConnection: () => void; dismissNotificationAboutLostConnection: () => void; resetConnection: () => void; send: (msg: SocketMsg) => void; } export declare function createConnection(getCurrentBoard: () => Board, getAccount: () => Account, getStorage: () => Storage): Connection; interface WsClient { send: (message: SocketMsg) => void; isConnected: () => boolean; close: () => void; } type SocketMsgHandler = (message: SocketMsg) => void; export declare function createWsClient(wsUrl: string, token: string, msgHandler: SocketMsgHandler, onError: (error: unknown) => void, onReconnect: () => void): WsClient; export {};