Skip to content

Commit

Permalink
fix: support DANMU_MSG:4:0:2:2:2:0 msg (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Dec 1, 2022
1 parent 2d032df commit 4a750c7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/listener/index.ts
Expand Up @@ -2,7 +2,7 @@ import {
HEARTBEAT, type AttentionChangeMsgHandler,
LIVE, type LiveStartMsgHandler,
PREPARING, type LiveStopMsgHandler,
DANMU_MSG, type DanmuMsgHandler,
DANMU_MSG, DANMU_MSG_402220, type DanmuMsgHandler,
GUARD_BUY, type GuardBuyHandler,
INTERACT_WORD, ENTRY_EFFECT, type UserActionMsgHandler,
LIKE_INFO_V3_UPDATE, type LikedChangeMsgHandler,
Expand Down Expand Up @@ -98,11 +98,15 @@ export const listenAll = (instance: KeepLiveTCP | KeepLiveWS, roomId: number, ha
}

// DANMU_MSG
if (handler[DANMU_MSG.handlerName]) {
if (handler[DANMU_MSG.handlerName] || handler[DANMU_MSG_402220.handlerName]) {
instance.on(DANMU_MSG.eventName, (data: WSMessage<any>) => {
const parsedData = DANMU_MSG.parser(data.data, roomId)
handler[DANMU_MSG.handlerName]?.(normalizeDanmu(DANMU_MSG.eventName, parsedData))
})
instance.on(DANMU_MSG_402220.eventName, (data: WSMessage<any>) => {
const parsedData = DANMU_MSG_402220.parser(data.data, roomId)
handler[DANMU_MSG_402220.handlerName]?.(normalizeDanmu(DANMU_MSG_402220.eventName, parsedData))
})
}

// GUARD_BUY
Expand Down
6 changes: 6 additions & 0 deletions src/parser/DANMU_MSG.ts
Expand Up @@ -65,6 +65,12 @@ export const DANMU_MSG = {
handlerName: 'onIncomeDanmu' as const,
}

export const DANMU_MSG_402220 = {
parser,
eventName: 'DANMU_MSG:4:0:2:2:2:0' as const,
handlerName: 'onIncomeDanmu' as const,
}

export type Handler = {
/** 收到普通弹幕消息 */
onIncomeDanmu: (msg: Message<DanmuMsg>) => void
Expand Down
2 changes: 1 addition & 1 deletion src/parser/index.ts
@@ -1,7 +1,7 @@
export { HEARTBEAT, type Handler as AttentionChangeMsgHandler, type AttentionChangeMsg } from './HEARTBEAT'
export { LIVE, type Handler as LiveStartMsgHandler, type LiveStartMsg } from './LIVE'
export { PREPARING, type Handler as LiveStopMsgHandler, type LiveEndMsg } from './PREPARING'
export { DANMU_MSG, type Handler as DanmuMsgHandler, type DanmuMsg } from './DANMU_MSG'
export { DANMU_MSG, DANMU_MSG_402220, type Handler as DanmuMsgHandler, type DanmuMsg } from './DANMU_MSG'
export { GUARD_BUY, type Handler as GuardBuyHandler, type GuardBuyMsg } from './GUARD_BUY'
export { INTERACT_WORD, ENTRY_EFFECT, type Handler as UserActionMsgHandler, type UserActionMsg } from './INTERACT_WORD_ENTRY_EFFECT'
export { LIKE_INFO_V3_UPDATE, type Handler as LikedChangeMsgHandler, type LikedChangeMsg } from './LIKE_INFO_V3_UPDATE'
Expand Down
12 changes: 12 additions & 0 deletions test/index.ts
@@ -0,0 +1,12 @@
import { startListen, type MsgHandler } from '../dist/index'

const handler: MsgHandler = {
onStartListen: () => {
console.log('start listen')
},
onIncomeDanmu: (msg) => {
console.log(msg)
},
}

startListen(652581, handler)
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"lib": ["ESNext"],
"lib": ["ESNext", "dom"],
"strict": true,
"esModuleInterop": true,
"moduleResolution": "Node",
Expand Down

0 comments on commit 4a750c7

Please sign in to comment.