npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

douyudm

v2.1.1

Published

实时获取斗鱼弹幕

Downloads

525

Readme

douyudm

基于websocket实时获取斗鱼弹幕

>= 2.0.0 不再支持WEB引用

安装(命令行)

npm i -g douyudm
or
yarn global add douyudm

使用(命令行)

通过命令行监听,默认显示,--debug开启输出到文件,默认保存当前运行目录

douyudm -i 房间号

更多命令查看 douyudm --help

安装(API)

npm i douyudm
or
yarn add douyudm

使用(API)

通过库调用自行封装

//引入类库
const douyu = require('douyudm')

//设置房间号,初始化
const roomId = 102965
const opts = {
    debug: true,  // 默认关闭 false
}
const room = new douyu(roomId, opts)

//系统事件
room.on('connect', function () {
    console.log('[connect] roomId=%s', this.roomId)
})
room.on('disconnect', function () {
    console.log('[disconnect] roomId=%s', this.roomId)
})
room.on('error', function(err) {
    console.log('[error] roomId=%s', this.roomId)
})

//消息事件
room.on('chatmsg', function(res) {
    console.log('[chatmsg]', `<lv ${res.level}> [${res.nn}] ${res.txt}`)
})
room.on('loginres', function(res) {
    console.log('[loginres]', '登录成功')
})
room.on('uenter', function(res) {
    console.log('[uenter]', `${res.nn}进入房间`)
})

//开始监听
room.run()

事件列表

| 系统事件 | 描述 | |:----------:|:--------:| | connect | 连接 | | disconnect | 断开 | | error | 错误监听 |


| 消息事件 | 描述 | |:---------------------:|:----------------------:| | loginres | 登入 | | pingreq | 跟随 loginres 一起 | | chatmsg | 弹幕消息 | | uenter | 进入房间 | | upgrade | 用户等级提升 | | rss | 房间开播提醒 | | bc_buy_deserve | 赠送酬勤通知 | | ssd | 超级弹幕 | | spbc | 房间内礼物广播 | | dgb | 赠送礼物 | | onlinegift | 领取在线鱼丸 | | ggbb | 房间用户抢红包 | | rankup | 房间内top10变化消息 | | ranklist | 广播排行榜消息 | | mrkl | 心跳 | | erquizisn | 鱼丸预言 | | blab | 粉丝等级升级 | | rri | 未知的消息事件 | | synexp | 未知的消息事件 | | noble_num_info | 未知的消息事件 | | gbroadcast | 未知的消息事件 | | qausrespond | 未知的消息事件 | | wiru | 未知的消息事件 | | wirt | 未知的消息事件 | | mcspeacsite | 未知的消息事件 | | rank_change | 未知的消息事件 | | srres | 未知的消息事件 | | anbc | 未知的消息事件 | | frank | 未知的消息事件 | | rnewbc | 未知的消息事件 | | nlkstatus | 未知的消息事件 | | pandoraboxinfo | 未知的消息事件 | | ro_game_succ | 未知的消息事件 | | lucky_wheel_star_pool | 未知的消息事件 | | tsgs | 未知的消息事件 | | fswrank | 未知的消息事件 | | tsboxb | 未知的消息事件 | | cthn | 未知的消息事件 | | configscreen | 估计是全屏广播显示礼物 | | rnewbc | 未知的消息事件 |

斗鱼STT序列化反序列化库

STT序列化规定如下:

  1. 键key和值value直接采用@=分割
  2. 数组采用/分割
  3. 如果key或者value中含有字符/, 则使用@S转义
  4. 如果key或者value中含有字符@, 则使用@A转义

序列化测试

npm run test:stt
or
yarn test:stt

后话

坑太多了,github上的库大部分都是不能使用的,如果近期更新的可以判断使用的新接口,review了几乎所有相关的库,都是依据斗鱼自己官方平台的方法发起tcp连接?但根本连不上,一直拒绝...

看了下能使用的库,都是通过websocket建立的连接,立马修改,不出片刻撸完,发现发送数据的格式有点难搞,虽说示意图挺清楚的,但是用Buffer传输死活没有相应的消息,调试太磨人心性了,玛德,直接去把斗鱼网页上的方法扒下来。

通过webpack打包混淆代码乍一眼看去很混乱,其实仔细观察还是有规律寻找的。

文档中编码的几个固定参数均为数字,在webpack中数字的混淆我还没见过,按这个思路精准的找到这段代码。经过我十几分钟的理解,提取出 bufferCoder.js

斗鱼自有的序列化,反序列化方法可以查看 stt.js