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:
@@ -61,3 +61,12 @@ conf.registerGlobalValue(
|
||||
"""IRC channel to send announce messages to.""",
|
||||
),
|
||||
)
|
||||
|
||||
conf.registerGlobalValue(
|
||||
NtrPlaylist,
|
||||
"clientId",
|
||||
registry.String(
|
||||
"limnoria",
|
||||
"""Identifier for this bot when connecting to the announce WebSocket.""",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -144,6 +144,7 @@ class NtrPlaylist(callbacks.Plugin):
|
||||
ws_url = self.registryValue("wsUrl")
|
||||
token = self.registryValue("adminToken")
|
||||
channel = self.registryValue("announceChannel")
|
||||
client_id = self.registryValue("clientId") or "limnoria"
|
||||
|
||||
if not ws_url or not token:
|
||||
LOGGER.warning("wsUrl or adminToken not configured, WS listener sleeping")
|
||||
@@ -154,7 +155,12 @@ class NtrPlaylist(callbacks.Plugin):
|
||||
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