SDK for templates
JavaScript SDK for template development
Usage notes
Caution
This SDK is dedicated to OneComme templates.
It may be used only for things used with OneComme, such as templates and plugins.
Use unrelated to OneComme, or use of any API other than those permitted as public APIs, is not allowed.
Review the terms of use again
The OneComme terms of use also apply to integrated applications and services.
About credits
Credit notation is required for free use, including when using applications or services that use the HTTP API.
When distributing an application, be sure to include a note about the credit notation.
Access from external IPs and domains
For security reasons, access to the OneComme API is restricted to local IPs.
To access the API from an external IP or domain, you need to register the Hostname you want to allow in "Settings > API tab" (settings page).
Caution
The API documentation is partly incomplete.
Additions and the latest information are exchanged in the developer-only channel on the Discord server.
Developers are encouraged to join Discord and let us know that you are a developer.
How to use
npm install @onecomme.com/onesdk -S
Alternatively, use preset/__origin/js/onesdk.js in the Templates folder.
(It can also be accessed at http://localhost:11180/templates/preset/__origin/js/onesdk.js.)
Caution
You do not need to ask us individually before copying, bundling, or distributing the SDK with works made for OneComme, whether paid or free. Keep the SDK's license and copyright notices intact. See the terms of use for details.
API
ready():Promise< void >
Resolves the Promise when the page has finished loading.
If loading has already finished, it resolves immediately.
setup(config: Partial< OneSDKConfig >): void
Performs the initial SDK settings.
Calling this function is required.
| config | Partial< OneSDKConfig > |
export type Protocol = 'ws' | 'local'
export interface OneSDKConfig {
protocol: Protocol // Connection protocol (Default: 'local')
port: number // Port (Default: 11180)
host: string // Hostname (Default: 'localhost')
pathname: string // API pathname (Default: '')
mode: 'all' | 'diff' // Comment retrieval mode (Default: 'all') all=retrieve all recently fetched comments every time (excluding deleted ones) diff=always retrieve only the latest
disabledDelay: boolean // Set comment retrieval delay to 0 (Default: false)
intervalTime: number // Comment update interval (Default: 5000)
maxQueueInterval: number // Interval for consecutive comments (Default: 150)
reconnectInterval: number // Reconnect interval after disconnection (Default: 5000)
commentLimit: number // Maximum number of comments kept in the SDK (Default: 100)
includes: string[] | null // Streaming services to retrieve (Default: null)
excludes: string[] | null // Streaming services to exclude (Default: null)
includeIds: string[] | null // User Ids to receive (Default: null)
excludeIds: string[] | null // User Ids to exclude (Default: null)
includeNames: string[] | null // Stream names to retrieve (Default: null)
excludeNames: string[] | null // Stream names to exclude (Default: null)
lifeTime: number // Comment retention time (Default: Infinity)
permissions: SendType[] | null // API Permission
}
subscribe(subscriber: Subscriber): number
Subscribes to events for changes in OneComme.
Returns a subscription ID needed for unsubscribing.
| subscriber | Subscriber |
export type Subscriber = {
action: T // Action name specified in permissions
callback: (response: PublishActions[T]) => void
}
unsubscribe(subscriberId: number): void
Stops an event subscription based on the subscription ID.
| subscriberId | number |
reset():void
Resets retrieved data such as comments.
getStyleVariable< T = any >(name: string, defaultValue: T, parser: (val:string) => T): T
A function that retrieves the value of a CSS variable defined in the CSS :root.
| name | string |
| defaultValue | T |
| parser | (val: string) ⇒ T |
getCommentStyle(comment: Comment): {[key: string]: string}
Returns color information for Super Chats, Memberships, and similar on YouTube and other platforms, based on the comment.
| comment | Comment |
export interface Comment {
id: string
service: ServiceType // Identifier of the platform the comment was received from
name: string
url: string
color: RGBColor // Color information {r,g,b} set for the stream
meta?: BaseCommentMeta
data: CommentData
}
export interface BaseCommentMeta {
no?: number // Comment number
tc?: number // Total comment count
lc?: number // Comments Count
interval?: number // Comment interval
free?: boolean // Whether it is a Free gifts item
isUpdate?: boolean // Whether a comment with the same data.id arrived for the second time or later (display update) (9.2+)
isStreak?: boolean // Whether this is the second or later delivery of a streak (combo) (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'
}
For the fields included in data for each platform, see CommentResponse for each site in the SDK reference.
In 9.2, the gift count (giftCount) for Mirrativ, MIXCHANNEL, and bilibili, the gift amount (price) for Kick, and Twitch subscription information (giftCount, subType, tier, plan, and giftReceivers for the recipients of a single Subscription Gift) were added.
checkLicensed(): Promise< boolean >
Returns a flag indicating whether PRO is being used.
connect(): Promise< void >
Connects to the OneComme API server.
Calling this function is required.
getInfo(): Promise< AppInfo >
Returns basic information about the OneComme app.
| AppInfo | AppInfo |
export interface AppInfo {
platform: 'win' | 'mac'
version: string
port: number
licensed: boolean
templatePath: string
templateUrl: string
}
getOrders(): Promise< OrderItem[] >
Returns the waiting list for viewer participation.
| 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[] >
Cancels a waiting entry based on the participation ID.
Returns the latest waiting list after cancellation.
| OrderItem[] | OrderItem[] |
completeOrder(orderId: string): Promise< OrderItem[] >
Completes a waiting entry based on the participation ID.
Returns the latest waiting list after completion.
| OrderItem[] | OrderItem[] |
getSetList(): Promise< SetListAPIResponse >
[Provisional implementation] Returns the Setlist list.
| SetListAPIResponse | SetListAPIResponse |
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
To receive various data from the SDK, you must explicitly specify the data to receive.
You can specify multiple values as an array in the permissions of config.
Values specified in permissions can be received as event types in subscribe.
| Type | When it is delivered | Data passed to the callback |
|---|---|---|
| connected | When the connection is established successfully | { config?: Config; services?: Service[]; comments?: Comment[]; waitingList?: OrderItem[]; setList?: SetListAPIResponse } |
| comments | When a regular comment is received | Comment[] |
| systemComment | When a system comment is received The source platform can be determined with data.fromService (9.2+) | SystemComment |
| clear | When Clear comments is executed | An empty array [] |
| deleted | When a comment is deleted | { id: string; message: string }[] id is the id of the deleted comment (comment.data.id), and message is a display text such as "Deleted" |
| meta | When Streaming information is updated | { type: ServiceType; service: Service; data: ServiceMeta } |
| meta.clear | When Streaming information is cleared | string (the ID of the stream that was cleared) |
| meta.clear.all | When Streaming information for all streams is cleared | null |
| config | When OneComme settings are updated | Config |
| services | When the list of streams changes | Service[] |
| userDatas | When viewer (user) information is updated | UserStoreData |
| notification | When a notification is received | { type: string; message: string } |
| pinned | When a comment pin changes | Comment (null when the pin is removed) |
| bookmarked | When a bookmark changes | { key: string; commentId: string | null } |
| waitingList | When the participation waiting list changes | OrderItem[] |
| setList | When the Setlist changes | SetListAPIResponse |
| setList.request | When requests change | RequestItem[] |
| reactions | When a YouTube Reaction or a NicoNicoLive Emotion is received effect indicates whether OneComme itself is set to display on-screen effects | { reactions: Reaction[]; effect: boolean } |
| events | When a platform event that is not delivered as a comment is received (Twitch raids, subscriptions, and viewer milestones, NicoNicoLive visits and cruises, etc.) (9.2+) These are delivered regardless of the app's notification settings | EventPayload |
| wp.update | When WordParty settings are updated | { dir: string } |
| wp.exec | When a WordParty on-screen effect is executed | WordPartyExecParams |
| yt.survey.start / yt.survey.update / yt.survey.finish | When a YouTube poll starts, updates, or finishes | YouTube.SurveyData |
| ni.survey.start / ni.survey.finish | When a NicoNicoLive Poll starts or finishes | { state, meta } |
| vts.position | When a tracking position is received from VTube Studio integration | VTSPositionParams |
| toast | When an in-app notification (toast) is displayed Note: This is for streaming to Remote View and cannot be received by regular templates | CommentNotification |
| deck.layouts | When the remote deck Layout changes (9.2+) Note: This is for streaming to Remote View and cannot be received by regular templates | DeckLayout[] |
deleted / clear can be received with SDK 9.2.0 or later.
Use id to identify the deleted comment.message is a display text, and its content is not fixed.
For the data types received by each event, see PublishActions. For the list of values that can be specified, see SendType.
The data received by events (EventPayload) is as follows.
export interface EventPayload {
id: string
timestamp: string
service: Pick<Service, 'id' | 'name' | 'url' | 'color'>
serviceType: ServiceType
event: CommentEvent // Content of the event, such as a raid or subscription
message: string // Text displayed as a notification
user?: { userId: string; name: string; screenName?: string }
}
Permission presets
Pass OneSDK.PERM preset names to OneSDK.usePermission() to specify them together.
OneSDK.setup({
permissions: OneSDK.usePermission([OneSDK.PERM.COMMENT, OneSDK.PERM.EVENT]),
})
| Preset | Included |
|---|---|
| DEFAULT | comments・deleted・clear・pinned・bookmarked・meta・meta.clear |
| COMMENT | comments・deleted・clear・pinned・bookmarked |
| META | meta・meta.clear |
| ORDER | waitingList |
| REACTION | reactions |
| SETLIST | setList・setList.request |
| WORDPARTY | wp.update・wp.exec |
| YT_SURVEY | yt.survey.start・yt.survey.update・yt.survey.finish |
| NI_SURVEY | ni.survey.start・ni.survey.finish |
| CONFIG | config |
| SERVICE | services |
| USER | userDatas |
| NOTIFICATION | notification |
| EVENT | events (9.2+) |