mirror of
https://github.com/xfgryujk/blivechat.git
synced 2025-02-24 10:40:43 +08:00
重连间隔时间可增长,防止一直重连失败时消耗太多资源
This commit is contained in:
parent
be05184777
commit
7e656ebe09
2
blivedm
2
blivedm
@ -1 +1 @@
|
||||
Subproject commit fc98b1a6999d8e35d057b20e3ddb3969759c9375
|
||||
Subproject commit 4351881f2e25374c2a3cfc6cf0c42d1fd23672cd
|
@ -192,7 +192,14 @@ export default class ChatClientOfficialBase {
|
||||
}
|
||||
this.retryCount++
|
||||
console.warn('掉线重连中', this.retryCount)
|
||||
window.setTimeout(this.wsConnect.bind(this), 1000)
|
||||
window.setTimeout(this.wsConnect.bind(this), this.getReconnectInterval())
|
||||
}
|
||||
|
||||
getReconnectInterval() {
|
||||
return Math.min(
|
||||
1000 + ((this.retryCount - 1) * 2000),
|
||||
10 * 1000
|
||||
)
|
||||
}
|
||||
|
||||
onWsMessage(event) {
|
||||
|
@ -59,7 +59,6 @@ export default class ChatClientRelay {
|
||||
}
|
||||
|
||||
onWsOpen() {
|
||||
this.retryCount = 0
|
||||
this.websocket.send(JSON.stringify({
|
||||
cmd: COMMAND_JOIN_ROOM,
|
||||
data: {
|
||||
@ -100,7 +99,14 @@ export default class ChatClientRelay {
|
||||
return
|
||||
}
|
||||
console.warn(`掉线重连中${++this.retryCount}`)
|
||||
window.setTimeout(this.wsConnect.bind(this), 1000)
|
||||
window.setTimeout(this.wsConnect.bind(this), this.getReconnectInterval())
|
||||
}
|
||||
|
||||
getReconnectInterval() {
|
||||
return Math.min(
|
||||
1000 + ((this.retryCount - 1) * 2000),
|
||||
10 * 1000
|
||||
)
|
||||
}
|
||||
|
||||
onWsMessage(event) {
|
||||
@ -190,5 +196,10 @@ export default class ChatClientRelay {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 至少成功处理1条消息
|
||||
if (cmd !== COMMAND_FATAL_ERROR) {
|
||||
this.retryCount = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import api.open_live as api_open_live
|
||||
import blivedm.blivedm as blivedm
|
||||
import blivedm.blivedm.models.open_live as dm_open_models
|
||||
import blivedm.blivedm.models.web as dm_web_models
|
||||
import blivedm.blivedm.utils as dm_utils
|
||||
import config
|
||||
import services.avatar
|
||||
import services.translate
|
||||
@ -115,6 +116,7 @@ class LiveClientManager:
|
||||
|
||||
class WebLiveClient(blivedm.BLiveClient):
|
||||
HEARTBEAT_INTERVAL = 10
|
||||
RECONNECT_POLICY = dm_utils.make_linear_retry_policy(1, 2, 10)
|
||||
|
||||
def __init__(self, room_key: RoomKey):
|
||||
assert room_key.type == RoomKeyType.ROOM_ID
|
||||
@ -124,6 +126,7 @@ class WebLiveClient(blivedm.BLiveClient):
|
||||
session=utils.request.http_session,
|
||||
heartbeat_interval=self.HEARTBEAT_INTERVAL,
|
||||
)
|
||||
self.set_reconnect_policy(self.RECONNECT_POLICY)
|
||||
|
||||
@property
|
||||
def room_key(self):
|
||||
@ -141,6 +144,7 @@ class WebLiveClient(blivedm.BLiveClient):
|
||||
|
||||
class OpenLiveClient(blivedm.OpenLiveClient):
|
||||
HEARTBEAT_INTERVAL = 10
|
||||
RECONNECT_POLICY = dm_utils.make_linear_retry_policy(1, 2, 10)
|
||||
|
||||
def __init__(self, room_key: RoomKey):
|
||||
assert room_key.type == RoomKeyType.AUTH_CODE
|
||||
@ -153,6 +157,7 @@ class OpenLiveClient(blivedm.OpenLiveClient):
|
||||
session=utils.request.http_session,
|
||||
heartbeat_interval=self.HEARTBEAT_INTERVAL,
|
||||
)
|
||||
self.set_reconnect_policy(self.RECONNECT_POLICY)
|
||||
|
||||
@property
|
||||
def room_key(self):
|
||||
|
Loading…
Reference in New Issue
Block a user