Skip to content

Commit 4a750c7

Browse files
committed
fix: support DANMU_MSG:4:0:2:2:2:0 msg (#14)
1 parent 2d032df commit 4a750c7

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

src/listener/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
HEARTBEAT, type AttentionChangeMsgHandler,
33
LIVE, type LiveStartMsgHandler,
44
PREPARING, type LiveStopMsgHandler,
5-
DANMU_MSG, type DanmuMsgHandler,
5+
DANMU_MSG, DANMU_MSG_402220, type DanmuMsgHandler,
66
GUARD_BUY, type GuardBuyHandler,
77
INTERACT_WORD, ENTRY_EFFECT, type UserActionMsgHandler,
88
LIKE_INFO_V3_UPDATE, type LikedChangeMsgHandler,
@@ -98,11 +98,15 @@ export const listenAll = (instance: KeepLiveTCP | KeepLiveWS, roomId: number, ha
9898
}
9999

100100
// DANMU_MSG
101-
if (handler[DANMU_MSG.handlerName]) {
101+
if (handler[DANMU_MSG.handlerName] || handler[DANMU_MSG_402220.handlerName]) {
102102
instance.on(DANMU_MSG.eventName, (data: WSMessage<any>) => {
103103
const parsedData = DANMU_MSG.parser(data.data, roomId)
104104
handler[DANMU_MSG.handlerName]?.(normalizeDanmu(DANMU_MSG.eventName, parsedData))
105105
})
106+
instance.on(DANMU_MSG_402220.eventName, (data: WSMessage<any>) => {
107+
const parsedData = DANMU_MSG_402220.parser(data.data, roomId)
108+
handler[DANMU_MSG_402220.handlerName]?.(normalizeDanmu(DANMU_MSG_402220.eventName, parsedData))
109+
})
106110
}
107111

108112
// GUARD_BUY

src/parser/DANMU_MSG.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export const DANMU_MSG = {
6565
handlerName: 'onIncomeDanmu' as const,
6666
}
6767

68+
export const DANMU_MSG_402220 = {
69+
parser,
70+
eventName: 'DANMU_MSG:4:0:2:2:2:0' as const,
71+
handlerName: 'onIncomeDanmu' as const,
72+
}
73+
6874
export type Handler = {
6975
/** 收到普通弹幕消息 */
7076
onIncomeDanmu: (msg: Message<DanmuMsg>) => void

src/parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { HEARTBEAT, type Handler as AttentionChangeMsgHandler, type AttentionChangeMsg } from './HEARTBEAT'
22
export { LIVE, type Handler as LiveStartMsgHandler, type LiveStartMsg } from './LIVE'
33
export { PREPARING, type Handler as LiveStopMsgHandler, type LiveEndMsg } from './PREPARING'
4-
export { DANMU_MSG, type Handler as DanmuMsgHandler, type DanmuMsg } from './DANMU_MSG'
4+
export { DANMU_MSG, DANMU_MSG_402220, type Handler as DanmuMsgHandler, type DanmuMsg } from './DANMU_MSG'
55
export { GUARD_BUY, type Handler as GuardBuyHandler, type GuardBuyMsg } from './GUARD_BUY'
66
export { INTERACT_WORD, ENTRY_EFFECT, type Handler as UserActionMsgHandler, type UserActionMsg } from './INTERACT_WORD_ENTRY_EFFECT'
77
export { LIKE_INFO_V3_UPDATE, type Handler as LikedChangeMsgHandler, type LikedChangeMsg } from './LIKE_INFO_V3_UPDATE'

test/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { startListen, type MsgHandler } from '../dist/index'
2+
3+
const handler: MsgHandler = {
4+
onStartListen: () => {
5+
console.log('start listen')
6+
},
7+
onIncomeDanmu: (msg) => {
8+
console.log(msg)
9+
},
10+
}
11+
12+
startListen(652581, handler)

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"module": "ESNext",
44
"target": "ESNext",
5-
"lib": ["ESNext"],
5+
"lib": ["ESNext", "dom"],
66
"strict": true,
77
"esModuleInterop": true,
88
"moduleResolution": "Node",

0 commit comments

Comments
 (0)