Skip to content

Commit

Permalink
fix: listen DANMU_MSG message failed, close #1
Browse files Browse the repository at this point in the history
starknt committed Dec 17, 2022
1 parent 2e99129 commit e12b829
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion playground/node/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Message } from 'tiny-bilibili-ws'
import { KeepLiveTCP, getLongRoomId } from 'tiny-bilibili-ws'

const res = await getLongRoomId(7777)
const res = await getLongRoomId(7688602)

const live = new KeepLiveTCP(res.data.room_id)

8 changes: 5 additions & 3 deletions src/base.ts
Original file line number Diff line number Diff line change
@@ -95,15 +95,17 @@ export class LiveClient<T extends string = ListenerEvents> extends EventEmitter<

for (const packet of packs) {
if (packet.meta.op === WS_OP.MESSAGE) {
const cmd = packet.data?.cmd || (packet.data?.msg && packet.data?.msg?.cmd)
const cmd: string = packet.data?.cmd || (packet.data?.msg && packet.data?.msg?.cmd)
if (this.skipMessage.length > 0 && !this.skipMessage.includes(cmd))
continue

if (this.options.stub)
this.emit('msg', packet)

if (cmd)
this.emit(cmd, packet)
if (cmd.includes('DANMU_MSG'))
this.emit('DANMU_MSG', packet)
else
this.emit(cmd as any, packet)

continue
}

0 comments on commit e12b829

Please sign in to comment.