PhoenixKit.PubSubHelper (phoenix_kit v1.7.71)

Copy Markdown View Source

Helper for dynamically resolving the PubSub server to use.

This module provides functions to get the appropriate PubSub server based on configuration. It will use the configured pubsub from the parent application.

Configuration

Configure the PubSub server in your application:

config :phoenix_kit, pubsub: MyApp.PubSub

If not configured, PhoenixKit will attempt to derive it from the parent app name (e.g., MyApp -> MyApp.PubSub).

Summary

Functions

Broadcasts a message to a topic using the configured PubSub server.

Broadcasts a message using a specific PubSub server.

Gets the PubSub server module to use.

Gets the PubSub server from socket endpoint config.

Subscribes to a topic using the configured PubSub server.

Subscribes to a topic using a specific PubSub server.

Functions

broadcast(topic, message)

Broadcasts a message to a topic using the configured PubSub server.

broadcast(pubsub_server, topic, message)

Broadcasts a message using a specific PubSub server.

pubsub()

Gets the PubSub server module to use.

Returns the configured pubsub server, or derives it from parent_module config.

pubsub_from_socket(socket)

Gets the PubSub server from socket endpoint config.

This is useful in LiveView contexts where the socket has access to the endpoint configuration.

subscribe(topic)

Subscribes to a topic using the configured PubSub server.

subscribe(pubsub_server, topic)

Subscribes to a topic using a specific PubSub server.