SDKリファレンス

SDKの読み込み

実行時(OBS)は起動中アプリから、開発・参照用はこのサイトから読み込めます。

<!-- 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.

イベントデータ(ProjectedEvent)

public は既定。rich(金額・アバター等)は配信者の同意が必要で、同意が無い場合は自動的に 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)