import * as Y from 'yjs'; import { Awareness } from 'y-protocols/awareness'; import * as mutex from 'lib0/mutex'; import type { Event, CloseEvent, MessageEvent } from 'ws'; import EventEmitter from './EventEmitter'; import { OutgoingMessage } from './OutgoingMessage'; import { ConstructableOutgoingMessage } from './types'; import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.'; export declare enum WebSocketStatus { Connecting = "connecting", Connected = "connected", Disconnected = "disconnected" } export declare type HocuspocusProviderConfiguration = Required> & Partial; export interface CompleteHocuspocusProviderConfiguration { /** * URL of your @hocuspocus/server instance */ url: string; /** * The identifier/name of your document */ name: string; /** * The actual Y.js document */ document: Y.Doc; /** * Pass `false` to start the connection manually. */ connect: boolean; /** * Pass false to disable broadcasting between browser tabs. */ broadcast: boolean; /** * An Awareness instance to keep the presence state of all clients. */ awareness: Awareness; /** * A token that’s sent to the backend for authentication purposes. */ token: string | (() => string) | (() => Promise) | null; /** * URL parameters that should be added. */ parameters: { [key: string]: any; }; /** * An optional WebSocket polyfill, for example for Node.js */ WebSocketPolyfill: any; /** * Force syncing the document in the defined interval. */ forceSyncInterval: false | number; /** * Disconnect when no message is received for the defined amount of milliseconds. */ messageReconnectTimeout: number; /** * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially. */ delay: number; /** * The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately. */ initialDelay: number; /** * The factor option is used to grow the delay exponentially. */ factor: number; /** * The maximum number of attempts or 0 if there is no limit on number of attempts. */ maxAttempts: number; /** * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled. */ minDelay: number; /** * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay. */ maxDelay: number; /** * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration. */ jitter: boolean; /** * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted. */ timeout: number; onAuthenticated: () => void; onAuthenticationFailed: ({ reason }: { reason: string; }) => void; onOpen: (event: Event) => void; onConnect: () => void; onMessage: (event: MessageEvent) => void; onOutgoingMessage: (message: OutgoingMessage) => void; onStatus: (status: any) => void; onSynced: () => void; onDisconnect: (event: CloseEvent) => void; onClose: (event: CloseEvent) => void; onDestroy: () => void; onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void; onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void; /** * Don’t output any warnings. */ quiet: boolean; } export declare class HocuspocusProvider extends EventEmitter { configuration: CompleteHocuspocusProviderConfiguration; subscribedToBroadcastChannel: boolean; webSocket: WebSocket | null; shouldConnect: boolean; status: WebSocketStatus; isSynced: boolean; isAuthenticated: boolean; lastMessageReceived: number; mux: mutex.mutex; intervals: any; connectionAttempt: { resolve: (value?: any) => void; reject: (reason?: any) => void; } | null; constructor(configuration: HocuspocusProviderConfiguration); setConfiguration(configuration?: Partial): void; connect(): Promise; createWebSocketConnection(): Promise; resolveConnectionAttempt(): void; rejectConnectionAttempt(): void; get document(): Y.Doc; get awareness(): Awareness; checkConnection(): void; forceSync(): void; registerEventListeners(): void; documentUpdateHandler(update: Uint8Array, origin: any): void; awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void; permissionDeniedHandler(reason: string): void; authenticatedHandler(): void; get serverUrl(): string; get url(): string; get synced(): boolean; set synced(state: boolean); get isAuthenticationRequired(): boolean; disconnect(): void; onOpen(event: Event): void; getToken(): Promise; webSocketConnectionEstablished(): Promise; startSync(): void; send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void; onMessage(event: MessageEvent): void; onClose(event: CloseEvent): void; destroy(): void; get broadcastChannel(): string; broadcastChannelSubscriber(data: ArrayBuffer): void; subscribeToBroadcastChannel(): void; disconnectBroadcastChannel(): void; broadcast(Message: ConstructableOutgoingMessage, args?: any): void; setAwarenessField(key: string, value: any): void; }