import type { ConnectionState, WSocketOptions, EventCallback } from './types.js'; import { Channel } from './pubsub/channel.js'; import { PubSubNamespace } from './pubsub/index.js'; import { PushClient, type PushClientOptions } from './push/index.js'; export type { ConnectionState, WSocketOptions, ChannelSubscription, MessageMeta, PresenceMember, HistoryMessage, HistoryResult, HistoryOptions, PublishOptions, EventCallback, ClientMessage, ServerMessage, } from './types.js'; export { Channel } from './pubsub/channel.js'; export { Presence } from './pubsub/presence.js'; export { PubSubNamespace } from './pubsub/index.js'; export { PushClient, type PushClientOptions, type PushPayload, type PushSendResult, type PushSubscriptionRecord, type PushSubscriptionsResult } from './push/index.js'; /** * wSocket realtime client. * * Create via the {@link createClient} factory or the constructor directly: * * ```ts * import { createClient } from '@wsocket/sdk'; * * const client = createClient('wss://node00.wsocket.online', 'your-api-key'); * await client.connect(); * ``` */ export declare class WSocket { private ws; private url; private apiKey; private options; private state; private channels; private events; private reconnectAttempts; private reconnectTimer; private pingInterval; private lastMessageTimestamp; private resumeToken; /** Pub/Sub namespace — `client.pubsub.channel('name')` */ readonly pubsub: PubSubNamespace; /** Push client — lazily created, auto-configured from connection info */ private _push; /** * Create a new wSocket client. * * @param url - WebSocket server URL (e.g. `wss://node00.wsocket.online`) * @param apiKey - API key for authentication * @param options - Optional connection options */ constructor(url: string, apiKey: string, options?: WSocketOptions); /** * Push notifications — auto-configured, ready to use. * * @example * ```ts * // Subscribe browser to channels * await client.push.subscribe(['news', 'alerts']); * * // Send to a member * await client.push.send({ title: 'Hello' }, { to: 'user-1', channel: 'news' }); * * // Broadcast to all * await client.push.broadcast({ title: 'Hi all' }); * ``` */ get push(): PushClient; /** * Configure push with custom options (overrides auto-config). * Only needed if your push API uses a different URL or token. * * @param options - Custom push client options * @returns The newly created {@link PushClient} */ configurePush(options: PushClientOptions): PushClient; /** * Connect to the wSocket server. * * @returns A promise that resolves when the connection is established */ connect(): Promise; /** Disconnect from the server */ disconnect(): void; /** * Get or create a channel by name. * * @param name - Channel name * @returns The {@link Channel} instance for the given name */ channel(name: string): Channel; /** * Listen for client events. * * Supported events: `'connected'`, `'disconnected'`, `'reconnecting'`, `'error'`, `'state'`, * `'subscribed'`, `'unsubscribed'`, `'ack'` * * @param event - Event name * @param callback - Event handler * @returns `this` for chaining */ on(event: string, callback: EventCallback): this; /** * Remove a previously registered event listener. * * @param event - Event name * @param callback - The same callback reference passed to {@link on} * @returns `this` for chaining */ off(event: string, callback: EventCallback): this; /** * Current connection state. * * @returns `'disconnected'` | `'connecting'` | `'connected'` | `'reconnecting'` */ get connectionState(): ConnectionState; private send; private handleMessage; private setState; private emit; private resubscribeAll; private scheduleReconnect; private startPing; private stopPing; } /** * Create a new wSocket client. * * @example * ```ts * import { createClient } from '@wsocket/sdk'; * * const client = createClient('ws://localhost:9001', 'your-api-key'); * await client.connect(); * * // Pub/Sub (backward compatible) * const chat = client.channel('chat'); * chat.subscribe((data, meta) => console.log('Received:', data)); * chat.publish({ text: 'Hello!' }); * * // New namespaced API * client.pubsub.channel('chat').publish({ text: 'Hello!' }); * * // Push notifications * client.configurePush({ * baseUrl: 'http://localhost:9001', * token: 'your-api-key', * appId: 'your-app-id', * }); * await client.push!.sendToMember('user-1', { title: 'New message!' }); * ``` */ export declare function createClient(url: string, apiKey: string, options?: WSocketOptions): WSocket; //# sourceMappingURL=index.d.ts.map