This is documentation for the upcoming version (9.2), which is still in development. Content may change before release.

See the same page for the current release.

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.

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

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

subscriberIdnumber

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.

namestring
defaultValueT
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.

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

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

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

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.

TypeWhen it is deliveredData passed to the callback
connectedWhen the connection is established successfully{ config?: Config; services?: Service[]; comments?: Comment[]; waitingList?: OrderItem[]; setList?: SetListAPIResponse }
commentsWhen a regular comment is receivedComment[]
systemCommentWhen a system comment is received
The source platform can be determined with data.fromService (9.2+)
SystemComment
clearWhen Clear comments is executedAn empty array []
deletedWhen 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"
metaWhen Streaming information is updated{ type: ServiceType; service: Service; data: ServiceMeta }
meta.clearWhen Streaming information is clearedstring (the ID of the stream that was cleared)
meta.clear.allWhen Streaming information for all streams is clearednull
configWhen OneComme settings are updatedConfig
servicesWhen the list of streams changesService[]
userDatasWhen viewer (user) information is updatedUserStoreData
notificationWhen a notification is received{ type: string; message: string }
pinnedWhen a comment pin changesComment (null when the pin is removed)
bookmarkedWhen a bookmark changes{ key: string; commentId: string | null }
waitingListWhen the participation waiting list changesOrderItem[]
setListWhen the Setlist changesSetListAPIResponse
setList.requestWhen requests changeRequestItem[]
reactionsWhen 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 }
eventsWhen 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.updateWhen WordParty settings are updated{ dir: string }
wp.execWhen a WordParty on-screen effect is executedWordPartyExecParams
yt.survey.start / yt.survey.update / yt.survey.finishWhen a YouTube poll starts, updates, or finishesYouTube.SurveyData
ni.survey.start / ni.survey.finishWhen a NicoNicoLive Poll starts or finishes{ state, meta }
vts.positionWhen a tracking position is received from VTube Studio integrationVTSPositionParams
toastWhen an in-app notification (toast) is displayed
Note: This is for streaming to Remote View and cannot be received by regular templates
CommentNotification
deck.layoutsWhen 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]),
})
PresetIncluded
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+)