Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

📺 raidtech-rpc

Server-side Discord Rich Presence for Jellyfin

Your friends see what you're watching. Nothing to install. Discord can even be closed.

C++17 Discord Social SDK Jellyfin Authentik Docker


✨ What it looks like

┌────────────────────────────────────────────────────────┐
│  Watching Raidtech                                     │
│  ┌──────────┐                                          │
│  │          │  Dirk Gently's Holistic Detective Agency │
│  │  poster  │  S02E07 · That Is Not Miami              │
│  │          │  10:12 ━━━━━━━━━━━━━━──────────── 40:32   │
│  └──────(◆)─┘                                          │
│          └─ Jellyfin logo · "Raidtech Media Server"    │
└────────────────────────────────────────────────────────┘
                    ▼  user hits pause  ▼
┌────────────────────────────────────────────────────────┐
│  Watching Raidtech                                     │
│  ┌──────────┐                                          │
│  │          │  Dirk Gently's Holistic Detective Agency │
│  │  poster  │  S02E07 · That Is Not Miami              │
│  │          │  ⏱ 0:42  (time since pause)              │
│  └──────(⏸)─┘                                          │
└────────────────────────────────────────────────────────┘

Inspired by PreMiD's YouTube presence — except it runs entirely on the server.


🧠 Why

Classic Jellyfin presence tools need a program running on every viewer's PC, next to the Discord desktop app. That means nothing on phones, TVs or consoles.

raidtech-rpc flips it around: the server watches Jellyfin sessions and talks to Discord on each user's behalf through the Discord Social SDK. Watch on a TV, a phone or a browser: your profile updates either way.


🏗️ Architecture

flowchart LR
    subgraph Viewers["👀 Viewers (any device)"]
        TV["📺 TV / phone / browser"]
    end

    subgraph Server["🖥️ raidtech-rpc (one process)"]
        Poller["⏱️ Session poller<br/>every second"]
        Mapper["🔗 Account mapper"]
        Clients["🎮 Discord SDK clients<br/>one per linked user"]
        Web["🌐 Link page<br/>OAuth callback"]
        Guard["🛡️ Revocation watcher"]
    end

    Jellyfin[("🎬 Jellyfin<br/>/Sessions")]
    Plugin[("📁 TwoFactorAuth<br/>SsoLinks (read-only)")]
    Authentik[("🔐 Authentik<br/>Discord source")]
    Discord(("💬 Discord"))

    TV --> Jellyfin
    Poller --> Jellyfin
    Poller --> Clients
    Web --> Mapper
    Mapper --> Authentik
    Mapper --> Plugin
    Guard --> Plugin
    Guard --> Authentik
    Clients ==>|"Rich Presence"| Discord
    Web <-->|"OAuth2"| Discord
Loading

🔗 How an account gets linked

There's no password to type and usually no consent screen: users who already sign in to Jellyfin with Discord through Authentik have already granted the scopes.

sequenceDiagram
    autonumber
    actor U as User
    participant R as raidtech-rpc
    participant D as Discord
    participant A as Authentik
    participant P as TwoFactorAuth files

    U->>R: Open the page → "Enable my Discord status"
    R->>D: authorize (prompt=none, openid sdk.social_layer_presence)
    D-->>R: code (no consent screen, already granted)
    R->>D: exchange code with client secret (confidential client)
    D-->>R: access + refresh token, Discord user id
    R->>A: who owns this Discord id? (source connection)
    A-->>R: Authentik user uid (= OIDC sub)
    R->>P: which Jellyfin user has SsoLink.Subject == uid?
    P-->>R: Jellyfin user id ✅
    R-->>U: "Enable your Discord status?" (avatar, name) · Confirm / Cancel
    U->>R: Confirm
    R->>D: SDK client connects → Ready
    R-->>U: "Connected as Raid" + pause / unlink buttons
Loading

A Discord account with no linked Jellyfin account is turned away with a friendly explanation. Nothing is stored until the user confirms; Cancel simply drops the tokens held in memory. (From Jellyfin, the plugin wraps all of this in a single button.)


🎬 Presence lifecycle

stateDiagram-v2
    direction LR
    [*] --> Idle
    Idle --> Playing: playback starts
    Playing --> Paused: pause
    Paused --> Playing: resume
    Playing --> Playing: seek > 5 s / next episode
    Playing --> Idle: stop
    Paused --> Idle: stop

    Idle: 🫥 Nothing shown
    Playing: ▶️ Poster + progress bar<br/>Jellyfin logo badge
    Paused: ⏸️ Poster + "time since pause"<br/>Pause badge
Loading
Content Activity type Line 1 Line 2
📺 Episode Watching Series name S02E07 · Episode title
🎞️ Movie Watching Movie title Year
🎵 Track Listening Track title Artist(s)

Jellyfin is polled every second, so play, pause, start and stop are picked up almost immediately. Players only report their position every ~10 s, so the progress bar is anchored on the moment the player sent it (LastPlaybackCheckIn) rather than on the moment it was read: no lag on the bar. Discord is only contacted when something actually changes, which keeps updates far below presence rate limits.


🛡️ Privacy & safety

  • 🔒 Confidential OAuth client. The code exchange and token refresh happen on the server, and the client secret never leaves it.
  • 📁 Read-only plugin mount. The TwoFactorAuth files also hold TOTP secrets and recovery codes; only UserId and SsoLinks are read.
  • 🔐 Least-privilege Authentik token. A service account with a role limited to view_user + view_useroauthsourceconnection.
  • ✂️ Automatic cut-off. If the Discord link disappears from Jellyfin (checked every minute) or from Authentik (every 10 minutes), the session is closed and its tokens are deleted from disk.
  • 🧯 Fail-safe. An unreadable or empty link folder (broken mount) never triggers mass unlinking.
  • ✅ No silent linking. Every link ends on a confirmation page showing the exact Discord account; nothing is saved before Confirm.
  • ⏯️ User control. Each user can pause, snooze or unlink, from Jellyfin or from their own page (signed cookie).
  • ℹ️ The sdk.social_layer_presence scope also covers friend-list permissions on Discord's consent screen. This service doesn't use them.

📦 Requirements

What Details
💬 Discord application Social SDK enabled, confidential client, redirect URI https://<your-domain>/oauth/callback
🔐 Authentik Discord source with extra scopes openid sdk.social_layer_presence; service account + API token
🎬 Jellyfin A dedicated API key; the JellyfinSecurity / TwoFactorAuth plugin (by ZL154) with an OIDC Discord provider
🧩 Discord Social SDK Download it yourself, it is not redistributable (see below)
🐳 Docker Compose ≥ 2.17 (for additional_contexts)

Getting the SDK

Download DiscordSocialSdk-<version>.zip from the Developer Portal (Social SDK → Downloads) and extract only these files next to compose.yaml:

sdk/linux/include/discordpp.h
sdk/linux/include/cdiscord.h
sdk/linux/lib/libdiscord_partner_sdk.so     ← from lib/release/

🚀 Deploy (Docker Compose / Dockge)

The image is built straight from this GitHub repo; only the SDK stays local. Your stack folder contains just:

📁 raidtech-rpc/
├── compose.yaml
├── .env              ← from .env.example
└── sdk/linux/...     ← Discord Social SDK
docker compose up -d --build

Adjust the TwoFactorAuth/users path in compose.yaml to your Jellyfin config folder.

🔄 Updating: click Update in Dockge (or run docker compose up -d --build). It fetches the latest main, rebuilds and restarts.

🛠️ Local build from a clone:

docker buildx build --build-context sdk=sdk/linux -t raidtech-rpc .

🧩 Jellyfin plugin

Plugin Jellyfin .NET

The service works on its own (users link from https://<your-domain>/), but the Raidtech RPC plugin brings everything inside Jellyfin, so users never need to know the URL.

What users get

                                         ┌───────────────────────────────────┐
                                         │ ◉ Discord Status               ✕  │
                                         ├───────────────────────────────────┤
                                         │ ● Sharing on               Raid   │
                                         │ ┌───────────────────────────────┐ │
                                         │ │ WATCHING RAIDTECH             │ │
                                         │ │ ┌──────┐ Dirk Gently's Holi…  │ │
                                         │ │ │poster│ S02E07 · That Is No… │ │
                                         │ │ └───(◆)┘ Playing              │ │
                                         │ └───────────────────────────────┘ │
                                         │ [        Pause sharing        ]   │
                                         │ [ Hide for 1 h ] [Until tomorrow] │
                                         │ [    Unlink my Discord account  ] │
                                         └───────────────────────────────────┘
                                                                        (◉)●  ← floating button
Feature Details
🟣 Floating Discord button Bottom right of every page, with a status dot: 🟢 sharing · 🟠 paused · ⚪ not linked. Hidden during video playback.
🪟 Panel Live preview of the card your friends see (same poster and badge as on Discord), Pause / Resume, Hide for 1 h, Until tomorrow (sharing resumes by itself), Unlink.
👤 Profile entry A Discord Status block at the top of Settings (#/mypreferencesmenu) that opens the panel.
👋 Welcome prompt Shown to users who haven't linked yet: Link my Discord account, Later (asks again in a week), Don't ask again. Remembered server-side, so it follows the user across devices.
🔗 One-button linking Works even for password-only accounts: if Discord isn't linked to the Jellyfin account yet, the button runs JellyfinSecurity's own account-link flow first, then chains into the presence link.
✅ Explicit confirmation Before anything is saved, a page shows which Discord account (avatar, name, @username) is about to be linked, with Confirm / Cancel.

How it fits together

flowchart LR
    subgraph Browser["🌐 Jellyfin web page"]
        W["🟣 widget.js<br/>button · panel · prompt"]
    end

    subgraph JF["🎬 Jellyfin server"]
        MW["🧩 Middleware<br/>adds &lt;script&gt; to index.html<br/>(in memory)"]
        API["🔌 /RaidtechRpc/*<br/>authenticated by the<br/>Jellyfin session"]
        JS["🔐 JellyfinSecurity<br/>/TwoFactorAuth/Oidc/LinkBegin"]
    end

    RPC["🖥️ raidtech-rpc<br/>/api/plugin/*"]

    MW -. serves .-> W
    W -->|"user token<br/>(same origin)"| API
    API -->|"user id + shared secret"| RPC
    W -->|"not linked yet"| JS
Loading
  • Nothing on disk is touched. The <script> tag is added to index.html as Jellyfin serves it, so the plugin survives Jellyfin updates and uninstalls cleanly.
  • Jellyfin tokens never leave Jellyfin. The widget only calls the plugin's own endpoints; the plugin forwards the user id to the service with a shared secret.
  • No account hijacking. Links started from Jellyfin carry a one-time ticket bound to that Jellyfin user. A Discord account that belongs to another Jellyfin user is refused.

One-button linking, step by step

sequenceDiagram
    autonumber
    actor U as User (password account)
    participant W as Widget
    participant S as JellyfinSecurity
    participant A as Authentik → Discord
    participant R as raidtech-rpc

    U->>W: "Link my Discord account"
    W->>S: POST /TwoFactorAuth/Oidc/LinkBegin/connect-with-discord
    S-->>W: authUrl (bound to this Jellyfin user)
    W->>A: popup → Discord consent (presence scopes included)
    A-->>S: callback → SsoLink saved
    S-->>W: postMessage {type: "tfa-link-oidc", success: true}
    W->>R: POST /RaidtechRpc/Link → one-time ticket
    W->>R: popup → /link?ticket=… (prompt=none, no Discord screen)
    R-->>U: "Enable your Discord status?" + avatar · Confirm / Cancel
    U->>R: Confirm
    R-->>W: postMessage "raidtech-rpc:linked" → popup closes, dot turns 🟢
Loading

Users who already sign in with Discord skip steps 2–6. If the browser blocks the second popup (it isn't opened by a click), the panel shows a "Last step" button instead.

Install

  1. Dashboard → Plugins → Repositories → +, and add:
    https://raw.githubusercontent.com/raidoudou/raidtech-rpc/main/plugin-repo/manifest.json
    
  2. Catalog → Raidtech RPC → Install, then restart Jellyfin.
  3. Set RPC_PLUGIN_SECRET in the service's .env (≥ 24 random chars) and Update the stack.
  4. Open the plugin settings and fill them in:
Setting Default Purpose
Enable the Raidtech RPC interface ✅ Master switch for the injected widget
Internal URL of the service http://192.168.1.25:8787 How the Jellyfin server reaches raidtech-rpc
Shared secret — Same value as RPC_PLUGIN_SECRET
Discord provider ID in JellyfinSecurity connect-with-discord Used for one-button linking of password accounts
Show the Discord button ✅ Floating button bottom right
Offer linking to unlinked users ✅ Welcome prompt

Updates show up in the Jellyfin catalog like any other plugin.

Building a release

./plugin/build.ps1 -Version 1.3.0.0 -Changelog "What changed"

The script builds with the official .NET 10 SDK image (no local SDK needed), zips the DLL into plugin-repo/, computes its MD5 and prepends the version to manifest.json. Commit and push plugin-repo/ and Jellyfin will offer the update.


⚙️ Configuration

Variable Default Purpose
DISCORD_APP_ID — Discord application ID
DISCORD_CLIENT_SECRET — Existing client secret (don't reset it if other services share the app)
RPC_PUBLIC_URL https://rpc.raidtech.xyz Public URL; the redirect URI is <url>/oauth/callback
RPC_ADMIN_KEY — Admin page key + cookie signing key (≥ 16 chars)
RPC_PLUGIN_SECRET — Shared secret with the Jellyfin plugin (≥ 24 chars); empty disables the plugin API
RPC_OAUTH_PROMPT none none = skip the consent screen when already granted
JELLYFIN_URL — Internal Jellyfin URL (API)
JELLYFIN_API_KEY — Jellyfin API key
JELLYFIN_PUBLIC_URL https://media.raidtech.xyz Public URL used for posters
JELLYFIN_POLL_SECONDS 1 Session polling interval (one cheap LAN request, kept-alive connection)
JELLYFIN_OIDC_PROVIDER_ID connect-with-discord Provider id in the plugin's SsoLinks
AUTHENTIK_URL https://authentication.raidtech.xyz Authentik base URL
AUTHENTIK_TOKEN — API-intent token of the service account
AUTHENTIK_DISCORD_SOURCE discord Slug of the Discord source

🗺️ Endpoints

Route Who What
/ everyone Enable the status, then pause / unlink
/link → /oauth/callback → /link/confirm everyone Discord OAuth flow, then explicit confirmation
/api/plugin/* Jellyfin plugin Status, pause, snooze, unlink, link ticket, prompt dismissal (shared secret)
/admin?k=… admin Linked accounts, SDK status, now playing, refresh / unlink
/icon/jellyfin.png · /icon/pause.png Discord Small badges shown on the presence
/healthz Docker Health probe

Plugin endpoints, on the Jellyfin server:

Route Auth What
GET /RaidtechRpc/widget.js none The injected widget
GET /RaidtechRpc/Status Jellyfin session Linked?, sharing state, card preview, prompt flag
POST /RaidtechRpc/Toggle · Snooze?minutes= · Unlink Jellyfin session Sharing controls
POST /RaidtechRpc/Link Jellyfin session One-time link ticket bound to the user
POST /RaidtechRpc/Dismiss?mode=later|never Jellyfin session Welcome prompt answer

🧪 Validated

  • Presence shows with no Discord client running
  • Watching activity type
  • Linux Social SDK inside a Debian container
  • Several Discord clients in one process
  • External poster URLs (straight from Jellyfin)
  • prompt=none linking with no consent screen
  • Self-service linking via Authentik → TwoFactorAuth mapping
  • Jellyfin 12.4 plugin: in-memory injection, button, panel, profile entry, welcome prompt
  • One-button linking of a password-only account through JellyfinSecurity
  • Explicit confirmation page before any link is saved

⚠️ Known limits

  • The card title is always "Watching <Discord app name>": the SDK overrides the activity name.
  • Discord crops images to a square, so tall posters lose a bit of top and bottom.
  • The Social SDK's Linux support is flagged experimental by Discord.
  • The plugin's button and panel live in the web interface (browsers and the apps that embed it); native TV apps such as Android TV or Swiftfin don't show them. Presence itself works everywhere.

Made with ☕ for Raidtech Media Server

Not affiliated with Discord or Jellyfin. The user-facing pages are in French.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages