PhoenixMountable.PubSub (PhoenixMountable v0.2.1)

Copy Markdown View Source

PubSub topics scoped to a mount.

Users of the same mount see each other's changes live; two mounts of the same library (or two libraries) never share a topic. Messages travel across the cluster like any Phoenix.PubSub message.

# in a LiveView of the library
PhoenixMountable.PubSub.subscribe(socket.assigns.mount, "items")

# anywhere, after a change
PhoenixMountable.PubSub.broadcast(mount, "items", {:item_updated, item})

The PubSub server is the mount's :pubsub option, or the host endpoint's :pubsub_server.

Summary

Functions

Broadcasts message to the subscribers of topic in the mount, on all nodes.

Like broadcast/3, but not to the caller.

The PubSub server of the mount.

Subscribes the caller to topic in the mount.

The full topic name for topic in the mount.

Unsubscribes the caller from topic in the mount.

Functions

broadcast(mount, topic, message)

@spec broadcast(PhoenixMountable.Mount.t(), String.t(), term()) ::
  :ok | {:error, term()}

Broadcasts message to the subscribers of topic in the mount, on all nodes.

broadcast_from(mount, topic, message)

@spec broadcast_from(PhoenixMountable.Mount.t(), String.t(), term()) ::
  :ok | {:error, term()}

Like broadcast/3, but not to the caller.

local_broadcast(mount, topic, message)

@spec local_broadcast(PhoenixMountable.Mount.t(), String.t(), term()) :: :ok

Like broadcast/3, but only on this node.

server!(mount)

@spec server!(PhoenixMountable.Mount.t()) :: atom()

The PubSub server of the mount.

subscribe(mount, topic)

@spec subscribe(PhoenixMountable.Mount.t(), String.t()) :: :ok | {:error, term()}

Subscribes the caller to topic in the mount.

topic(mount, topic)

@spec topic(PhoenixMountable.Mount.t(), String.t()) :: String.t()

The full topic name for topic in the mount.

unsubscribe(mount, topic)

@spec unsubscribe(PhoenixMountable.Mount.t(), String.t()) :: :ok

Unsubscribes the caller from topic in the mount.