The Realtime APIs let you send and receive messages between a site backend and connected clients in real time. When a backend service publishes messages to a channel, clients subscribed to that channel receive them instantly.
With the Realtime APIs, you can:
Learn more about how the modules work together.
Channels are how publishers send messages to subscribers. Each channel has a unique name and can contain multiple resources. Subscribers can subscribe to channels, resources, or both.
Resources act as independent subchannels that let you send messages only to subscribers who listen on that resource. For example, a chat channel might use a separate resource for each chat room, allowing subscribers to listen to a specific room without receiving messages from other rooms.
Subscribers to a channel don't receive messages sent to a resource on that channel. Similarly, subscribers to a resource don't receive messages sent to its parent channel.
Permissions follow a cascading model: Each channel and resource can have its own permissions handlers, but if a resource doesn't have a designated handler, it inherits its parent channel's handler. Similarly, when neither the resource nor its parent channel have permissions handlers, the default handler runs.
Learn more about controlling subscriber permissions with the Site API and permission resolution.
Each module handles a different part of the messaging pipeline:
Before messages can be sent, some setup is required.
To set up the messaging pipeline:
You can also register handlers for subscription successes, reconnections, and errors. Learn more about the subscriber lifecycle.
Once the messaging pipeline is set up, the following occurs each time a message is sent:
publish() with a channel or resource and a message payload.realtime_check_permission hook runs for each subscriber, checking their permissions.By default, subscribers can only subscribe to channels managed by the current app or by the site's backend code. However, subscribers can also subscribe to channels managed by a different Wix app, as long as that app is installed on the same site. You can subscribe to channels provided by apps created by Wix as well as 3rd-party Wix apps.
To subscribe to a channel managed by another app, specify that app's app ID. The app that provides that channel must implement the Realtime Permissions Provider service plugin to authorize cross-app subscriptions.
It's important to note the following points before starting to code:
read permissions are always true.