- Escape angle brackets around IRC username so Owncast doesn't swallow them as HTML tags (<nick> instead of <nick>) - Register a chat user via POST /api/chat/register to obtain an accessToken, then pass it as a query param when connecting to /ws (Owncast closes the WebSocket immediately without one) - Cache the access token across reconnections; re-register only on rejection - Add ws_display_name config option (default "IRC Bridge") - Fix echo suppression: record_sent and is_echo now both compare raw body instead of mismatched formatted/raw values Made-with: Cursor
1.8 KiB
1.8 KiB
Fix IRC-Owncast Bridge Issues
Task
Fix three issues: IRC username stripped in Owncast chat, WebSocket connection always failing, and echo suppression bug.
Changes Made
1. HTML-escape username in IRC->Owncast messages (src/router.rs)
- Changed
<username>to<username>in the formatted message sent to Owncast's chat API - Owncast renders chat as HTML, so bare angle brackets were being interpreted as HTML tags and swallowed
2. Fix WebSocket authentication (src/websocket.rs, src/owncast_api.rs, src/main.rs)
- Root cause: Owncast's
/wsendpoint requires anaccessTokenquery parameter from a registered chat user. The bridge was connecting without one. - Added
register_chat_user()toOwncastApiClient-- callsPOST /api/chat/registerto get a user-level access token - Updated
run_websocket_taskto register a chat user, cache the token, and pass it as?accessToken=in the WebSocket URL - Token is cached across reconnections; re-registration happens only if rejected
- Added
base_url()accessor toOwncastApiClient
3. Add ws_display_name config field (src/config.rs, config.toml, config.example.toml)
- New
ws_display_namefield onOwncastConfig(default: "IRC Bridge") controls the display name of the WebSocket chat user in Owncast
4. Fix echo suppression bug (src/router.rs)
record_sentwas storing the full formatted string ([IRC] <nick> body) butis_echocompared against rawbody-- they never matched- Changed
record_sentto store the rawbodyso echo suppression actually works - Moved the
is_echocheck before formatting in the Owncast->IRC path to avoid unnecessary work
Follow-up Items
- Owncast admin still needs to configure webhook URL pointing to the bridge's port 9078
- The bridge's WebSocket user will appear as "IRC Bridge" in Owncast's connected users list