Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix live crash #232

Merged
merged 5 commits into from
Nov 13, 2023
Merged

fix live crash #232

merged 5 commits into from
Nov 13, 2023

Conversation

lanytcc
Copy link
Contributor

@lanytcc lanytcc commented Nov 12, 2023

今天上来跑就崩溃,发现了个惊天大bug😂,居然这么长时间都能跑

LiveActivity::LiveActivity(const bilibili::LiveVideoResult& live)
: liveData(live) {
brls::Logger::debug("LiveActivity: create: {}", live.roomid);
LiveDanmaku::instance().setonMessage(onDanmakuReceived);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

问题就在这,原来是先this->setCommonData(),再注册函数,但是这样连接的过快的话LiveDanmaku里面的onMessage是空的

@xfangfang
Copy link
Owner

竟然还有这个问题,我倒是没遇到过,可能我这边网络速度不行 : )

LiveActivity::LiveActivity(const bilibili::LiveVideoResult& live) 这个构造函数现在完全没有在使用了,其实删掉也是可以的。或者 可以把 LiveDanmaku::instance().setonMessage 还有顺便把那两个 GA一起都写到 setCommonData 里面去。

我有两个小建议:

  1. LiveDanmaku::connect 内部的逻辑变成先调用 get_live_s 异步获取token,然后再开始连接好不好。这样避免了网络质量不好的设备点开直播间时卡顿(比如 psv)。
  2. mongoose_thread 中 wait_time 的值可以设置一个更低的默认值吗?比如 100,应该也不会对性能有比较大的影响?800还是有点过于高了,关闭直播页的体验会稍差一点。

如果要做异步请求的话,可以模仿这个提交来做:ec3295e

只需要声明好数据结构,按照如下形式调用即可:

HTTP::getResultAsync<LiveDanmuInfo>(
        Api::DanmuInfo,
        {{"id", std::to_string(roomid)},
         {"type", "0"},
        callback, error);

当然你也可以用cpr自己解析一下json,不过json解析的报错或者返回的code报错之类的就需要自己来处理了。

@lanytcc
Copy link
Contributor Author

lanytcc commented Nov 13, 2023

可以了,你可以测试一下

@xfangfang xfangfang merged commit a3ed021 into xfangfang:dev Nov 13, 2023
14 checks passed
@xfangfang
Copy link
Owner

感谢,看来又要更新版本了

@xfangfang
Copy link
Owner

发现了一个问题,因为获取token变成异步了,会出现一些比较奇怪的问题,比如:

在获取token返回之前退出直播间,并重新进入。这时候两个异步请求都能正常向后执行。

我想到的一个比较简单的修复是,把获取token的函数提到 activity 里去,这样当 activity销毁的时候,如果异步请求还没有执行结束,那么他的回调就会被舍弃。

    LiveDanmaku::instance().setonMessage(onDanmakuReceived);
    ASYNC_RETAIN
    bilibili::HTTP::getResultAsync<LiveDanmakuinfo>(
        "https://api.live.bilibili.com/xlive/web-room/v1/index/"
        "getDanmuInfo?type=0&id=" +
            std::to_string(this->liveData.roomid),
        {},
        [ASYNC_TOKEN](const auto& info) {
            ASYNC_RELEASE
            LiveDanmaku::instance().connect(
                liveData.roomid,
                std::stoll(ProgramConfig::instance().getUserID()), info);
        },
        [ASYNC_TOKEN](const std::string& error) {
            ASYNC_RELEASE
            brls::Logger::error("getDanmuInfo error:{}", error);
        });

@xfangfang xfangfang mentioned this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants