Skip to content

Commit

Permalink
修改触发延迟位置,第三次ping失败时,将延迟设置9999
Browse files Browse the repository at this point in the history
  • Loading branch information
caiyaonan committed Mar 25, 2024
1 parent f9e7aa0 commit cfcb9ab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/connect_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class ConnectManager {
this.heartTimer = setInterval(() => {
self.sendPing(); // 发送心跳包
if (self.pingRetryCount > self.pingMaxRetryCount) {
this.notifyConnectDelayListeners(9999); // 连接超时
console.log('ping没有响应,断开连接。');
self.onlyDisconnect();
if (this.status === ConnectStatus.Disconnect) {
Expand Down Expand Up @@ -256,7 +257,6 @@ export class ConnectManager {
const packetType = header >> 4
if (packetType == PacketType.PONG) {
dataCallback([header])
this.notifyConnectDelayListeners(Date.now()-this.pingTime)
return data.slice(1)
}

Expand Down Expand Up @@ -341,6 +341,7 @@ export class ConnectManager {
this.notifyConnectStatusListeners(connackPacket.reasonCode);
} else if (p.packetType === PacketType.PONG) {
this.pingRetryCount = 0;
this.notifyConnectDelayListeners(Date.now()-this.pingTime)
} else if (p.packetType === PacketType.DISCONNECT) { // 服务器要求客户端断开(一般是账号在其他地方登录,被踢)

const disconnectPacket = (p as DisconnectPacket)
Expand Down

0 comments on commit cfcb9ab

Please sign in to comment.