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.

FieldLevel
kindpublic"comment" | "gift" | "membership" | "follow" | "stats"
platformpublic"youtube" | "twitch" | "twitcasting" | "kick" | "nicolive" | "whowatch"
idpublicStable per-platform id.
timestamppublicEpoch milliseconds.
namepublicDisplay name of the author.
messagepublicComment text.
isMember / isModerator / isOwnerpublicAuthor role flags.
anonymouspublicTrue for anonymous posters (Niconico 184 / Whowatch).
tierpublicGift color tier.
gift.displayText / gift.tier / gift.itemNamepublicGift display info.
gift.amount / gift.currency / gift.jpyEstimaterichNumeric gift amounts (require viewer consent).
membershipEvent / monthspublic / richMembership event type / duration.
userIdrichPrefixed viewer id.
avatarUrlrichAuthor avatar URL.
memberMonthsrichMembership months.
statspublicViewer / like counters for stats events.

castdeck-sdk.d.ts — TypeScript type definitions (exact API & event types)