subscribe( )


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.

Method Declaration
Copy
Method Parameters
channelSubscribeChannelRequired

Channel and resource to subscribe to.


messageHandlerfunctionRequired

messageHandler(message: Message, channel: SubscribeChannel): void Handler that runs whenever a message is published to the channel or resource.


optionsSubscriptionOptions

Lifecycle handlers for subscription events.

Returns
Return Type:string
Errors

This method doesn't return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?