Fixed websocket-sharp logging, reconnect on error

This commit is contained in:
RogueException
2015-10-04 22:14:12 -03:00
parent d7da8d6e21
commit fd8150c9d9
2 changed files with 8 additions and 5 deletions

View File

@@ -2,8 +2,6 @@
using Discord.Helpers;
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WSSharpNWebSocket = WebSocketSharp.WebSocket;
@@ -38,9 +36,14 @@ namespace Discord.WebSockets
_webSocket = new WSSharpNWebSocket(host);
_webSocket.EmitOnPing = false;
_webSocket.EnableRedirection = true;
_webSocket.Compression = WebSocketSharp.CompressionMethod.None;
_webSocket.Compression = WebSocketSharp.CompressionMethod.None;
_webSocket.OnMessage += (s, e) => RaiseProcessMessage(e.Data);
_webSocket.OnError += (s, e) => _parent.RaiseOnLog(LogMessageSeverity.Error, $"Websocket Error: {e.Message}");
_webSocket.OnError += async (s, e) =>
{
_parent.RaiseOnLog(LogMessageSeverity.Error, $"Websocket Error: {e.Message}");
await _parent.DisconnectInternal(e.Exception, true, true);
}
_webSocket.Log.Output = (e, m) => { }; //Dont let websocket-sharp print to console
_webSocket.Connect();
return TaskHelper.CompletedTask;
}

View File

@@ -115,7 +115,7 @@ namespace Discord.WebSockets
}
public Task Disconnect() => DisconnectInternal(new Exception("Disconnect was requested by user."), isUnexpected: false);
protected async Task DisconnectInternal(Exception ex = null, bool isUnexpected = true, bool skipAwait = false)
protected internal async Task DisconnectInternal(Exception ex = null, bool isUnexpected = true, bool skipAwait = false)
{
int oldState;
bool hasWriterLock;