Skip to content

Commit

Permalink
feat: 导出实例类型MessageListener,增加close、getAttention方法
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Sep 26, 2022
1 parent 48bfce9 commit aba44e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/index.ts
Expand Up @@ -2,12 +2,27 @@ import { KeepLiveTCP } from 'bilibili-live-ws'

import { listenAll, type MsgHandler } from './listener'

export interface MessageListener {
/** 直播间房间号 */
roomId: number
/** 关闭连接 */
close: () => void
/** 刷新当前直播间热度 */
getAttention: () => Promise<number>
}

export const startListen = (roomId: number, handler: MsgHandler) => {
const live = new KeepLiveTCP(roomId)

listenAll(live, roomId, handler)

return live
const listenerInstance: MessageListener = {
roomId: live.roomid,
close: () => live.close(),
getAttention: () => live.getOnline(),
}

return listenerInstance
}

export type { MsgHandler }
Expand Down

0 comments on commit aba44e5

Please sign in to comment.