SDK Reference
Loading the SDK
At runtime (OBS) load it from the running app; for development/reference load it from this site.
<!-- runtime (OBS): running app -->
<script src="http://localhost:3030/sdk/castdeck-sdk.js"></script>
<!-- development / reference -->
<script src="https://castdeck.studio/developers/sdk/castdeck-sdk.js"></script>
API
| API | |
|---|---|
setup(options?) | options = { port?: number = 3030, level?: "public" | "rich" }. Call before connect(). |
connect() | Opens the comment stream (SSE /comments/events). Auto-reconnects every 3s. |
disconnect() | Closes the stream. |
subscribe(cb) | cb(ev: ProjectedEvent) is called for every event. Returns an unsubscribe function. |
subscribeKind(kind, cb) | kind = "comment" | "gift" | "membership" | "follow" | "stats". Returns an unsubscribe function. |
onSnapshot(cb) | cb(events[]) with the recent history on connect (up to 50). Returns an unsubscribe function. |
getTierColor(tier) | Maps a gift tier (blue/teal/green/yellow/orange/magenta/red) to a CSS color string. |
Event data (ProjectedEvent)
public is the default. rich (amounts, avatar, etc.) requires the streamer’s consent; without it the stream is automatically downgraded to public.
| Field | Level | |
|---|---|---|
kind | public | "comment" | "gift" | "membership" | "follow" | "stats" |
platform | public | "youtube" | "twitch" | "twitcasting" | "kick" | "nicolive" | "whowatch" |
id | public | Stable per-platform id. |
timestamp | public | Epoch milliseconds. |
name | public | Display name of the author. |
message | public | Comment text. |
isMember / isModerator / isOwner | public | Author role flags. |
anonymous | public | True for anonymous posters (Niconico 184 / Whowatch). |
tier | public | Gift color tier. |
gift.displayText / gift.tier / gift.itemName | public | Gift display info. |
gift.amount / gift.currency / gift.jpyEstimate | rich | Numeric gift amounts (require viewer consent). |
membershipEvent / months | public / rich | Membership event type / duration. |
userId | rich | Prefixed viewer id. |
avatarUrl | rich | Author avatar URL. |
memberMonths | rich | Membership months. |
stats | public | Viewer / like counters for stats events. |
castdeck-sdk.d.ts — TypeScript type definitions (exact API & event types)