0.7.3 • Published 2 months ago

acfun-live-danmaku v0.7.3

Weekly downloads
-
License
GPLv3
Repository
github
Last release
2 months ago

acfun-live-danmaku

简介

acfun-live-danmaku是一个用于获取acfun直播弹幕的服务端js组件

  • 因为使用了buffer所以不能运行在浏览器环境下, 编写使用node v16 lts

使用方式

const { getAcClient } = require("acfun-live-danmaku")

// 使用init(主播房间号)初始化客户端
AcClient("8500263").then(({ client }) => {
    // 启动websocket连接
    client.wsStart();
    client.on("EnterRoomAck", () => {
        console.log("Enter room success!");
    });
    client.on("RecentComment", (msg) => {
        // 获得建立连接当前的弹幕列表
        console.log(msg);
    });
    client.on("Comment", (msg) => {
        // 收到的弹幕
        console.log(msg);
    });
});

或者

const { getAcClient } = require("acfun-live-danmaku")

// 使用init(主播房间号)初始化客户端
const { client } = await getAcClient("8500263")
// 启动websocket连接
client.wsStart();
client.on("EnterRoomAck", () => {
    console.log("Enter room success!");
});
client.on("RecentComment", (commmnets) => {
    // 获得建立连接当前的弹幕列表
    console.log(commmnets);
});
client.on("Comment", (danmaku) => {
    // 收到的弹幕
    console.log(danmaku);
});

收到的弹幕返回如下

{
    content: '晚安',
    sendTimeMs: Long {
        low: -1921110048,
        high: 372,
        unsigned: false
    },
    userInfo: ZtLiveUserInfo {
        avatar: [
            [ImageCdnNode]
        ],
        userId: Long {
            low: 147764,
            high: 0,
            unsigned: false
        },
        nickname: 'NNK',
        badge: '{"medalInfo":{"uperId":100001,"userId":100001,"clubName":"蓝钻","level":100}}',
        userIdentity: ZtLiveUserIdentity {}
    }
}

事件列表

事件消息payload类型
EnterRoomAck程序进入直播间null
Comment弹幕CommonActionSignalComment
Like点赞CommonActionSignalLike
Gift发送礼物CommonActionSignalGift
UserFollowAuthor关注主播CommonActionSignalUserFollowAuthor
UserEnterRoom用户进入直播间CommonActionSignalUserEnterRoom
DisplayInfo当前直播间数据状态CommonStateSignalDisplayInfo
RecentComment当前弹幕列表CommonStateSignalRecentComment
TopUsers前几名用户的数据CommonStateSignalTopUsers
JoinClub用户加入主播守护团AcfunActionSignalJoinClub

安装

npm i acfun-live-danmaku --save