Phoenix.SocketClient.ChannelManager (phoenix_socket_client v0.7.0)

Dynamic supervisor for managing channel processes.

This module supervises individual channel processes, handling their lifecycle from creation to termination. It provides functionality for:

  • Starting and supervising channel processes
  • Finding channel processes by topic
  • Managing channel lifecycle events

Channel Lifecycle

Channels are started as child processes under this supervisor when:

Channels are terminated when:

  • The channel is left explicitly via Channel.leave/1
  • The socket connection is lost
  • The supervisor terminates

Summary

Functions

Finds the PID of a channel process by its topic.

Returns a specification to start this module under a supervisor.

Starts the ChannelManager dynamic supervisor.

Terminates all channel processes.

Functions

channel_pid(sup_pid, topic)

@spec channel_pid(pid(), String.t()) :: pid() | nil

Finds the PID of a channel process by its topic.

Parameters

  • sup_pid - The supervisor PID
  • topic - The channel topic to search for

Returns

  • pid - The channel PID if found
  • nil - If no channel with the given topic exists

Examples

channel_pid = Phoenix.SocketClient.ChannelManager.channel_pid(sup_pid, "rooms:lobby")

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_channel(sup_pid, topic, params, channel_module \\ nil)

@spec start_channel(pid(), String.t(), map(), module() | nil) ::
  {:ok, pid()} | {:error, term()}

Starts a channel process.

start_link(opts)

@spec start_link(keyword() | map()) :: {:ok, pid()} | {:error, term()}

Starts the ChannelManager dynamic supervisor.

Parameters

  • opts - Configuration options (unused, required by DynamicSupervisor)

Examples

{:ok, pid} = Phoenix.SocketClient.ChannelManager.start_link([])

terminate(cm_pid)

@spec terminate(pid()) :: :ok

Terminates all channel processes.

terminate_channel(pid, channel)