fix: separate bot vs viewer WebSocket connections, add client identification
The dashboard's own WS connection was being counted as a bot subscriber,
causing "1 bot connected" with no bots actually present. Now WS clients
send a role ("bot" or "viewer") in the subscribe message. Only bots count
toward the subscriber total. Bot plugins also send a configurable client_id
so the dashboard shows which specific bots are connected.
Made-with: Cursor
This commit is contained in:
@@ -24,6 +24,7 @@ class NtrPlaylistSection(types.StaticSection):
|
||||
display_timezone = types.ValidatedAttribute("display_timezone", default="America/New_York")
|
||||
ws_url = types.ValidatedAttribute("ws_url", default="ws://127.0.0.1:8000/ws/announce")
|
||||
announce_channel = types.ValidatedAttribute("announce_channel", default="#sewerchat")
|
||||
client_id = types.ValidatedAttribute("client_id", default="sopel")
|
||||
|
||||
|
||||
_ws_stop = None
|
||||
@@ -54,6 +55,7 @@ def _ws_listener(bot):
|
||||
ws_url = bot.settings.ntr_playlist.ws_url
|
||||
token = bot.settings.ntr_playlist.admin_token
|
||||
channel = bot.settings.ntr_playlist.announce_channel
|
||||
client_id = bot.settings.ntr_playlist.client_id or "sopel"
|
||||
|
||||
if not ws_url or not token:
|
||||
LOGGER.warning("ws_url or admin_token not configured, WS listener sleeping")
|
||||
@@ -64,7 +66,12 @@ def _ws_listener(bot):
|
||||
try:
|
||||
ws = websocket.WebSocket()
|
||||
ws.connect(ws_url, timeout=10)
|
||||
ws.send(json.dumps({"type": "subscribe", "token": token}))
|
||||
ws.send(json.dumps({
|
||||
"type": "subscribe",
|
||||
"token": token,
|
||||
"role": "bot",
|
||||
"client_id": client_id,
|
||||
}))
|
||||
LOGGER.info("Connected to announce WebSocket at %s", ws_url)
|
||||
backoff = 5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user