@source/rich-presence-sdk (0.2.0)

Published 2026-02-14 04:44:19 +00:00 by hibna

Installation

@source:registry=
npm install @source/rich-presence-sdk@0.2.0
"@source/rich-presence-sdk": "0.2.0"

About this package

@source/rich-presence-sdk

Source rich presence SDK for external applications.

What It Solves

  • Send Playing, Listening, Watching activities to Source.
  • Use Source desktop app's logged-in session through a local bridge (http://127.0.0.1:17634/rpc).
  • Manage auth tokens for external apps (login + refresh) with SourceAuthSession.
  • Auto-discover auth credentials from localStorage or environment variables.
  • Auto-discover the authenticated user profile (/users/@me) after session bootstrap.
  • Retry presence updates after token expiration (401) with minimal boilerplate.

Important

  • Session bootstrap priority:

    1. Explicit refreshToken
    2. Explicit email + password
    3. Discovered localStorage.refreshToken (default key: refreshToken)
    4. Discovered env vars (SOURCE_REFRESH_TOKEN or SOURCE_EMAIL + SOURCE_PASSWORD)
  • You can disable discovery:

    • autoDiscoverCredentials: false
    • autoDiscoverUser: false

Quick Start (No Login Prompt, Desktop Bridge)

When Source desktop app is installed, running, and already logged in, external apps can update rich presence without collecting credentials:

import {
  PresenceActivityType,
  SourceRichPresenceClient,
} from "@source/rich-presence-sdk";

const client = new SourceRichPresenceClient({
  transport: "local-bridge",
  // Optional override:
  // localBridgeUrl: "http://127.0.0.1:17634/rpc",
});

const bridge = await client.getBridgeHealth();
if (!bridge.authenticated) {
  throw new Error("Source desktop app is not logged in.");
}

await client.setActivity({
  type: PresenceActivityType.PLAYING,
  name: "My Game",
  details: "In a ranked match",
  state: "Map: Neon District",
});

Quick Start (Token-Based API)

import {
  PresenceActivityType,
  SourceAuthSession,
  SourceRichPresenceClient,
} from "@source/rich-presence-sdk";

const session = new SourceAuthSession({
  apiBaseUrl: "https://discord.hibna.com.tr/api",
  // Optional explicit bootstrap:
  // email: process.env.SOURCE_EMAIL,
  // password: process.env.SOURCE_PASSWORD,
  // refreshToken: process.env.SOURCE_REFRESH_TOKEN,
});

await session.initialize();
const user = session.getCurrentUserOrThrow();
console.log(`Authenticated as ${user.username} (${user.id})`);

const client = new SourceRichPresenceClient({
  apiBaseUrl: "https://discord.hibna.com.tr/api",
  accessToken: session.getAccessTokenOrThrow(),
});

await client.setActivity({
  type: PresenceActivityType.PLAYING,
  name: "My External App",
  details: "In a live match",
  state: "Room Alpha",
});

Client Transport Modes

  • transport: "auto" (default)
    • Uses API when accessToken exists.
    • Uses local bridge otherwise.
  • transport: "api"
    • Uses direct Source API (apiBaseUrl) with bearer token.
  • transport: "local-bridge"
    • Uses local desktop bridge (localBridgeUrl) and current desktop session.

External Integration Template

Use examples/local-bridge-template.ts for desktop-bridge mode, or examples/external-app-template.ts for token mode.

  • Creates rich presence client.
  • Reads bridge health in local mode.
  • Initializes session from explicit options or auto-discovery in token mode.
  • Periodically refreshes tokens.
  • Retries on 401.
  • Maps external app state to presence payload.

Suggested Environment Variables

  • SOURCE_API_BASE_URL (optional, default: https://discord.hibna.com.tr/api)
  • SOURCE_EMAIL (optional if refresh token exists)
  • SOURCE_PASSWORD (optional if refresh token exists)
  • SOURCE_REFRESH_TOKEN (optional if email/password exists)

Dependencies

Dependencies

ID Version
@source/shared ^0.1.0

Development Dependencies

ID Version
@source/tsconfig workspace:*
typescript ^5.7.3
Details
npm
2026-02-14 04:44:19 +00:00
3
latest
12 KiB
Assets (1)
Versions (2) View all
0.2.0 2026-02-14
0.1.0 2026-02-13