Open futuretech6 opened 1 year ago
Yeah, I found this issue. Actually, if you use this to connect a live room that has a lot of audience, this will lose some messages. I will try to fix it in a couple of days.
I found I can't send danmaku in bilibili_live_tui sometimes but can do it in bili-live-chat.
That's weird!!!
bilibili_live_tui.1:
bilibili_live_tui.2:
bili-live-chat:
If you modify the following code in src/app.rs
, can avoid losing messages occasionally.
let client2 = self.danmu_client.clone();
let recv_msg = tokio::spawn(async move {
loop {
client2.lock().await.receive().await;
// tokio::time::sleep(Duration::from_secs_f32(0.3)).await;
tokio::time::sleep(Duration::from_secs_f32(0.01)).await;
}
});
If you modify the following code in
src/app.rs
, can avoid losing messages occasionally.let client2 = self.danmu_client.clone(); let recv_msg = tokio::spawn(async move { loop { client2.lock().await.receive().await; // tokio::time::sleep(Duration::from_secs_f32(0.3)).await; tokio::time::sleep(Duration::from_secs_f32(0.01)).await; } });
So that's some sync problem?
I send several messages using bilibili_live_tui, none of them fails. But I can't a single message using bili-live-chat, and there is no error message such as "发送弹幕失败".
If you modify the following code in
src/app.rs
, can avoid losing messages occasionally.let client2 = self.danmu_client.clone(); let recv_msg = tokio::spawn(async move { loop { client2.lock().await.receive().await; // tokio::time::sleep(Duration::from_secs_f32(0.3)).await; tokio::time::sleep(Duration::from_secs_f32(0.01)).await; } });
So that's some sync problem?
Actually yes, because there are 2 tasks that need to manipulate the client
, and the client
be protected by Mutex
. If we do not send a 'heartbeat' to the server within the 60s, the server would close the connection with us. So we have to sleep the receiving message task and release the Mutex
protecting the client
to make sure that the 'heartbeat' be sent within a reasonable time.
And I found a possible reason that some messages can not be sent. That is caused by the data that do not be encoded by urlencode
.
At the branch dev 95402a0f09eb5e2b0e9454c7b332da770cb96cbe, the sync problem had been solved.
At the branch dev 95402a0, the sync problem had been solved.
I test it using roomId 23141761, it is ok but the messages box are refreshed once many seconds rather then fetched immediately (possibly due to the message frequency is very high in that room)
I found that when messages are sent very frequently, the Danmaku Receiver in the BiLiBiLi web client also has this problem.
I can send message using bilibili_live_tui with same device and network in the same room but can't use this.
Also, some messages are lost occasionally.