bilibili-live-manager
Version:
BiliBili 直播管理器
47 lines (38 loc) • 869 B
JavaScript
;
import axios from 'axios';
import { stringify } from 'qs';
class BiliBiliLiveManager {
constructor(roomId, config) {
this.callback = () => {};
if (roomId, config) {
this.roomId = roomId ?? null;
this.config = config ?? null;
} else {
throw new Error('未設定重要參數');
}
}
open() {
this.request('startLive');
}
stop() {
this.request('stopLive');
}
async request(action) {
const result = await new axios(`https://api.live.bilibili.com/room/v1/Room/${action}`, {
method: 'post',
headers: { cookie: this.config.COOKIE },
data: stringify({
room_id: this.roomId,
platform: 'pc',
area_v2: 216,
csrf_token: this.config.CSRF,
csrf: this.config.CSRF
})
});
this.callback(result);
}
addListener(callback) {
this.callback = callback;
}
}
export default BiliBiliLiveManager;