SDK สำหรับเทมเพลต
JavaScript SDK สำหรับพัฒนาเทมเพลต
ข้อควรทราบในการใช้งาน
ข้อควรระวัง
SDK นี้เป็น SDK เฉพาะสำหรับเทมเพลตของ OneComme
สามารถใช้ได้เฉพาะกับสิ่งที่ใช้งานร่วมกับ OneComme เช่น เทมเพลตหรือปลั๊กอินเท่านั้น
ไม่สามารถใช้งานในกรณีที่ไม่เกี่ยวข้องกับ OneComme หรือใช้ API ที่ไม่ได้รับอนุญาตให้ใช้เป็น public API
กรุณาตรวจสอบข้อตกลงการใช้งานอีกครั้ง
ข้อตกลงการใช้งาน (Terms of Service) ของ OneComme มีผลบังคับใช้กับแอปพลิเคชันและบริการที่เชื่อมต่อด้วยเช่นกัน
เกี่ยวกับการระบุเครดิต
เมื่อใช้งานแอปพลิเคชันหรือบริการที่เรียกใช้ HTTP API ในกรณีที่ใช้งานแบบไม่มีค่าใช้จ่าย จำเป็นต้องมีการระบุเครดิต
เมื่อเผยแพร่แอปพลิเคชัน ต้องระบุหมายเหตุเกี่ยวกับการระบุเครดิตด้วยทุกครั้ง
เกี่ยวกับการอ้างอิงจาก IP หรือโดเมนภายนอก
ด้วยเหตุผลด้านความปลอดภัย API ของ OneComme มีข้อจำกัดในการเข้าถึงจาก IP อื่นที่ไม่ใช่ local IP
หากต้องการเข้าถึง API จาก IP หรือโดเมนภายนอก จำเป็นต้องลงทะเบียนชื่อโฮสต์ที่อนุญาตให้เข้าถึงได้ที่ "การตั้งค่า > แท็บ API" (หน้าการตั้งค่า)
ข้อควรระวัง
เอกสาร API บางส่วนยังไม่สมบูรณ์
มีการแลกเปลี่ยนข้อมูลเพิ่มเติมและข้อมูลล่าสุดในช่องสำหรับนักพัฒนาโดยเฉพาะบน Discord server
สำหรับนักพัฒนา ขอเชิญเข้าร่วม Discord และแจ้งให้ทราบว่าคุณเป็นนักพัฒนา
วิธีใช้งาน
npm install @onecomme.com/onesdk -S
หรือใช้ preset/__origin/js/onesdk.js ที่อยู่ในเทมเพลตโฟลเดอร์
(สามารถดูได้ที่ http://localhost:11180/templates/preset/__origin/js/onesdk.js เช่นกัน)
ข้อควรระวัง
หากต้องการอัปโหลดขึ้นเซิร์ฟเวอร์หรือคัดลอกไปยังเทมเพลตโฟลเดอร์ กรุณาปรึกษาเราก่อน
API
ready():Promise< void >
จะ resolve Promise เมื่อการโหลดหน้าเสร็จสมบูรณ์
หากโหลดเสร็จแล้ว จะ resolve ทันที
setup(config: Partial< OneSDKConfig >): void
ทำการตั้งค่าเริ่มต้นของ SDK
จำเป็นต้องเรียกใช้ฟังก์ชันนี้เสมอ
| config | Partial< 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 // ทำให้ delay ในการดึงคอมเมนต์เป็น 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
จะได้รับ subscription ID ที่จำเป็นสำหรับการยกเลิกการสมัคร
| subscriber | Subscriber |
export type Subscriber = {
action: T // ชื่อ action ที่ระบุไว้ใน permissions
callback: (response: PublishActions[T]) => void
}
unsubscribe(subscriberId: number): void
หยุดการสมัครรับอีเวนต์โดยอ้างอิงจาก subscription 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}
คืนค่าข้อมูลสีของ super chat หรือ membership เช่น ของ YouTube โดยอิงจากคอมเมนต์
| comment | Comment |
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 // เป็นฟรีกิฟหรือไม่
}
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'
}
checkLicensed(): Promise< boolean >
คืนค่าสถานะว่ากำลังใช้งาน PRO อยู่หรือไม่
connect(): Promise< void >
เชื่อมต่อกับ OneComme API server
จำเป็นต้องเรียกใช้ฟังก์ชันนี้เสมอ
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[] >
ยกเลิกการรอคิวโดยอ้างอิงจาก participation ID
จะได้รับรายการรอคิวล่าสุดหลังจากยกเลิก
| OrderItem[] | OrderItem[] |
completeOrder(orderId: string): Promise< OrderItem[] >
ทำการรอคิวให้เสร็จสมบูรณ์โดยอ้างอิงจาก participation ID
จะได้รับรายการรอคิวล่าสุดหลังจากเสร็จสมบูรณ์
| OrderItem[] | OrderItem[] |
getSetList(): Promise< SetListAPIResponse >
【ยังเป็นการใช้งานชั่วคราว】คืนค่ารายการ Setlist เพลง
| 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 จำเป็นต้องระบุข้อมูลที่ต้องการรับให้ชัดเจน
สามารถระบุได้หลายรายการเป็น array ใน permissions ของ config
รายการที่ระบุไว้ใน permissions จะสามารถรับเป็น event type ผ่าน subscribe ได้
| connected | เมื่อเชื่อมต่อสำเร็จ |
| comments | เมื่อได้รับคอมเมนต์ปกติ |
| systemComment | เมื่อได้รับ system comment |
| clear | เมื่อทำการลบแชททั้งหมด |
| deleted | เมื่อคอมเมนต์ถูกลบ |
| meta | เมื่อข้อมูลการสตรีมได้รับการอัปเดต |
| meta.clear | เมื่อข้อมูลการสตรีมถูกล้างข้อมูล |
| notification | เมื่อได้รับการแจ้งเตือน |
| pinned | เมื่อการปักหมุดคอมเมนต์มีการเปลี่ยนแปลง |
| waitingList | เมื่อรายการรอคิวมีการเปลี่ยนแปลง |
| setList | เมื่อ Setlist เพลงมีการเปลี่ยนแปลง |
| setList.request | เมื่อคำขอเพลงมีการเปลี่ยนแปลง |