Skip to content

Commit d898a01

Browse files
committed
fix: check if info exists within DANMU_MSG parser (#34)
1 parent 539ee92 commit d898a01

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

mock/RECALL_DANMU_MSG/normal.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"cmd": "RECALL_DANMU_MSG",
3+
"data": {
4+
"recall_type": 2,
5+
"target_id": 77777777771
6+
}
7+
}

src/listener/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ export const listenAll = (instance: KeepLiveTCP | KeepLiveWS | KeepLiveWSB, room
140140
instance.on(DANMU_MSG.eventName, (data) => {
141141
isHandleRaw && rawHandler[DANMU_MSG.eventName]?.(data.data)
142142
const parsedData = DANMU_MSG.parser(data.data, roomId)
143+
if (!parsedData) {
144+
return
145+
}
143146
handler[DANMU_MSG.handlerName]?.(normalizeDanmu(DANMU_MSG.eventName, parsedData, data.data))
144147
})
145148
}

src/parser/DANMU_MSG.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ export interface DanmuMsg {
3232
}>
3333
}
3434

35-
const parser = (data: DataType, roomId: number): DanmuMsg => {
35+
const parser = (data: DataType, roomId: number): DanmuMsg | null => {
3636
const rawData = data.info
37+
if (!rawData) {
38+
return null
39+
}
3740
const content = rawData[1]
3841
const shouldParseInMessageEmoticon = /\[.*?\]/.test(content)
3942
let inMessageEmoticon

0 commit comments

Comments
 (0)