@floating-live/bilibili 0.15.2 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugin.d.ts CHANGED
@@ -1,29 +1,26 @@
1
- import type { FloatingLive } from "floating-live";
2
- interface BilibiliLoginInfo {
3
- credentials: string;
4
- tokens: {
5
- /** 用户uid */
6
- userId: number;
7
- /** buvid */
8
- buvid: string;
9
- };
10
- userId: number;
11
- }
12
- declare module "floating-live" {
13
- interface FloatingCommandMap {
14
- "bilibili.credentials.check": (credentials: string) => Promise<BilibiliLoginInfo>;
15
- "bilibili.login.qrcode.get": () => Promise<{
16
- key: string;
17
- url: string;
18
- }>;
19
- "bilibili.login.qrcode.poll": (key: string) => Promise<{
20
- status: number;
21
- credentials?: string;
22
- }>;
23
- }
24
- }
25
- export declare class PluginBilibili {
26
- static pluginName: string;
27
- constructor(main: FloatingLive);
28
- }
29
- export default PluginBilibili;
1
+ import { BasePlugin, PluginContext } from "floating-live";
2
+ interface BilibiliLoginInfo {
3
+ credentials: string;
4
+ userId: number;
5
+ }
6
+ declare module "floating-live" {
7
+ interface AppCommandMap {
8
+ "bilibili.credentials.check": (credentials: string) => Promise<BilibiliLoginInfo>;
9
+ "bilibili.login.qrcode.get": () => Promise<{
10
+ key: string;
11
+ url: string;
12
+ }>;
13
+ "bilibili.login.qrcode.poll": (key: string) => Promise<{
14
+ status: number;
15
+ credentials?: string;
16
+ }>;
17
+ }
18
+ }
19
+ export interface PluginOptions {
20
+ userAgent: string;
21
+ }
22
+ export declare class PluginBilibili extends BasePlugin {
23
+ static pluginName: string;
24
+ init(ctx: PluginContext): void;
25
+ }
26
+ export default PluginBilibili;
package/plugin.js CHANGED
@@ -1,67 +1,63 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginBilibili = void 0;
4
- const room_1 = require("./room");
5
- const utils_1 = require("./utils");
6
- const parser_1 = require("./parser");
7
- const platformInfo = {
8
- name: "bilibili",
9
- membership: {
10
- id: "guard",
11
- name: "大航海",
12
- level: ["", "总督", "提督", "舰长"],
13
- },
14
- gift: {
15
- action: "投喂",
16
- },
17
- currency: {
18
- silver: {
19
- name: "银瓜子",
20
- ratio: 1,
21
- },
22
- gold: {
23
- name: "电池",
24
- ratio: 100,
25
- money: 1000,
26
- },
27
- },
28
- stats: {
29
- view: "看过",
30
- online: "在线",
31
- like: "点赞",
32
- },
33
- };
34
- class PluginBilibili {
35
- constructor(main) {
36
- main.command.register("bilibili.room.create", (id, options) => {
37
- return new room_1.RoomBilibili(Number(id), options);
38
- });
39
- main.command.register("bilibili.room.info", async (id) => {
40
- const rawInfo = await (0, utils_1.getInfoByRoom)(parseInt("" + id));
41
- return (0, parser_1.parseInfo)(rawInfo);
42
- });
43
- main.command.register("bilibili.credentials.check", async (credentials) => {
44
- const buvid = (await (0, utils_1.getBuvid)(credentials)) || "";
45
- const userId = await (0, utils_1.getLoginUid)(credentials);
46
- return {
47
- credentials,
48
- tokens: {
49
- userId,
50
- buvid,
51
- },
52
- userId,
53
- };
54
- });
55
- main.manifest.register("platform", "bilibili", platformInfo);
56
- main.command.register("bilibili.login.qrcode.get", () => {
57
- return (0, utils_1.generateLoginQRcode)();
58
- });
59
- main.command.register("bilibili.login.qrcode.poll", async (key) => {
60
- const [status, credentials] = await (0, utils_1.checkLoginQRcode)(key);
61
- return { status, credentials };
62
- });
63
- }
64
- }
65
- exports.PluginBilibili = PluginBilibili;
66
- PluginBilibili.pluginName = "bilibili";
67
- exports.default = PluginBilibili;
1
+ import { BasePlugin, } from "floating-live";
2
+ import { RoomBilibili } from "./room";
3
+ import { checkLoginQRcode, qrcodeGenerate } from "./utils";
4
+ import { requestGetInfoByRoom, getLoginUid, Cookies, } from "bilibili-live-danmaku";
5
+ import { parseGetInfoByRoom } from "./parser";
6
+ const platformInfo = {
7
+ name: "bilibili",
8
+ membership: {
9
+ id: "guard",
10
+ name: "大航海",
11
+ level: ["", "总督", "提督", "舰长"],
12
+ },
13
+ gift: {
14
+ action: "投喂",
15
+ },
16
+ currency: {
17
+ silver: {
18
+ name: "银瓜子",
19
+ ratio: 1,
20
+ },
21
+ gold: {
22
+ name: "电池",
23
+ ratio: 100,
24
+ money: 1000,
25
+ },
26
+ },
27
+ stats: {
28
+ view: "看过",
29
+ online: "在线",
30
+ like: "点赞",
31
+ },
32
+ };
33
+ export class PluginBilibili extends BasePlugin {
34
+ init(ctx) {
35
+ ctx.whenRegister("platform", (platform) => {
36
+ platform.register("bilibili", platformInfo, ctx.signal);
37
+ });
38
+ ctx.registerCommand("bilibili.room.create", (e, id, options) => {
39
+ return new RoomBilibili(Number(id), options);
40
+ });
41
+ ctx.registerCommand("bilibili.room.data", async (e, id) => {
42
+ const rawInfo = await requestGetInfoByRoom(parseInt("" + id));
43
+ return parseGetInfoByRoom(rawInfo);
44
+ });
45
+ ctx.registerCommand("bilibili.credentials.check", async (e, credentials) => {
46
+ const buvid = new Cookies(credentials).get("buvid3");
47
+ const userId = await getLoginUid({ cookie: credentials });
48
+ return {
49
+ credentials,
50
+ userId,
51
+ };
52
+ });
53
+ ctx.registerCommand("bilibili.login.qrcode.get", () => {
54
+ return qrcodeGenerate();
55
+ });
56
+ ctx.registerCommand("bilibili.login.qrcode.poll", async (e, key) => {
57
+ const [status, credentials] = await checkLoginQRcode(key);
58
+ return { status, credentials };
59
+ });
60
+ }
61
+ }
62
+ PluginBilibili.pluginName = "bilibili";
63
+ export default PluginBilibili;
package/room.d.ts CHANGED
@@ -1,74 +1,108 @@
1
- import { BilibiliRoomInfo, ConnectTokens } from "./types";
2
- import { LiveRoom } from "floating-live";
3
- import { UserInfo, RoomStatsInfo, RoomDetail } from "floating-live";
4
- import { KeepLiveWS } from "bilibili-live-ws";
5
- /** 配置项 */
6
- export interface RoomOptions {
7
- /** 生成房间后是否打开 */
8
- open?: boolean;
9
- /** 登录凭据 */
10
- credentials?: string;
11
- /** 连接凭证 */
12
- tokens?: ConnectTokens;
13
- /** 房间信息 */
14
- info?: BilibiliRoomInfo;
15
- /** 断线重连间隔(默认值为100ms) */
16
- connectInterval?: number;
17
- }
18
- export declare class RoomBilibili extends LiveRoom implements BilibiliRoomInfo {
19
- /** 平台id */
20
- readonly platform: string;
21
- /** 直播间号 */
22
- readonly id: number;
23
- /** 直播间room_id */
24
- roomId: number;
25
- /** 直播间短房号 */
26
- shortId: number;
27
- /** 房间信息 */
28
- detail: RoomDetail;
29
- stats: RoomStatsInfo;
30
- /** 房间是否可用 */
31
- available: boolean;
32
- /** 是否连接上房间 */
33
- connected: boolean;
34
- /** 主播信息 */
35
- anchor: UserInfo;
36
- /** 直播间弹幕api模块 */
37
- client: KeepLiveWS | null;
38
- /** 断线重连间隔 */
39
- connectInterval: number;
40
- /** 连接凭证 */
41
- private tokens;
42
- /** 是否处于正在打开的状态 */
43
- private opening;
44
- /** 是否处于重连状态 */
45
- private reconnecting;
46
- constructor(
47
- /** 房间id */
48
- id: number, options?: RoomOptions);
49
- /** 初始化 */
50
- protected init(options?: RoomOptions): Promise<void>;
51
- /** 获取房间信息 */
52
- getInfo(): Promise<void>;
53
- /** 请求房间信息 */
54
- fetchInfo(): Promise<BilibiliRoomInfo>;
55
- /** 更新直播间信息 */
56
- updateInfo({ roomId, shortId, status, timestamp, detail, stats, anchor, liveId, available, }: BilibiliRoomInfo): void;
57
- /** 开启直播间监听 */
58
- open(): Promise<void>;
59
- private openWS;
60
- /** 设置登录凭据 */
61
- setCredentials(credentials: string, userToken?: ConnectTokens): Promise<void>;
62
- /** 请求连接tokens */
63
- fetchTokens(credentials?: string, userToken?: ConnectTokens): Promise<ConnectTokens>;
64
- /** 设置直播连接tokens */
65
- setTokens(tokens: ConnectTokens): void;
66
- /** 重连 */
67
- reconnect(): void;
68
- private emitConnention;
69
- /** 创建直播弹幕客户端 */
70
- private initClient;
71
- /** 关闭直播间监听 */
72
- close(): void;
73
- }
74
- export default RoomBilibili;
1
+ import { BilibiliRoomData, ConnectTokens } from "./types";
2
+ import { LiveWS, ResponseData } from "bilibili-live-danmaku";
3
+ import { FetchOptions } from "./utils";
4
+ import { UserInfo, LiveRoomStatsInfo, LiveRoomDetailInfo, LiveRoom } from "floating-live";
5
+ /** 配置项 */
6
+ export interface RoomOptions {
7
+ /** 是否自动初始化(默认为true) */
8
+ init?: boolean;
9
+ /** 生成房间后是否立即打开 */
10
+ open?: boolean;
11
+ /** 自动重连(默认为false) */
12
+ autoReconnect?: boolean;
13
+ /** 登录凭据,若为空,则初始化时自动生成 */
14
+ credentials?: string;
15
+ /** 连接凭证,若为空,则初始化时自动生成 */
16
+ tokens?: ConnectTokens;
17
+ /** 预设置的房间数据,若设置,将不会自动更新直播间数据 */
18
+ data?: BilibiliRoomData;
19
+ /** 断线重连间隔(默认值为500ms) */
20
+ connectInterval?: number;
21
+ /** 连接超时阈值(默认值为45000ms) */
22
+ connectTimeout?: number;
23
+ /** 自定义fetchData */
24
+ customFetchData?: (id: number | string) => Promise<BilibiliRoomData>;
25
+ /** 自定义fetchTokens */
26
+ customFetchTokens?: (roomId: number) => Promise<ConnectTokens>;
27
+ /** 自定义fetch函数 */
28
+ fetch?: (input: string | URL, init?: RequestInit) => Promise<Response>;
29
+ }
30
+ declare const symbolAbortController: unique symbol;
31
+ interface ClientWithAbortController extends LiveWS {
32
+ [symbolAbortController]: AbortController;
33
+ }
34
+ export declare class RoomBilibili extends LiveRoom implements BilibiliRoomData {
35
+ #private;
36
+ /** 平台id */
37
+ readonly platform: string;
38
+ /** 直播间号 */
39
+ readonly id: number;
40
+ /** 直播间room_id */
41
+ roomId: number;
42
+ /** 直播间短房号 */
43
+ shortId: number;
44
+ /** 房间信息 */
45
+ detail: LiveRoomDetailInfo;
46
+ stats: LiveRoomStatsInfo;
47
+ /** 是否连接上房间 */
48
+ connected: boolean;
49
+ /** 主播信息 */
50
+ anchor: UserInfo;
51
+ /** 直播间弹幕api客户端 */
52
+ client: ClientWithAbortController | null;
53
+ /** 断线重连间隔 */
54
+ connectInterval: number;
55
+ /** 连接超时阈值 */
56
+ connectTimeout: number;
57
+ /** 自动重连 */
58
+ autoReconnect: boolean;
59
+ /** 是否初始化 */
60
+ whenInit: Promise<RoomBilibili>;
61
+ /** 用户代理 */
62
+ userAgent?: string;
63
+ /** 是否处于重连状态 */
64
+ private reconnecting;
65
+ /** 最后一次连接时间 */
66
+ private lastConnectionTime;
67
+ /** 自定义fetchData */
68
+ customFetchData?: (id: number | string) => BilibiliRoomData;
69
+ /** 自定义fetchTokens */
70
+ customFetchTokens?: (roomId: number, credentials: string) => Promise<ConnectTokens>;
71
+ /** 自定义fetch函数 */
72
+ fetch: (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>;
73
+ constructor(
74
+ /** 房间id */
75
+ id: number, options?: RoomOptions);
76
+ /** 初始化
77
+ * 自动获取并设置 `credentials` ,自动获取房间信息和连接 `token`
78
+ */
79
+ protected init(options?: RoomOptions): Promise<void>;
80
+ /** 更新房间信息 */
81
+ update(): Promise<BilibiliRoomData>;
82
+ /** 获取房间信息 */
83
+ fetchData(): Promise<BilibiliRoomData>;
84
+ /** 设置直播间数据 */
85
+ setData({ roomId, shortId, status, timestamp, detail, stats, anchor, liveId, openStatus, available, }: BilibiliRoomData): import("floating-live").LiveRoomData;
86
+ /** 开启直播间监听 */
87
+ open(): Promise<void>;
88
+ /** 设置登录凭据 */
89
+ setCredentials(credentials: string, updateTokens?: boolean): Promise<void>;
90
+ /** 更新连接tokens */
91
+ updateTokens(): Promise<void>;
92
+ /** 请求连接tokens */
93
+ fetchTokens(credentials?: string): Promise<ConnectTokens>;
94
+ /** 设置直播连接tokens */
95
+ setTokens(tokens: ConnectTokens): void;
96
+ /** 无缝重连 */
97
+ reconnect(): void;
98
+ private emitConnention;
99
+ /** 打开直播弹幕客户端 */
100
+ private openWebsocketClient;
101
+ /** 创建直播弹幕客户端 */
102
+ private initClient;
103
+ /** 关闭直播间监听 */
104
+ close(): void;
105
+ }
106
+ export default RoomBilibili;
107
+ /** 获取房间信息 */
108
+ export declare function requestGetInfoByRoom(id: number, options?: FetchOptions): Promise<ResponseData.GetInfoByRoom>;