Skip to content

Commit 0db9e55

Browse files
committed
Enhancement: Add PubSub name as config value (#537)
1 parent 4688ea2 commit 0db9e55

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ config :live_debugger,
123123
signing_salt: "your_signing_salt", # Signing salt used for LiveDebugger.Endpoint
124124
adapter: Bandit.PhoenixAdapter, # Adapter used in LiveDebugger.Endpoint
125125
server: true, # Forces LiveDebugger to start even if project is not started with the `mix phx.server`
126+
127+
# Name for LiveDebugger PubSub (it will create new one so don't put already used name)
128+
config :live_debugger, :pubsub_name, LiveDebugger.CustomPubSub
126129
```
127130

128131
## Contributing

docs/config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ config :live_debugger,
5353
signing_salt: "your_signing_salt", # Signing salt used for LiveDebugger.Endpoint
5454
adapter: Bandit.PhoenixAdapter, # Adapter used in LiveDebugger.Endpoint
5555
server: true, # Forces LiveDebugger to start even if project is not started with the `mix phx.server`
56+
57+
# Name for LiveDebugger PubSub (it will create new one so don't put already used name)
58+
config :live_debugger, :pubsub_name, LiveDebugger.CustomPubSub
5659
```

lib/live_debugger.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ defmodule LiveDebugger do
2525
put_endpoint_config(config)
2626
put_live_debugger_tags(config)
2727

28+
pubsub_name = Keyword.get(config, :pubsub_name, LiveDebugger.PubSub)
29+
2830
children = [
29-
{Phoenix.PubSub, name: LiveDebugger.PubSub},
31+
{Phoenix.PubSub, name: pubsub_name},
3032
{LiveDebuggerWeb.Endpoint,
3133
[
3234
check_origin: false,
33-
pubsub_server: LiveDebugger.PubSub
35+
pubsub_server: pubsub_name
3436
]}
3537
]
3638

lib/live_debugger/utils/pubsub.ex

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ defmodule LiveDebugger.Utils.PubSub do
105105

106106
@impl true
107107
def broadcast(topic, payload) do
108-
Phoenix.PubSub.broadcast(LiveDebugger.PubSub, topic, payload)
108+
Phoenix.PubSub.broadcast(pubsub_name(), topic, payload)
109109
end
110110

111111
@impl true
@@ -118,7 +118,7 @@ defmodule LiveDebugger.Utils.PubSub do
118118

119119
@impl true
120120
def subscribe!(topic) do
121-
case Phoenix.PubSub.subscribe(LiveDebugger.PubSub, topic) do
121+
case Phoenix.PubSub.subscribe(pubsub_name(), topic) do
122122
:ok -> :ok
123123
{:error, reason} -> raise reason
124124
end
@@ -134,7 +134,11 @@ defmodule LiveDebugger.Utils.PubSub do
134134

135135
@impl true
136136
def unsubscribe(topic) do
137-
Phoenix.PubSub.unsubscribe(LiveDebugger.PubSub, topic)
137+
Phoenix.PubSub.unsubscribe(pubsub_name(), topic)
138+
end
139+
140+
defp pubsub_name() do
141+
Application.get_env(:live_debugger, :pubsub_name, LiveDebugger.PubSub)
138142
end
139143
end
140144
end

0 commit comments

Comments
 (0)