import { type SubscribeChannel, type MessageHandler, type SubscriptionOptions, type UnsubscribeOptions } from '@wix/realtime-common/types'; import type { HttpClient } from '@wix/sdk-types'; interface SubscribeSignature { /** * Subscribes to a channel or resource. * * The method attempts to establish a subscription to the specified channel or resource. It returns the subscription ID immediately while the subscription is attempted in the background. * * Use the `options` parameter to register handlers that run whenever the subscription succeeds or generates an error. For some errors, the subscription is re-attempted automatically. The `onSubscribed()` handler runs on every successful re-subscription. * * Learn more about the [subscription lifecycle](https://dev.wix.com/docs/sdk/core-modules/realtime/realtime/subscriber/introduction#core-modules_realtime_realtime_subscriber_subscription-lifecycle). * * @example Subscribe to a channel * ```ts * import { subscriber } from '@wix/realtime'; * * const subscriptionId = subscriber.subscribe( * { name: 'my-channel' }, * (message, channel) => { * console.log('Received:', message.payload); * }, * ); * ``` * * @example Subscribe to a channel: Self-hosted * ```ts * import { createClient } from '@wix/sdk'; * import { subscriber } from '@wix/realtime'; * * // Import the auth strategy for the relevant access type * // Import the relevant host module if needed * * const client = createClient({ * modules: { subscriber }, * // Include the auth strategy and host as relevant * }); * * const subscriptionId = client.subscriber.subscribe( * { name: 'my-channel' }, * (message, channel) => { * console.log('Received:', message.payload); * }, * { * onSubscribed: (id, isSynced) => console.log('Subscribed', id), * onSubscriptionError: (error, id) => console.error('Error', error), * }, * ); * ``` * * @param channel - Channel and resource to subscribe to. * @requiredField channel * @param messageHandler - Handler that runs whenever a message is published to the channel or resource. * @requiredField messageHandler * @param options - [Lifecycle handlers](https://dev.wix.com/docs/sdk/core-modules/realtime/realtime/subscriber/introduction#core-modules_realtime_realtime_subscriber_subscription-lifecycle) for subscription events. */ (channel: SubscribeChannel, messageHandler: MessageHandler, options?: SubscriptionOptions): string; } /** @hidden */ export declare function subscribe(httpClient: HttpClient): SubscribeSignature; interface UnsubscribeSignature { /** * Removes 1 or more subscriptions. * * You can unsubscribe in 3 ways: * - By `subscriptionId`: removes a single subscription. * - By `channel`: removes all subscriptions to that channel or resource. * - By both: removes the specific subscription, verifying it matches the channel. * * When the last subscription on a connection is removed, the connection * closes automatically. * * @example Remove the specified subscription. * ```ts * import { subscriber } from '@wix/realtime'; * * subscriber.unsubscribe({ subscriptionId }); * ``` * * @example Remove the specified subscription: Self-hosted * ```ts * import { subscriber } from '@wix/realtime'; * import { createClient } from '@wix/sdk'; * * // Import the auth strategy for the relevant access type * // Import the relevant host module if needed * * const client = createClient({ * modules: { subscriber }, * // Include the auth strategy and host as relevant * }); * * // Remove the specified subscription * client.subscriber.unsubscribe({ subscriptionId }); * * // Remove all subscriptions from the specified channel * client.subscriber.unsubscribe({ channel: { name: 'my-channel' } }); * ``` * * @param options - Unsubscribe details. You must specify `channel`, `subscriptionId`, or both. * @requiredField options */ (options: UnsubscribeOptions): void; } /** @hidden */ export declare function unsubscribe(_: HttpClient): UnsubscribeSignature; /** @internal Resets all module-level state. Only for use in tests. */ export declare function _resetForTesting(): void; export {};