import { Channel, UnsubscribeOptions, ConnectionHandler, DisconnectionHandler, ErrorHandler, MessageHandler } from './common.types'; /** * Adds an event handler that runs when a connection or reconnection * occurs. * * A connection occurs on the first subscription to a channel or channel resource or * when an existing connection is lost and then restored. * @param handler - The name of the function or * the function expression to run when a connection occurs. * @requiredField handler * @servicePath wix-realtime-frontend.ConnectionHandler */ export function onConnected(handler: ConnectionHandler): Promise; /** * Adds an event handler that runs when a disconnection occurs. * * A disconnection can occur, for example, if there is a network issue. * @param handler - The name of the function or * the function expression to run when a disconnection occurs. * @requiredField handler * @servicePath wix-realtime-frontend.DisconnectionHandler */ export function onDisconnected(handler: DisconnectionHandler): Promise; /** * Adds an event handler that runs when an error occurs. * * An error can occur when attempting to resubscribe after a disconnection. * Errors that occur during the initial subscription process cause the * Promise returned by the [`subscribe()`](#subscribe) function to reject * and do not trigger `onError()` event handlers. * @param handler - The name of the function or * the function expression to run when an error occurs. * @requiredField handler * @servicePath wix-realtime-frontend.ErrorHandler */ export function onError(handler: ErrorHandler): Promise; /** * Subscribes to a channel or channel resource. * * The `subscribe()` function subscribes to receive messages published on the * specified channel or channel resource and sets a function that handles * incoming messages when they are published to the channel. * * When you subscribe to a channel you do not receive messages published to * a resource on that same channel. To receive those messages, you must * explicitly subscribe to the specific resource. * * The specified message handler is run each time a message is published on * the given channel or channel resource. Use it to define what happens when * messages are received. * * You can subscribe to a channel or channel resource more than once to add * multiple message handlers. Each subscription returns a unique subscription * ID which can be used later to unsubscribe from the specific subscription * with that ID, without affecting the other subscriptions on the same channel * or channel resource. * @param channel - The channel, and optionally the resource, to * subscribe to. * @requiredField channel * @servicePath wix-realtime-frontend.Channel * @param handler - The name of the function or * the function expression to run when something is published to the subscription's * channel or channel resource. * @requiredField handler * @servicePath wix-realtime-frontend.MessageHandler * @returns Fulfilled - An ID representing the subscription, used for unsubscribing. * Rejected - Error that caused the rejection, such as insufficient * permissions. */ export function subscribe(channel: Channel, handler: MessageHandler): Promise; /** * Unsubscribes from a channel or channel resource. * * The `unsubscribe()` function unsubscribes from receiving messages published * on the specified channel or channel resource. * * + Use the `channel` property of the `UnsubscribeOptions` object * passed to the `options` parameter to unsubscribe from all subscriptions to a * specific channel or channel resource. * * When you unsubscribe from a channel you do not unsubscribe from the * resources on that same channel. To no longer receive messages on a * channel resource, you must explicitly unsubscribe from the specific resource. * * + Use the `subscriptionId` property of the `UnsubscribeOptions` object * passed to the `options` parameter to unsubscribe from a specific subscription. * * This option is typically used when you have more than one subscription to the same * channel or channel resource and you only want to unsubscribe from one of those subscriptions. * * Get a subscription's `subscriptionId` from the resolution of the Promise returned * when creating the subscription with the [`subscribe()`](#subscribe) function. * @param options - Options to use when unsubscribing. * @requiredField options * @servicePath wix-realtime-frontend.UnsubscribeOptions * @returns Fulfilled - When unsubscribed from the channel or channel resource. * Rejected - Error that caused the rejection. */ export function unsubscribe(options: UnsubscribeOptions): Promise;