douyin-danma-listener 0.1.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/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "douyin-danma-listener",
3
+ "version": "0.1.0",
4
+ "description": "douyin danma listener",
5
+ "main": "./lib/index.js",
6
+ "types": "./types/index.d.ts",
7
+ "type": "module",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/index.ts",
14
+ "development": "./src/index.ts",
15
+ "default": "./lib/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "lib",
20
+ "types"
21
+ ],
22
+ "keywords": [
23
+ "douyin",
24
+ "recorder",
25
+ "bililive-tools",
26
+ "直播",
27
+ "danma",
28
+ "弹幕",
29
+ "抖音"
30
+ ],
31
+ "repository": "https://github.com/renmu123/biliLive-tools/tree/master/packages/DouYinDanma",
32
+ "author": "renmu123",
33
+ "license": "GPLV3",
34
+ "dependencies": {
35
+ "protobufjs": "^7.4.0",
36
+ "tiny-typed-emitter": "^2.1.0",
37
+ "ws": "^8.18.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "*",
41
+ "protobufjs-cli": "^1.1.3"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc",
45
+ "watch": "tsc -w",
46
+ "gen:proto": "pbjs -t static-module -w es6 -o src/danma/proto.js src/danma/dy.proto"
47
+ }
48
+ }
@@ -0,0 +1,44 @@
1
+ import { TypedEmitter } from "tiny-typed-emitter";
2
+ import type {
3
+ ChatMessage,
4
+ MemberMessage,
5
+ LikeMessage,
6
+ SocialMessage,
7
+ GiftMessage,
8
+ RoomUserSeqMessage,
9
+ RoomStatsMessage,
10
+ RoomRankMessage,
11
+ Message,
12
+ } from "../types/types.js";
13
+ import WebSocket from "ws";
14
+
15
+ interface Events {
16
+ open: () => void;
17
+ close: () => void;
18
+ reconnect: (count: number) => void;
19
+ heartbeat: () => void;
20
+ error: (error: Error) => void;
21
+ chat: (message: ChatMessage) => void;
22
+ member: (message: MemberMessage) => void;
23
+ like: (message: LikeMessage) => void;
24
+ social: (message: SocialMessage) => void;
25
+ gift: (message: GiftMessage) => void;
26
+ roomUserSeq: (message: RoomUserSeqMessage) => void;
27
+ roomStats: (message: RoomStatsMessage) => void;
28
+ roomRank: (message: RoomRankMessage) => void;
29
+ message: (message: Message) => void;
30
+ }
31
+ declare class DouYinDanmaClient extends TypedEmitter<Events> {
32
+ private ws: WebSocket;
33
+ constructor(
34
+ roomId: string,
35
+ options?: {
36
+ autoStart?: boolean;
37
+ autoReconnect?: number;
38
+ heartbeatInterval?: number;
39
+ cookie?: string;
40
+ },
41
+ );
42
+ connect(): Promise<void>;
43
+ }
44
+ export default DouYinDanmaClient;
@@ -0,0 +1,197 @@
1
+ interface Common {
2
+ method: string;
3
+ msgId: string;
4
+ roomId: string;
5
+ isShowMsg: boolean;
6
+ priorityScore?: string;
7
+ foldType?: string;
8
+ anchorFoldType?: string;
9
+ anchorFoldTypeV2?: string;
10
+ createTime?: string;
11
+ }
12
+
13
+ interface AvatarThumb {
14
+ urlListList: string[];
15
+ uri: string;
16
+ avgColor: string;
17
+ }
18
+
19
+ interface BadgeImage {
20
+ urlListList: string[];
21
+ height: string;
22
+ width: string;
23
+ imageType: number;
24
+ content: {
25
+ level: string;
26
+ alternativeText: string;
27
+ };
28
+ }
29
+
30
+ interface User {
31
+ id: string;
32
+ nickName: string;
33
+ AvatarThumb: AvatarThumb;
34
+ BadgeImageList: BadgeImage[];
35
+ }
36
+
37
+ interface AnchorDisplayText {
38
+ key: string;
39
+ defaultPatter: string;
40
+ defaultFormat: {
41
+ color: string;
42
+ weight: number;
43
+ };
44
+ piecesList: {
45
+ type: boolean;
46
+ format: {
47
+ color: string;
48
+ weight: number;
49
+ };
50
+ }[];
51
+ }
52
+
53
+ interface DisplayControlInfo {
54
+ showText: boolean;
55
+ showIcons: boolean;
56
+ }
57
+
58
+ interface Image {
59
+ urlListList: string[];
60
+ uri: string;
61
+ avgColor: string;
62
+ }
63
+
64
+ interface Gift {
65
+ image: Image;
66
+ describe: string;
67
+ id: string;
68
+ forLinkmic: boolean;
69
+ combo: boolean;
70
+ type: number;
71
+ diamondCount: number;
72
+ isDisplayedOnPanel: boolean;
73
+ name: string;
74
+ icon: Image;
75
+ }
76
+
77
+ interface UserLabel {
78
+ urlListList: string[];
79
+ uri: string;
80
+ avgColor: string;
81
+ }
82
+
83
+ interface PublicAreaCommon {
84
+ userLabel: UserLabel;
85
+ }
86
+
87
+ interface Format {
88
+ color: string;
89
+ weight: number;
90
+ useRemoteClor: boolean;
91
+ }
92
+
93
+ interface Piece {
94
+ type: boolean;
95
+ format: Format;
96
+ }
97
+
98
+ interface TrayDisplayText {
99
+ key: string;
100
+ defaultPatter: string;
101
+ defaultFormat: Format;
102
+ piecesList: Piece[];
103
+ }
104
+
105
+ interface Rank {
106
+ user: User;
107
+ rank: string;
108
+ }
109
+
110
+ export interface ChatMessage {
111
+ common: Common & { method: "WebcastChatMessage" };
112
+ user: User;
113
+ content: string;
114
+ // giftImage: {
115
+ // urlListList: string[];
116
+ // width: string;
117
+ // content: Record<string, unknown>;
118
+ // };
119
+ // individualChatPriority: number;
120
+ }
121
+
122
+ export interface MemberMessage {
123
+ common: Common & { method: "WebcastMemberMessage" };
124
+ user: User;
125
+ memberCount: string;
126
+ action: string;
127
+ anchorDisplayText: AnchorDisplayText;
128
+ publicAreaCommon: Record<string, unknown>;
129
+ }
130
+
131
+ export interface LikeMessage {
132
+ common: Common & { method: "WebcastLikeMessage" };
133
+ count: string;
134
+ total: string;
135
+ user: User;
136
+ displayControlInfo: DisplayControlInfo;
137
+ }
138
+
139
+ export interface SocialMessage {
140
+ common: Common & { method: "WebcastSocialMessage" };
141
+ user: User;
142
+ action: string;
143
+ shareTarget: string;
144
+ followCount: string;
145
+ publicAreaCommon: Record<string, unknown>;
146
+ }
147
+
148
+ export interface GiftMessage {
149
+ common: Common & { method: "WebcastGiftMessage" };
150
+ user: User;
151
+ groupId: string;
152
+ gift: Gift;
153
+ publicAreaCommon: PublicAreaCommon;
154
+ trayDisplayText: TrayDisplayText;
155
+ totalCount: string;
156
+ clientGiftSource: number;
157
+ sendTime: string;
158
+ }
159
+
160
+ export interface RoomUserSeqMessage {
161
+ common: Common & { method: "WebcastRoomUserSeqMessage" };
162
+ ranksList: Rank[];
163
+ total: string;
164
+ totalUser: string;
165
+ totalUserStr: string;
166
+ totalStr: string;
167
+ onlineUserForAnchor: string;
168
+ totalPvForAnchor: string;
169
+ }
170
+
171
+ export interface RoomStatsMessage {
172
+ common: Common & { method: "WebcastRoomStatsMessage" };
173
+ displayShort: string;
174
+ displayMiddle: string;
175
+ displayLong: string;
176
+ displayValue: string;
177
+ displayVersion: string;
178
+ total: string;
179
+ displayType: string;
180
+ }
181
+
182
+ export interface RoomRankMessage {
183
+ common: Common & { method: "WebcastRoomRankMessage" };
184
+ ranks: {
185
+ user: User;
186
+ }[];
187
+ }
188
+
189
+ export type Message =
190
+ | ChatMessage
191
+ | MemberMessage
192
+ | LikeMessage
193
+ | SocialMessage
194
+ | GiftMessage
195
+ | RoomUserSeqMessage
196
+ | RoomStatsMessage
197
+ | RoomRankMessage;