import { Socket, Channel } from "phoenix"; export declare type LiveStateConfig = { /** The end point to connect to, should be a websocket url (ws or wss) */ url?: string; /** The topic for the channel */ topic?: string; /** will be sent as params on channel join */ params?: object; /** the options passed to the phoenix socket */ socketOptions?: object; }; export declare type LiveStateError = { /** * Describes what type of error occurred. */ type: string; /** The original error payload, type depends on error */ message: string; }; export declare type LiveStateChange = { /** state version as known by the channel */ version: number; state: object; }; export declare type LiveStatePatch = { /** the version this patch is valid for */ version: number; /** the json patch to be applied */ patch: any; }; /** * This is the lower level API for LiveState. It connects to a * [live_state]() channel over websockets and is responsible * for maintaining the state. From the channel it receives `state:change` events which * replace the state entirely, or `state:patch` events which contain a json * patch to be applied. * * ## Events * * ### Dispatching * A `CustomEvent` dispatched to LiveState will be pushed over the channel as * event with the `lvs_evt:` prefix and the detail property will become the payload * * ### Listeners * * Events which begin with `livestate-` are assumed to be livestate internal events. * The following CustomEvents are supported: * * | Event | Detail type | Description | * | ----------------- | ----------------------- | ------------------------------------ | * | livestate-error | {@link LiveStateError} | Occurs on channel or socket errors | * | livestate-change | {@link LiveStateChange} | on `state:change` from channel | * | livestate-patch | {@link LiveStatePatch} | on `state:patch` from channel | * | livestate-connect | none | on successful socket or channel join | * * Will occur on channel or socket errors. The `detail` will consist of * * Any other event name not prefixed with `livestate-` will be assumed to be a channel * event and will result in a event being listened to on the channel, which when * received, will be dispatched as a CustomEvent of the same name with the payload * from the channel event becoming the `detail` property. */ export declare class LiveState implements EventTarget { config: LiveStateConfig; channel: Channel; socket: Socket; state: any; stateVersion: number; connected: boolean; eventTarget: EventTarget; constructor(config: LiveStateConfig); /** connect to socket and join channel. will do nothing if already connected */ connect(): void; /** leave channel and disconnect from socket */ disconnect(): void; /** for events that begin with 'livestate-', add a listener. For * other events, additionally call `channel.on` to receive the event * over the channel, which will then be dispatched. */ addEventListener(type: any, listener: any, options?: any): void; removeEventListener(type: any, listener: any, options?: any): void; /** @deprecated */ subscribe(subscriber: Function): void; /** @deprecated */ unsubscribe(subscriber: any): void; emitServerError(error: any): void; emitError(type: any, error: any): void; extractMessage(error: any): any; handleChange({ state, version }: { state: any; version: any; }): void; handlePatch({ patch, version }: { patch: any; version: any; }): void; versionMatches(version: any): boolean; pushEvent(eventName: any, payload: any): void; /** Pushes the event over the channel, adding the `lvs_evt:` prefix and using the CustomEvent * detail property as the payload */ dispatchEvent(event: Event): boolean; pushCustomEvent(event: any): void; } export default LiveState;