oneRain 2020-06-23 16:38:18 +08:00
parent 4d9769eeb7
commit d5879d777a
1 changed files with 9 additions and 9 deletions

View File

@ -72,7 +72,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
private State state; private State state;
private Task connectTask; private Task connectTask;
private readonly Dictionary<string, LCIMClient> clients; private readonly Dictionary<string, LCIMClient> idToClients;
internal LCConnection(string id) { internal LCConnection(string id) {
this.id = id; this.id = id;
@ -83,7 +83,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
OnMessage = OnClientMessage, OnMessage = OnClientMessage,
OnClose = OnClientDisconnect OnClose = OnClientDisconnect
}; };
clients = new Dictionary<string, LCIMClient>(); idToClients = new Dictionary<string, LCIMClient>();
state = State.None; state = State.None;
} }
@ -207,7 +207,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
heartBeat.Pong(); heartBeat.Pong();
} else { } else {
// 通知 // 通知
if (clients.TryGetValue(command.PeerId, out LCIMClient client)) { if (idToClients.TryGetValue(command.PeerId, out LCIMClient client)) {
// 通知具体客户端 // 通知具体客户端
client.HandleNotification(command); client.HandleNotification(command);
} }
@ -221,7 +221,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
private void OnClientDisconnect() { private void OnClientDisconnect() {
state = State.Closed; state = State.Closed;
heartBeat.Stop(); heartBeat.Stop();
foreach (LCIMClient client in clients.Values) { foreach (LCIMClient client in idToClients.Values) {
client.HandleDisconnected(); client.HandleDisconnected();
} }
// 重连 // 重连
@ -231,7 +231,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
private void OnPingTimeout() { private void OnPingTimeout() {
state = State.Closed; state = State.Closed;
_ = ws.Close(); _ = ws.Close();
foreach (LCIMClient client in clients.Values) { foreach (LCIMClient client in idToClients.Values) {
client.HandleDisconnected(); client.HandleDisconnected();
} }
// 重连 // 重连
@ -259,7 +259,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
LCLogger.Debug("Reconnected"); LCLogger.Debug("Reconnected");
ws.OnMessage = OnClientMessage; ws.OnMessage = OnClientMessage;
ws.OnClose = OnClientDisconnect; ws.OnClose = OnClientDisconnect;
foreach (LCIMClient client in clients.Values) { foreach (LCIMClient client in idToClients.Values) {
client.HandleReconnected(); client.HandleReconnected();
} }
break; break;
@ -280,12 +280,12 @@ namespace LeanCloud.Realtime.Internal.Connection {
} }
internal void Register(LCIMClient client) { internal void Register(LCIMClient client) {
clients[client.Id] = client; idToClients[client.Id] = client;
} }
internal void UnRegister(LCIMClient client) { internal void UnRegister(LCIMClient client) {
clients.Remove(client.Id); idToClients.Remove(client.Id);
if (clients.Count == 0) { if (idToClients.Count == 0) {
_ = Close(); _ = Close();
} }
} }