템플릿용 SDK
템플릿 개발용 JavaScript SDK
이용 시 주의사항
주의
이 SDK는 OneComme 템플릿 전용 SDK입니다
템플릿, 플러그인 등 OneComme에서 사용하는 용도로만 이용할 수 있습니다
OneComme와 관련 없는 용도로 사용하거나, 공개 API로 사용이 허가된 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에서도 확인할 수 있습니다)
주의
OneComme용 제작물에 SDK를 복제·동봉·배포하는 경우, 유상·무상을 불문하고 별도 문의는 필요하지 않습니다. SDK의 라이선스·저작권 표기는 유지하세요. 자세한 내용은 이용약관을 확인하세요.
API
ready():Promise< void >
페이지 불러오기가 완료되면 Promise를 resolve합니다
이미 완료된 경우에는 즉시 resolve합니다
setup(config: Partial< OneSDKConfig >): void
SDK의 초기 설정을 수행합니다
이 함수의 호출은 필수입니다
| config | Partial< OneSDKConfig > |
export type Protocol = 'ws' | 'local'
export interface OneSDKConfig {
protocol: Protocol // Connection protocol (Default: 'local')
port: number // Port number (Default: 11180)
host: string // Host name (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 // Frame names to retrieve (Default: null)
excludeNames: string[] | null // Frame names to retrieve (Default: null)
lifeTime: number // Comment retention time (Default: Infinity)
permissions: SendType[] | null // API Permission
}
subscribe(subscriber: Subscriber): number
OneComme에서 변경이 있을 때의 이벤트를 구독합니다
구독 해제에 필요한 구독 ID가 반환됩니다
| subscriber | Subscriber |
export type Subscriber = {
action: T // Action name specified in permissions
callback: (response: PublishActions[T]) => void
}
unsubscribe(subscriberId: number): void
구독 ID를 기준으로 이벤트 구독을 중지합니다
| subscriberId | number |
reset():void
가져온 채팅 등의 데이터를 초기화합니다
getStyleVariable< T = any >(name: string, defaultValue: T, parser: (val:string) => T): T
CSS의 :root에 정의된 CSS 변수의 값을 가져오는 함수입니다
| name | string |
| defaultValue | T |
| parser | (val: string) ⇒ T |
getCommentStyle(comment: Comment): {[key: string]: string}
YouTube 등의 슈퍼챗이나 멤버십의 색상 정보를 채팅을 기준으로 반환합니다
| comment | Comment |
export interface Comment {
id: string
service: ServiceType // Identifier of the received streaming platform
name: string
url: string
color: RGBColor // Color info set for the frame {r,g,b}
meta?: BaseCommentMeta
data: CommentData
}
export interface BaseCommentMeta {
no?: number // Comment number
tc?: number // Total comment count
lc?: number // Comment count
interval?: number // Comment interval
free?: boolean // Whether it is a free gift
isUpdate?: boolean // Whether a comment with the same data.id arrived for the second time or later (display update) (9.2+)
isStreak?: boolean // Whether it is the second or later delivery of a consecutive (combo) post (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 앱의 기본 정보를 반환합니다
| AppInfo | AppInfo |
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 >
[임시 구현] 세트리스트 목록을 반환합니다
| 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
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 |
| config | OneComme 설정이 업데이트되었을 때 | 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의 리액션이나 NicoNicoLive의 이모티콘을 수신했을 때 effect는 OneComme 본체에서 연출을 표시하도록 설정되어 있는지 여부입니다 | { reactions: Reaction[]; effect: boolean } |
| events | 채팅으로 흐르지 않는 플랫폼 이벤트(Twitch의 레이드·구독·시청자 마일스톤, NicoNicoLive의 방문·크루즈 등)를 수신했을 때(9.2~) 앱의 알림 설정과 관계없이 수신됩니다 | EventPayload |
| wp.update | WordParty 설정이 업데이트되었을 때 | { dir: string } |
| wp.exec | WordParty 연출이 실행되었을 때 | WordPartyExecParams |
| yt.survey.start / yt.survey.update / yt.survey.finish | YouTube 투표가 시작·업데이트·종료되었을 때 | YouTube.SurveyData |
| ni.survey.start / ni.survey.finish | NicoNicoLive 투표가 시작·종료되었을 때 | { state, meta } |
| vts.position | VTube Studio 연동의 트래킹 위치를 수신했을 때 | VTSPositionParams |
| 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 // Event details such as raids or subscriptions
message: string // Text displayed as a notification
user?: { userId: string; name: string; screenName?: string }
}
권한 프리셋
OneSDK.usePermission()에 OneSDK.PERM의 프리셋 이름을 전달하면 한 번에 지정할 수 있습니다
OneSDK.setup({
permissions: OneSDK.usePermission([OneSDK.PERM.COMMENT, OneSDK.PERM.EVENT]),
})
| 프리셋 | 포함 항목 |
|---|---|
| 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~) |