這是開發中的下一個版本(9.2)的文件,正式發布前內容可能會變更。

目前正式版的同一頁面,敬請參考。

模板用 SDK

模板開發用的 JavaScript SDK

使用注意事項

注意

本 SDK 為 OneComme 模板專用的 SDK
僅限用於模板、擴充功能等 OneComme 使用的項目
不得用於與 OneComme 無關的用途,也不得使用未獲許可作為公開 API 的 API

請再次確認使用條款

串接的應用程式與服務同樣適用 OneComme 的使用條款

關於著作權標示

使用 HTTP API 的應用程式與服務,若為免費使用,同樣需要標示著作權

散布應用程式時,請務必附上與著作權標示相關的說明

關於從外部 IP 或網域存取

基於安全考量,OneComme 的 API 限制僅能從本機 IP 存取

若要從外部 IP 或網域存取 API,需在「設定 > API 分頁」(設定頁面)登記允許存取的主機名稱

注意

API 文件有部分內容尚不完整
新增內容與最新資訊會在 Discord 伺服器的開發者專用頻道中交流
開發者請務必加入 Discord,並告知自己是開發者

使用方式

npm install @onecomme.com/onesdk -S

或使用模板資料夾中的 preset/__origin/js/onesdk.js
(也可透過 http://localhost:11180/templates/preset/__origin/js/onesdk.js 取得)

注意

將 SDK 複製、內附或散布於 OneComme 用的作品中,無論有償或無償,皆無需另行洽詢。請保留 SDK 的授權與著作權標示。詳情請參閱使用條款。

API

ready():Promise< void >

頁面載入完成時 resolve Promise
若已載入完成,則立即 resolve

setup(config: Partial< OneSDKConfig >): void

進行 SDK 的初始設定
必須呼叫此函式

configPartial< OneSDKConfig >
export type Protocol = 'ws' | 'local'  
export interface OneSDKConfig {  
  protocol: Protocol // 連線協定(Default: 'local')  
  port: number // 通訊埠 (Default: 11180)  
  host: string // 主機名稱(Default: 'localhost')  
  pathname: string // API pathname (Default: '')  
  mode: 'all' | 'diff' // 留言取得模式 (Default: 'all') all=每次取得目前已取得的所有留言(已刪除者除外) diff=僅取得最新留言  
  disabledDelay: boolean // 將留言取得延遲設為 0 (Default: false)  
  intervalTime: number // 留言更新間隔 (Default: 5000)  
  maxQueueInterval: number // 連續出現留言時的間隔 (Default: 150)  
  reconnectInterval: number // 中斷連線後的重新連接間隔 (Default: 5000)  
  commentLimit: number // SDK 上保留的最大留言數 (Default: 100)  
  includes: string[] | null // 要取得的直播網站 (Default: null)  
  excludes: string[] | null // 要排除的直播網站 (Default: null)  
  includeIds: string[] | null // 要接收的使用者身分 (Default: null)  
  excludeIds: string[] | null // 要排除的使用者身分 (Default: null)  
  includeNames: string[] | null // 要取得的直播間名稱 (Default: null)  
  excludeNames: string[] | null // 要取得的直播間名稱 (Default: null)  
  lifeTime: number // 留言保留時間 (Default: Infinity)  
  permissions: SendType[] | null // API Permission  
}

subscribe(subscriber: Subscriber): number

訂閱 OneComme 發生變更時的事件
會回傳解除訂閱所需的訂閱 ID

subscriberSubscriber
export type Subscriber = {  
  action: T // permissions 中指定的動作名稱  
  callback: (response: PublishActions[T]) => void  
}

unsubscribe(subscriberId: number): void

依據訂閱 ID 停止訂閱事件

subscriberIdnumber

reset():void

重設已取得的留言等資料

getStyleVariable< T = any >(name: string, defaultValue: T, parser: (val:string) => T): T

取得 CSS 的 :root 中所定義 CSS 變數值的函式

namestring
defaultValueT
parser(val: string) ⇒ T

getCommentStyle(comment: Comment): {[key: string]: string}

依據留言,回傳 YouTube 等的 Super Chat 與會員資格的顏色資訊

commentComment
export interface Comment {  
  id: string  
  service: ServiceType // 接收到的直播網站識別碼  
  name: string  
  url: string  
  color: RGBColor // 直播間設定的顏色資訊{r,g,b}  
  meta?: BaseCommentMeta  
  data: CommentData  
}  
export interface BaseCommentMeta {  
  no?: number // 留言編號  
  tc?: number // 累計留言數  
  lc?: number // 留言數  
  interval?: number // 留言間隔  
  free?: boolean // 是否為贈品  
  isUpdate?: boolean // 是否為相同 data.id 的留言第二次以後送達(顯示更新)(9.2 起)  
  isStreak?: boolean // 是否為連發(連擊)第二則以後的送達(9.2 起)  
}  
export interface CommentData {  
  id: string  
  userId: string  
  liveId: string  
  name: string  
  screenName?: string  
  isOwner: boolean  
  isSupporter?: boolean  
  displayName?: string  
  nickname?: string  
  hasGift: boolean  
  autoModerated?: boolean  
  profileImage: string  
  originalProfileImage?: string  
  badges: BaseBadge[]  
  timestamp: string  
  comment: string  
  speechText?: string  
  isFirstTime?: boolean  
  isRepeater?: boolean  
  commentVisible?: boolean  
  meta?: CommentMeta  
}  
export interface BaseBadge {  
  url: string  
  label: string  
  type?: string  
}  
export interface CommentMeta {  
  hasNickname?: boolean  
  hasMemo?: boolean  
  anonymity?: boolean  
  label?: string  
  type?: 'system'  
}

各直播網站放入 data 的項目,請參閱 SDK 參考文件中各網站的 CommentResponse
9.2 新增了 Mirrativ、MIXCHANNEL、bilibili 的禮物數量(giftCount)、Kick 的禮物數量(price),以及 Twitch 的訂閱資訊(giftCount・subType・tier・plan,以及單次訂閱禮品的接收者 giftReceivers)

checkLicensed(): Promise< boolean >

回傳是否正在使用 PRO 版的旗標

connect(): Promise< void >

連接至 OneComme API 伺服器
必須呼叫此函式

getInfo(): Promise< AppInfo >

回傳 OneComme 應用程式的基本資訊

AppInfoAppInfo
export interface AppInfo {  
  platform: 'win' | 'mac'  
  version: string  
  port: number  
  licensed: boolean  
  templatePath: string  
  templateUrl: string  
}

getOrders(): Promise< OrderItem[] >

回傳觀眾參加型活動的排隊等候資訊清單

OrderItem[]OrderItem[]
export interface OrderItem {  
  id: string // userid  
  commentId: string  
  service: ServiceType  
  serviceName: string  
  username: string  
  profileImage: string  
  timestamp: string  
  comment: string  
  count: number  
  completed: boolean  
  playing: boolean  
  anonymity: boolean  
  userData?: UserNameData  
  totalCount?: number  
  lastCompletedAt?: string  
}

cancelOrder(orderId: string): Promise< OrderItem[] >

依據參加 ID 取消排隊等候

取消後會回傳最新的排隊等候清單

OrderItem[]OrderItem[]

completeOrder(orderId: string): Promise< OrderItem[] >

依據參加 ID 完成排隊等候

完成後會回傳最新的排隊等候清單

OrderItem[]OrderItem[]

getSetList(): Promise< SetListAPIResponse >

[暫定實作] 回傳歌單曲目清單

SetListAPIResponseSetListAPIResponse
export interface SetListAPIResponse {  
  id: number  
  name: string  
  items: MusicData[]  
  completed: MusicData[]  
}  
export interface MusicData {  
  id: number  
  box: number  
  name: string  
  link: string  
  tags: string[]  
  memo: string  
}

Permission

若要從 SDK 接收各種資料,必須明確指定要接收的資料

可在 config 的 permissions 中以陣列指定多個項目

permissions 中指定的項目,即可在 subscribe 中作為事件類型接收

類型何時收到傳給 callback 的資料
connected連接成功時{ config?: Config; services?: Service[]; comments?: Comment[]; waitingList?: OrderItem[]; setList?: SetListAPIResponse }
comments接收到一般留言時Comment[]
systemComment接收到系統留言時
來源直播網站可透過 data.fromService 判斷(9.2 起)
SystemComment
clear執行清除留言時空陣列 []
deleted留言被刪除時{ id: string; message: string }[]
id 是被刪除留言的 id(comment.data.id),message 是「已刪除」等顯示用的文字
meta直播情報更新時{ type: ServiceType; service: Service; data: ServiceMeta }
meta.clear直播情報被清除時string(被清除的直播間 ID)
meta.clear.all所有直播間的直播情報被清除時null
configOneComme 的設定更新時Config
services直播間清單變動時Service[]
userDatas觀眾(使用者)資訊更新時UserStoreData
notification接收到通知時{ type: string; message: string }
pinned留言的釘選狀態變動時Comment(取消釘選時為 null)
bookmarked書籤變動時{ key: string; commentId: string | null }
waitingList等候參加清單變動時OrderItem[]
setList歌單曲目變動時SetListAPIResponse
setList.request點歌請求變動時RequestItem[]
reactions接收到 YouTube 的反應或 NicoNico直播的情緒時
effect 表示 OneComme 本體是否設定為顯示特效
{ reactions: Reaction[]; effect: boolean }
events接收到不會以留言形式顯示的平台事件(Twitch 的突襲、訂閱、觀眾里程碑,NicoNico直播的來場、巡航等)時(9.2 起)
不受應用程式的通知設定影響,一律會送達
EventPayload
wp.updateWordParty 的設定更新時{ dir: string }
wp.execWordParty 的特效執行時WordPartyExecParams
yt.survey.start / yt.survey.update / yt.survey.finishYouTube 的問卷調查開始、更新、結束時YouTube.SurveyData
ni.survey.start / ni.survey.finishNicoNico直播的問卷調查開始、結束時{ state, meta }
vts.position接收到 VTube Studio 串接的追蹤位置時VTSPositionParams
toast顯示應用程式內通知(Toast)時
※ 此為遠端觀看用的傳送內容,一般模板無法接收
CommentNotification
deck.layouts遠端控制台的佈局變動時(9.2 起)
※ 此為遠端觀看用的傳送內容,一般模板無法接收
DeckLayout[]

deleted / clear 可在 SDK 9.2.0 以上版本接收
請使用 id 來辨識被刪除的留言
message 是顯示用的文字,內容並非固定

各事件可接收的資料型別請參閱 PublishActions,可指定的值清單請參閱 SendType

events 可接收的資料(EventPayload)如下

export interface EventPayload {
  id: string
  timestamp: string
  service: Pick<Service, 'id' | 'name' | 'url' | 'color'>
  serviceType: ServiceType
  event: CommentEvent // 突襲或訂閱等事件的內容
  message: string // 顯示為通知的文字
  user?: { userId: string; name: string; screenName?: string }
}

權限預設

將 OneSDK.PERM 的預設名稱傳給 OneSDK.usePermission(),即可一次指定多個權限

OneSDK.setup({
  permissions: OneSDK.usePermission([OneSDK.PERM.COMMENT, OneSDK.PERM.EVENT]),
})
預設包含的項目
DEFAULTcomments・deleted・clear・pinned・bookmarked・meta・meta.clear
COMMENTcomments・deleted・clear・pinned・bookmarked
METAmeta・meta.clear
ORDERwaitingList
REACTIONreactions
SETLISTsetList・setList.request
WORDPARTYwp.update・wp.exec
YT_SURVEYyt.survey.start・yt.survey.update・yt.survey.finish
NI_SURVEYni.survey.start・ni.survey.finish
CONFIGconfig
SERVICEservices
USERuserDatas
NOTIFICATIONnotification
EVENTevents(9.2 起)