From c358fd4de9263a95c1e7a583b759e6961c16b53e Mon Sep 17 00:00:00 2001 From: oneRain Date: Wed, 24 Jun 2020 12:21:16 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=AE=80=E5=8C=96=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Internal/Connection/LCConnection.cs | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Realtime/Realtime/Internal/Connection/LCConnection.cs b/Realtime/Realtime/Internal/Connection/LCConnection.cs index db350b7..40312d7 100644 --- a/Realtime/Realtime/Internal/Connection/LCConnection.cs +++ b/Realtime/Realtime/Internal/Connection/LCConnection.cs @@ -77,11 +77,11 @@ namespace LeanCloud.Realtime.Internal.Connection { internal LCConnection(string id) { this.id = id; responses = new Dictionary>(); - heartBeat = new LCHeartBeat(this, OnPingTimeout); + heartBeat = new LCHeartBeat(this, OnDisconnect); router = new LCRTMRouter(); ws = new LCWebSocketClient { - OnMessage = OnClientMessage, - OnClose = OnClientDisconnect + OnMessage = OnMessage, + OnClose = OnDisconnect }; idToClients = new Dictionary(); state = State.None; @@ -168,7 +168,7 @@ namespace LeanCloud.Realtime.Internal.Connection { /// 消息接收回调 /// /// - private void OnClientMessage(byte[] bytes) { + private void OnMessage(byte[] bytes) { try { GenericCommand command = GenericCommand.Parser.ParseFrom(bytes); LCLogger.Debug($"{id} <= {FormatCommand(command)}"); @@ -212,15 +212,7 @@ namespace LeanCloud.Realtime.Internal.Connection { /// /// 连接断开回调 /// - private void OnClientDisconnect() { - Disconnect(); - _ = Reconnect(); - } - - /// - /// Pong 超时回调 - /// - private void OnPingTimeout() { + private void OnDisconnect() { Disconnect(); _ = Reconnect(); } @@ -232,11 +224,11 @@ namespace LeanCloud.Realtime.Internal.Connection { internal void Reset() { Disconnect(); // 重新创建连接组件 - heartBeat = new LCHeartBeat(this, OnPingTimeout); + heartBeat = new LCHeartBeat(this, OnDisconnect); router = new LCRTMRouter(); ws = new LCWebSocketClient { - OnMessage = OnClientMessage, - OnClose = OnClientDisconnect + OnMessage = OnMessage, + OnClose = OnDisconnect }; _ = Reconnect(); } @@ -260,8 +252,8 @@ namespace LeanCloud.Realtime.Internal.Connection { if (reconnectCount < MAX_RECONNECT_TIMES) { // 重连成功 LCLogger.Debug("Reconnected"); - ws.OnMessage = OnClientMessage; - ws.OnClose = OnClientDisconnect; + ws.OnMessage = OnMessage; + ws.OnClose = OnDisconnect; foreach (LCIMClient client in idToClients.Values) { client.HandleReconnected(); }