floating-live 0.9.0 → 0.10.1
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/package.json +2 -2
- package/plugin/acfun/acfunLive.d.ts +19 -20
- package/plugin/acfun/acfunLive.js +20 -17
- package/plugin/bilibili/bilibiliLive.js +19 -5
- package/plugin/chatPrint/chatPrint.js +1 -1
- package/src/lib/LiveRoom.js +3 -3
- package/src/types/message/AttributeInfo.d.ts +4 -2
- package/src/types/message/MessageData.d.ts +23 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "floating-live",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"acfun-live-danmaku": "^0.6.1",
|
|
19
|
-
"axios": "^
|
|
19
|
+
"axios": "^1.2.3",
|
|
20
20
|
"bilibili-live-ws": "^6.0.3",
|
|
21
21
|
"fs-extra": "^11.1.0"
|
|
22
22
|
},
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { MedalInfo, UserInfo } from "../../src/types/message/AttributeInfo";
|
|
2
2
|
import AcClient from "acfun-live-danmaku/client";
|
|
3
3
|
import { LiveRoom, RoomBaseInfo } from "../../src/lib/LiveRoom";
|
|
4
|
+
declare type ZtLiveUserInfo = {
|
|
5
|
+
userIdentity: {
|
|
6
|
+
managerType?: number;
|
|
7
|
+
};
|
|
8
|
+
badge?: string;
|
|
9
|
+
nickname: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
avatar: [
|
|
12
|
+
{
|
|
13
|
+
url: string;
|
|
14
|
+
}
|
|
15
|
+
];
|
|
16
|
+
};
|
|
4
17
|
declare class acfunLive extends LiveRoom {
|
|
5
18
|
/** 平台id */
|
|
6
19
|
readonly platform: string;
|
|
@@ -28,41 +41,27 @@ declare class acfunLive extends LiveRoom {
|
|
|
28
41
|
close(): void;
|
|
29
42
|
destory(): void;
|
|
30
43
|
/** 根据守护徽章字符串获取粉丝牌信息 */
|
|
31
|
-
getMedal(badge
|
|
44
|
+
getMedal(badge?: string): MedalInfo | null;
|
|
45
|
+
getUser(user: ZtLiveUserInfo): UserInfo;
|
|
32
46
|
/** 文本信息(Comment) */
|
|
33
47
|
msg_Comment(data: {
|
|
34
48
|
sendTimeMs: string;
|
|
35
|
-
userInfo:
|
|
36
|
-
userIdentity: any;
|
|
37
|
-
badge: string;
|
|
38
|
-
nickname: any;
|
|
39
|
-
userId: string;
|
|
40
|
-
};
|
|
49
|
+
userInfo: ZtLiveUserInfo;
|
|
41
50
|
content: any;
|
|
42
51
|
}): void;
|
|
43
52
|
/** 礼物信息(Gift) */
|
|
44
53
|
msg_Gift(data: {
|
|
45
54
|
sendTimeMs: string;
|
|
46
|
-
user:
|
|
47
|
-
userIdentity: any;
|
|
48
|
-
badge: string;
|
|
49
|
-
nickname: any;
|
|
50
|
-
userId: string;
|
|
51
|
-
};
|
|
55
|
+
user: ZtLiveUserInfo;
|
|
52
56
|
giftName: any;
|
|
53
57
|
giftId: string;
|
|
54
|
-
count:
|
|
58
|
+
count: number;
|
|
55
59
|
value: string;
|
|
56
60
|
}): void;
|
|
57
61
|
/** 互动信息 */
|
|
58
62
|
msg_Interact(data: {
|
|
59
63
|
sendTimeMs: string;
|
|
60
|
-
userInfo:
|
|
61
|
-
userIdentity: any;
|
|
62
|
-
badge: string;
|
|
63
|
-
nickname: any;
|
|
64
|
-
userId: string;
|
|
65
|
-
};
|
|
64
|
+
userInfo: ZtLiveUserInfo;
|
|
66
65
|
}, type: "entry" | "like" | "follow" | "share" | "join"): void;
|
|
67
66
|
msg_LiveClosed(): void;
|
|
68
67
|
msg_LiveBanned(): void;
|
|
@@ -36,7 +36,6 @@ class acfunLive extends LiveRoom_1.LiveRoom {
|
|
|
36
36
|
if (open)
|
|
37
37
|
this.open();
|
|
38
38
|
});
|
|
39
|
-
console.log("连接直播间");
|
|
40
39
|
}
|
|
41
40
|
/** 直播间是否可用 */
|
|
42
41
|
get available() {
|
|
@@ -129,6 +128,22 @@ class acfunLive extends LiveRoom_1.LiveRoom {
|
|
|
129
128
|
return null;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
131
|
+
getUser(user) {
|
|
132
|
+
let identity = null;
|
|
133
|
+
if (user.userIdentity?.managerType == 1) {
|
|
134
|
+
identity = "admin";
|
|
135
|
+
}
|
|
136
|
+
else if (parseInt(user.userId) == this.anchor.id) {
|
|
137
|
+
identity = "anchor";
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
name: user.nickname,
|
|
141
|
+
id: parseInt(user.userId),
|
|
142
|
+
medal: this.getMedal(user.badge),
|
|
143
|
+
avatar: user.avatar[0].url,
|
|
144
|
+
identity: identity
|
|
145
|
+
};
|
|
146
|
+
}
|
|
132
147
|
/** 文本信息(Comment) */
|
|
133
148
|
msg_Comment(data) {
|
|
134
149
|
let danmaku = {
|
|
@@ -138,11 +153,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
|
|
|
138
153
|
type: "chat",
|
|
139
154
|
info: {
|
|
140
155
|
content: data.content,
|
|
141
|
-
user:
|
|
142
|
-
name: data.userInfo.nickname,
|
|
143
|
-
id: parseInt(data.userInfo.userId),
|
|
144
|
-
medal: this.getMedal(data.userInfo.badge),
|
|
145
|
-
},
|
|
156
|
+
user: this.getUser(data.userInfo),
|
|
146
157
|
timestamp: parseInt(data.sendTimeMs),
|
|
147
158
|
},
|
|
148
159
|
};
|
|
@@ -156,16 +167,12 @@ class acfunLive extends LiveRoom_1.LiveRoom {
|
|
|
156
167
|
type: "gift",
|
|
157
168
|
record_time: new Date().valueOf(),
|
|
158
169
|
info: {
|
|
159
|
-
user:
|
|
160
|
-
name: data.user.nickname,
|
|
161
|
-
id: parseInt(data.user.userId),
|
|
162
|
-
medal: this.getMedal(data.user.badge),
|
|
163
|
-
},
|
|
170
|
+
user: this.getUser(data.user),
|
|
164
171
|
gift: {
|
|
165
172
|
name: data.giftName,
|
|
166
173
|
id: parseInt(data.giftId),
|
|
167
174
|
num: data.count,
|
|
168
|
-
currency: "coin",
|
|
175
|
+
currency: data.giftId == "1" ? "banana" : "coin",
|
|
169
176
|
value: parseInt(data.value), // 总价值
|
|
170
177
|
},
|
|
171
178
|
timestamp: parseInt(data.sendTimeMs),
|
|
@@ -181,11 +188,7 @@ class acfunLive extends LiveRoom_1.LiveRoom {
|
|
|
181
188
|
type: type,
|
|
182
189
|
record_time: new Date().valueOf(),
|
|
183
190
|
info: {
|
|
184
|
-
user:
|
|
185
|
-
name: data.userInfo.nickname,
|
|
186
|
-
id: parseInt(data.userInfo.userId),
|
|
187
|
-
medal: this.getMedal(data.userInfo.badge),
|
|
188
|
-
},
|
|
191
|
+
user: this.getUser(data.userInfo),
|
|
189
192
|
timestamp: parseInt(data.sendTimeMs),
|
|
190
193
|
},
|
|
191
194
|
};
|
|
@@ -136,6 +136,7 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
136
136
|
let uid = msg.info[2][0];
|
|
137
137
|
let timestamp = msg.info[0][4];
|
|
138
138
|
let guard_level = msg.info[7]; // 舰长级别
|
|
139
|
+
let extra = JSON.parse(msg.info[0][15].extra);
|
|
139
140
|
let medal = (msg.info[3].length) ? {
|
|
140
141
|
level: msg.info[3][0],
|
|
141
142
|
name: msg.info[3][1],
|
|
@@ -143,12 +144,24 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
143
144
|
id: msg.info[3][12],
|
|
144
145
|
membership: msg.info[3][10] || 0,
|
|
145
146
|
} : null;
|
|
146
|
-
let
|
|
147
|
+
let identity = null;
|
|
148
|
+
let emoticon = undefined;
|
|
149
|
+
if (extra.emots) {
|
|
150
|
+
emoticon = {};
|
|
151
|
+
for (let key in extra.emots) {
|
|
152
|
+
let emotItem = extra.emots[key];
|
|
153
|
+
emoticon[key] = {
|
|
154
|
+
id: emotItem.emoticon_unique,
|
|
155
|
+
url: emotItem.url,
|
|
156
|
+
name: emotItem.emoji,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
147
160
|
if (msg.info[2][2]) {
|
|
148
|
-
|
|
161
|
+
identity = "admin";
|
|
149
162
|
}
|
|
150
163
|
else if (uid == this.anchor.id) {
|
|
151
|
-
|
|
164
|
+
identity = "anchor";
|
|
152
165
|
}
|
|
153
166
|
let danmaku = {
|
|
154
167
|
platform: "bilibili",
|
|
@@ -164,14 +177,15 @@ class bilibiliLive extends LiveRoom_1.LiveRoom {
|
|
|
164
177
|
name: content,
|
|
165
178
|
id: msg.info[0][13].emoticon_unique,
|
|
166
179
|
url: msg.info[0][13].url,
|
|
167
|
-
|
|
180
|
+
height: msg.info[0][13].height / 3,
|
|
168
181
|
} : undefined,
|
|
182
|
+
emoticon: emoticon,
|
|
169
183
|
user: {
|
|
170
184
|
name: uname,
|
|
171
185
|
id: uid,
|
|
172
186
|
medal: medal,
|
|
173
187
|
membership: guard_level,
|
|
174
|
-
|
|
188
|
+
identity: identity,
|
|
175
189
|
}
|
|
176
190
|
}
|
|
177
191
|
};
|
|
@@ -60,7 +60,7 @@ class chatPrint {
|
|
|
60
60
|
case "superchat": {
|
|
61
61
|
let user = this.getUserInfo(message);
|
|
62
62
|
let second = Math.round(message.info.duration / 1000);
|
|
63
|
-
console.log(`${"\x1b[1;36m"}SC(${second}s) ${user}${"\x1b[0m"}: ${message.info.
|
|
63
|
+
console.log(`${"\x1b[1;36m"}SC(${second}s) ${user}${"\x1b[0m"}: ${message.info.content}`);
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
66
|
case "entry": {
|
package/src/lib/LiveRoom.js
CHANGED
|
@@ -55,9 +55,9 @@ class LiveRoom extends events_1.EventEmitter {
|
|
|
55
55
|
break;
|
|
56
56
|
case "live_end":
|
|
57
57
|
case "live_cut":
|
|
58
|
-
this.status = msg.
|
|
59
|
-
this.timestamp = msg.
|
|
60
|
-
this.emit("status", msg.
|
|
58
|
+
this.status = msg.status || "off";
|
|
59
|
+
this.timestamp = msg.timestamp || msg.record_time;
|
|
60
|
+
this.emit("status", msg.status || "off", msg.timestamp || msg.record_time);
|
|
61
61
|
break;
|
|
62
62
|
case "live_change":
|
|
63
63
|
this.base = Object.assign(this.base, msg.info);
|
|
@@ -36,8 +36,8 @@ export interface ImageInfo {
|
|
|
36
36
|
id?: string | number;
|
|
37
37
|
/** 图像url */
|
|
38
38
|
url?: string;
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/** 图像高度 */
|
|
40
|
+
height?: number;
|
|
41
41
|
}
|
|
42
42
|
/** 礼物信息 */
|
|
43
43
|
export interface GiftInfo {
|
|
@@ -61,4 +61,6 @@ export interface GiftInfo {
|
|
|
61
61
|
action?: string;
|
|
62
62
|
/** 随机礼物信息 */
|
|
63
63
|
blind_gift?: GiftInfo;
|
|
64
|
+
/** 图片信息 */
|
|
65
|
+
image?: string;
|
|
64
66
|
}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { RoomBaseInfo, RoomStatsInfo, RoomStatus } from "../../lib/LiveRoom";
|
|
2
2
|
import { UserInfo, GiftInfo, ImageInfo } from "./AttributeInfo";
|
|
3
|
-
|
|
3
|
+
declare type MessageBase = {
|
|
4
4
|
/** 平台名称 */
|
|
5
5
|
platform: string;
|
|
6
6
|
/** 房间号 */
|
|
7
7
|
room: number | string;
|
|
8
8
|
/** 信息类型 */
|
|
9
9
|
type: string;
|
|
10
|
-
/** 数据信息 */
|
|
11
|
-
info: {
|
|
12
|
-
[attr: string]: any;
|
|
13
|
-
};
|
|
14
10
|
/** 记录时间 */
|
|
15
11
|
record_time: number;
|
|
16
12
|
/** 其他属性 */
|
|
17
13
|
[attr: string]: any;
|
|
14
|
+
};
|
|
15
|
+
export interface MessageInterface extends MessageBase {
|
|
16
|
+
/** 数据信息 */
|
|
17
|
+
info: {
|
|
18
|
+
[attr: string]: any;
|
|
19
|
+
};
|
|
18
20
|
}
|
|
19
21
|
export declare type MessageExt<T extends MessageInterface, E extends {
|
|
20
22
|
[attr: string]: any;
|
|
@@ -24,7 +26,7 @@ export declare type MessageExt<T extends MessageInterface, E extends {
|
|
|
24
26
|
info: E;
|
|
25
27
|
};
|
|
26
28
|
/** 文本聊天消息 */
|
|
27
|
-
export declare type MessageChat =
|
|
29
|
+
export declare type MessageChat = MessageBase & {
|
|
28
30
|
type: "chat";
|
|
29
31
|
info: {
|
|
30
32
|
/** 用户信息 */
|
|
@@ -42,11 +44,15 @@ export declare type MessageChat = MessageInterface & {
|
|
|
42
44
|
/** 图片信息 */
|
|
43
45
|
image?: ImageInfo;
|
|
44
46
|
/** 表情信息 */
|
|
45
|
-
emoticon?:
|
|
47
|
+
emoticon?: {
|
|
48
|
+
[keyword: string]: ImageInfo;
|
|
49
|
+
};
|
|
50
|
+
/** 标签信息 */
|
|
51
|
+
tag?: string;
|
|
46
52
|
};
|
|
47
53
|
};
|
|
48
54
|
/** 礼物消息 */
|
|
49
|
-
export declare type MessageGift =
|
|
55
|
+
export declare type MessageGift = MessageBase & {
|
|
50
56
|
type: "gift";
|
|
51
57
|
info: {
|
|
52
58
|
/** 用户信息 */
|
|
@@ -58,7 +64,7 @@ export declare type MessageGift = MessageInterface & {
|
|
|
58
64
|
};
|
|
59
65
|
};
|
|
60
66
|
/** 互动消息(进入直播间、点赞、关注、分享、加入粉丝团) */
|
|
61
|
-
export declare type MessageInteract =
|
|
67
|
+
export declare type MessageInteract = MessageBase & {
|
|
62
68
|
type: "entry" | "like" | "follow" | "share" | "join";
|
|
63
69
|
info: {
|
|
64
70
|
/** 用户信息 */
|
|
@@ -70,7 +76,7 @@ export declare type MessageInteract = MessageInterface & {
|
|
|
70
76
|
};
|
|
71
77
|
};
|
|
72
78
|
/** 粉丝vip开通消息 */
|
|
73
|
-
export declare type MessageMembership =
|
|
79
|
+
export declare type MessageMembership = MessageBase & {
|
|
74
80
|
type: "membership";
|
|
75
81
|
info: {
|
|
76
82
|
/** 用户信息 */
|
|
@@ -88,7 +94,7 @@ export declare type MessageMembership = MessageInterface & {
|
|
|
88
94
|
};
|
|
89
95
|
};
|
|
90
96
|
/** 粉丝vip开通消息 */
|
|
91
|
-
export declare type MessageSuperchat =
|
|
97
|
+
export declare type MessageSuperchat = MessageBase & {
|
|
92
98
|
type: "superchat";
|
|
93
99
|
info: {
|
|
94
100
|
/** 留言id */
|
|
@@ -108,7 +114,7 @@ export declare type MessageSuperchat = MessageInterface & {
|
|
|
108
114
|
};
|
|
109
115
|
};
|
|
110
116
|
/** 禁言消息 */
|
|
111
|
-
export declare type MessageBlock =
|
|
117
|
+
export declare type MessageBlock = MessageBase & {
|
|
112
118
|
type: "block";
|
|
113
119
|
info: {
|
|
114
120
|
/** 用户信息 */
|
|
@@ -122,7 +128,7 @@ export declare type MessageBlock = MessageInterface & {
|
|
|
122
128
|
};
|
|
123
129
|
};
|
|
124
130
|
/** 直播开播消息 */
|
|
125
|
-
export declare type MessageLiveStart =
|
|
131
|
+
export declare type MessageLiveStart = MessageBase & {
|
|
126
132
|
type: "live_start";
|
|
127
133
|
info: {
|
|
128
134
|
/** 开播时间 */
|
|
@@ -130,7 +136,7 @@ export declare type MessageLiveStart = MessageInterface & {
|
|
|
130
136
|
};
|
|
131
137
|
};
|
|
132
138
|
/** 直播切断消息 */
|
|
133
|
-
export declare type MessageLiveCut =
|
|
139
|
+
export declare type MessageLiveCut = MessageBase & {
|
|
134
140
|
type: "live_cut";
|
|
135
141
|
info: {
|
|
136
142
|
/** 切断消息 */
|
|
@@ -138,17 +144,17 @@ export declare type MessageLiveCut = MessageInterface & {
|
|
|
138
144
|
};
|
|
139
145
|
};
|
|
140
146
|
/** 直播数据更新 */
|
|
141
|
-
export declare type MessageLiveStats =
|
|
147
|
+
export declare type MessageLiveStats = MessageBase & {
|
|
142
148
|
type: "live_stats";
|
|
143
149
|
info: RoomStatsInfo;
|
|
144
150
|
};
|
|
145
151
|
/** 直播信息更新 */
|
|
146
|
-
export declare type MessageLiveChange =
|
|
152
|
+
export declare type MessageLiveChange = MessageBase & {
|
|
147
153
|
type: "live_change";
|
|
148
154
|
info: RoomBaseInfo;
|
|
149
155
|
};
|
|
150
156
|
/** 直播结束 */
|
|
151
|
-
export declare type MessageLiveEnd =
|
|
157
|
+
export declare type MessageLiveEnd = MessageBase & {
|
|
152
158
|
type: "live_end";
|
|
153
159
|
info: {
|
|
154
160
|
/** 直播状态 */
|