# `Jido.Messaging.PubSub`
[🔗](https://github.com/agentjido/jido_messaging/blob/v1.0.0/lib/jido_messaging/pubsub.ex#L1)

Optional Phoenix.PubSub integration for cross-node events and LiveView support.

This module provides publish/subscribe functionality for room events when
Phoenix.PubSub is available. All functions gracefully handle cases where
PubSub is not configured.

## Usage

    defmodule MyApp.Messaging do
      use Jido.Messaging, persistence: Jido.Messaging.Persistence.ETS,
        pubsub: MyApp.PubSub
    end

    # Subscribe to room events
    MyApp.Messaging.subscribe("room_123")

    # Events received:
    # {:message_added, %Message{}}
    # {:participant_joined, %Participant{}}
    # {:participant_left, participant_id}

# `broadcast`

```elixir
@spec broadcast(module(), String.t(), term()) :: :ok | {:error, :not_configured}
```

Broadcast an event to all subscribers of a room.

Returns `:ok` on success, or `{:error, :not_configured}` if PubSub is not configured.

# `configured?`

```elixir
@spec configured?(module()) :: boolean()
```

Check if PubSub is configured for the given instance module.

# `pubsub_available?`

```elixir
@spec pubsub_available?() :: boolean()
```

Check if Phoenix.PubSub is available at runtime.

# `subscribe`

```elixir
@spec subscribe(module(), String.t()) :: :ok | {:error, :not_configured}
```

Subscribe to events for a room.

Returns `:ok` on success, or `{:error, :not_configured}` if PubSub is not configured.

# `topic`

```elixir
@spec topic(String.t()) :: String.t()
```

Generate the topic string for a room.

# `unsubscribe`

```elixir
@spec unsubscribe(module(), String.t()) :: :ok | {:error, :not_configured}
```

Unsubscribe from events for a room.

Returns `:ok` on success, or `{:error, :not_configured}` if PubSub is not configured.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
