* LCWebSocketConnection.cs: chore: 增加 websocket 日志 id

* LCIMClient.cs: chore: 增加 WebSocket 日志输出 id
oneRain 2020-03-18 16:28:50 +08:00
parent 6781d4e94f
commit ca2c190d3b
2 changed files with 8 additions and 5 deletions

View File

@ -21,11 +21,14 @@ namespace LeanCloud.Realtime.Internal.WebSocket {
private Dictionary<int, TaskCompletionSource<GenericCommand>> responses;
private string id;
internal Action<GenericCommand> OnNotification {
get; set;
}
internal LCWebSocketConnection() {
internal LCWebSocketConnection(string id) {
this.id = id;
responses = new Dictionary<int, TaskCompletionSource<GenericCommand>>();
}
@ -44,11 +47,11 @@ namespace LeanCloud.Realtime.Internal.WebSocket {
TaskCompletionSource<GenericCommand> tcs = new TaskCompletionSource<GenericCommand>();
request.I = RequestI;
responses.Add(request.I, tcs);
LCLogger.Debug($"=> {request.Cmd}/{request.Op}: {request.ToString()}");
LCLogger.Debug($"{id} => {request.Cmd}/{request.Op}: {request.ToString()}");
ArraySegment<byte> bytes = new ArraySegment<byte>(request.ToByteArray());
try {
ws.SendAsync(bytes, WebSocketMessageType.Binary, true, default);
} catch (Exception e) {
} catch (Exception) {
// TODO 发送消息异常
}
@ -80,7 +83,7 @@ namespace LeanCloud.Realtime.Internal.WebSocket {
} while (!result.EndOfMessage);
try {
GenericCommand command = GenericCommand.Parser.ParseFrom(data);
LCLogger.Debug($"<= {command.Cmd}/{command.Op}: {command.ToString()}");
LCLogger.Debug($"{id} <= {command.Cmd}/{command.Op}: {command.ToString()}");
HandleCommand(command);
} catch (Exception e) {
// 解析消息错误

View File

@ -89,7 +89,7 @@ namespace LeanCloud.Realtime {
/// </summary>
/// <returns></returns>
public async Task Open() {
connection = new LCWebSocketConnection {
connection = new LCWebSocketConnection(ClientId) {
OnNotification = OnNotification
};
await connection.Connect();