PusherServer.Cluster (pusher_server v0.1.2)

Copy Markdown View Source

The one place the websocket handler and HTTP router go through for anything that may need to reach other nodes: broadcasting, presence, and channel occupancy.

It always does the node-local part itself (delivering to sockets connected to this node via the instance's Registry) and then asks the configured PusherServer.Backend to carry the rest across the cluster. With the default Local backend that second step is a no-op, so a single node behaves exactly as before.

Summary

Functions

Fires the channel_occupied webhook.

Fires the channel_vacated webhook.

Tells the cluster (and the webhook, if configured) that a user joined a presence channel.

Tells the cluster (and the webhook, if configured) that a user's last connection left a presence channel.

The backend module configured for this instance.

Delivers message (a map, or an already-encoded JSON string) to every subscriber of channel on this node, then to every other node through the backend. exclude_socket_id is skipped everywhere.

Records a local subscribe. true if the channel just became occupied cluster-wide.

Records a local unsubscribe. true if the channel just became vacant cluster-wide.

Names of every channel with at least one subscriber, across the cluster.

Delivers to this node's subscribers only. Used for messages that arrived from other nodes.

Adds a presence entry. true if this is the user's first connection on the channel, cluster-wide.

Unique members of a presence channel as {user_id, user_info} pairs.

Removes a presence entry. Returns {is_users_last_connection, user_id}.

Silently re-records an already-announced presence entry (used after Redis lost its data).

Total subscribers on channel across the cluster.

Functions

announce_channel_occupied(name, channel)

Fires the channel_occupied webhook.

announce_channel_vacated(name, channel)

Fires the channel_vacated webhook.

announce_member_added(name, channel, user_id, user_info, exclude_socket_id)

Tells the cluster (and the webhook, if configured) that a user joined a presence channel.

announce_member_removed(name, channel, user_id)

Tells the cluster (and the webhook, if configured) that a user's last connection left a presence channel.

backend(name)

The backend module configured for this instance.

broadcast(name, channel, message, exclude_socket_id \\ nil)

Delivers message (a map, or an already-encoded JSON string) to every subscriber of channel on this node, then to every other node through the backend. exclude_socket_id is skipped everywhere.

channel_joined(name, channel)

Records a local subscribe. true if the channel just became occupied cluster-wide.

channel_left(name, channel)

Records a local unsubscribe. true if the channel just became vacant cluster-wide.

list_channels(name)

Names of every channel with at least one subscriber, across the cluster.

local_dispatch(name, channel, encoded, exclude_socket_id)

Delivers to this node's subscribers only. Used for messages that arrived from other nodes.

presence_add(name, channel, socket_id, user_id, user_info)

Adds a presence entry. true if this is the user's first connection on the channel, cluster-wide.

presence_members(name, channel)

Unique members of a presence channel as {user_id, user_info} pairs.

presence_remove(name, channel, socket_id)

Removes a presence entry. Returns {is_users_last_connection, user_id}.

presence_restore(name, channel, socket_id, user_id, user_info)

Silently re-records an already-announced presence entry (used after Redis lost its data).

subscription_count(name, channel)

Total subscribers on channel across the cluster.