* LCConnection.cs:

* LCWebSocketClient.cs:
* LCIMSessionController.cs:
* LCIMConversationController.cs:

* LCIMClient.cs: chore: 实现在重连时如果被踢掉则关闭连接的情况
oneRain 2020-04-14 15:28:01 +08:00
parent bb3baf2ce8
commit f5c56e5a34
5 changed files with 10 additions and 7 deletions

View File

@ -27,7 +27,7 @@ namespace LeanCloud.Realtime.Internal.Connection {
/// <summary>
/// 重连间隔
/// </summary>
private const int RECONNECT_INTERVAL = 5000;
private const int RECONNECT_INTERVAL = 10000;
/// <summary>
/// 心跳间隔

View File

@ -632,9 +632,9 @@ namespace LeanCloud.Realtime.Internal.Controller {
/// <returns></returns>
private async Task OnLeft(ConvCommand convMessage) {
LCIMConversation conversation = await Client.GetOrQueryConversation(convMessage.Cid);
Client.OnKicked?.Invoke(conversation, convMessage.InitBy);
// TODO 从内存中清除对话
Client.OnKicked?.Invoke(conversation, convMessage.InitBy);
}
/// <summary>

View File

@ -37,7 +37,11 @@ namespace LeanCloud.Realtime.Internal.Controller {
GenericCommand request = NewCommand(CommandType.Session, OpType.Open);
request.SessionMessage = session;
GenericCommand response = await Client.Connection.SendRequest(request);
UpdateSession(response.SessionMessage);
if (response.Op == OpType.Opened) {
UpdateSession(response.SessionMessage);
} else if (response.Op == OpType.Closed) {
await OnClosed(response.SessionMessage);
}
}
/// <summary>
@ -119,7 +123,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
string reason = session.Reason;
string detail = session.Detail;
await Connection.Close();
Client.OnClose?.Invoke(code, reason, detail);
Client.OnClose?.Invoke(code, reason);
}
#endregion

View File

@ -120,7 +120,6 @@ namespace LeanCloud.Realtime.Internal.WebSocket {
} catch (Exception e) {
LCLogger.Error(e);
} finally {
// TODO 正常关闭不知道能否完成???
OnDisconnect?.Invoke();
}
}

View File

@ -66,7 +66,7 @@ namespace LeanCloud.Realtime {
/// <summary>
/// 当前客户端被服务端强行下线
/// </summary>
public Action<int, string, string> OnClose {
public Action<int, string> OnClose {
get; set;
}
@ -459,7 +459,7 @@ namespace LeanCloud.Realtime {
LCLogger.Error(e);
await Connection.Close();
// TODO 告知
//OnClose?.Invoke();
OnClose?.Invoke(0, string.Empty);
}
}