FishZe / go-bili-chat

Bilibili直播间弹幕处理库 支持事件绑定 高性能 低占用
GNU Affero General Public License v3.0
39 stars 10 forks source link

调整authBody发送时机 & 支持自定义authBody #37

Closed yawntee closed 6 months ago

yawntee commented 7 months ago
  1. 修复authBody可能会在open之前发送,导致连接失败
  2. 由于目前的websocket库存在连接失败后消息循环未终止,而是一直读取MessageType为-1的消息(EOF)的情况,将其更换为了gws
  3. 支持自定义authBody(可以用官方开放平台的key绕过cookie验证)
FishZe commented 6 months ago

感谢pr。

但是在测试过程中,发现如果出现断开重连的情况,似乎不会再次调用OnOpen方法,导致无法发送AuthBody

[bili-live][04-22 21:24:44][DEBUG]: Add Option: DANMU_MSG21692711 
[bili-live][04-22 21:24:44][DEBUG]: Add Option: SUPER_CHAT_MESSAGE21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: SEND_GIFT21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: USER_TOAST_MSG21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: INTERACT_WORD21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: HEARTBEAT_REPLY21692711
[bili-live][04-22 21:24:44][DEBUG]: try to get live room info: 21692711
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket: wss://zj-cn-live-comet.chat.bilibili.com:2245/sub
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket success 
[bili-live][04-22 21:24:44][INFO]: connected to blive success: 21692711
[bili-live][04-22 21:24:44][DEBUG]: start blive success: 21692711
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket success
[bili-live][04-22 21:24:44][DEBUG]: send auth msg to blive success
[bili-live][04-22 21:24:44][INFO]: disconnected from blive: 21692711 
[bili-live][04-22 21:24:46][DEBUG]: try to get live room info: 21692711 
[bili-live][04-22 21:24:46][DEBUG]: connect to blive websocket: wss://zj-cn-live-comet.chat.bilibili.com:2245/sub
[bili-live][04-22 21:24:46][DEBUG]: connect to blive websocket success 
[bili-live][04-22 21:24:46][INFO]: connected to blive success: 21692711
[bili-live][04-22 21:25:14][DEBUG]: send heart beat to blive... 
[bili-live][04-22 21:25:44][DEBUG]: send heart beat to blive... 

模拟了一个cookie不合法的情况,在发送认证包后会被断开,在再次连接时不会发送认证包

yawntee commented 6 months ago

感谢pr。

但是在测试过程中,发现如果出现断开重连的情况,似乎不会再次调用OnOpen方法,导致无法发送AuthBody

[bili-live][04-22 21:24:44][DEBUG]: Add Option: DANMU_MSG21692711 
[bili-live][04-22 21:24:44][DEBUG]: Add Option: SUPER_CHAT_MESSAGE21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: SEND_GIFT21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: USER_TOAST_MSG21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: INTERACT_WORD21692711
[bili-live][04-22 21:24:44][DEBUG]: Add Option: HEARTBEAT_REPLY21692711
[bili-live][04-22 21:24:44][DEBUG]: try to get live room info: 21692711
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket: wss://zj-cn-live-comet.chat.bilibili.com:2245/sub
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket success 
[bili-live][04-22 21:24:44][INFO]: connected to blive success: 21692711
[bili-live][04-22 21:24:44][DEBUG]: start blive success: 21692711
[bili-live][04-22 21:24:44][DEBUG]: connect to blive websocket success
[bili-live][04-22 21:24:44][DEBUG]: send auth msg to blive success
[bili-live][04-22 21:24:44][INFO]: disconnected from blive: 21692711 
[bili-live][04-22 21:24:46][DEBUG]: try to get live room info: 21692711 
[bili-live][04-22 21:24:46][DEBUG]: connect to blive websocket: wss://zj-cn-live-comet.chat.bilibili.com:2245/sub
[bili-live][04-22 21:24:46][DEBUG]: connect to blive websocket success 
[bili-live][04-22 21:24:46][INFO]: connected to blive success: 21692711
[bili-live][04-22 21:25:14][DEBUG]: send heart beat to blive... 
[bili-live][04-22 21:25:44][DEBUG]: send heart beat to blive... 

模拟了一个cookie不合法的情况,在发送认证包后会被断开,在再次连接时不会发送认证包

抱歉,忘记启动websocket消息循环了,现在我测试重连是正常的