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 Discord.Helpers;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using WSSharpNWebSocket = WebSocketSharp.WebSocket; using WSSharpNWebSocket = WebSocketSharp.WebSocket;
@@ -38,9 +36,14 @@ namespace Discord.WebSockets
_webSocket = new WSSharpNWebSocket(host); _webSocket = new WSSharpNWebSocket(host);
_webSocket.EmitOnPing = false; _webSocket.EmitOnPing = false;
_webSocket.EnableRedirection = true; _webSocket.EnableRedirection = true;
_webSocket.Compression = WebSocketSharp.CompressionMethod.None; _webSocket.Compression = WebSocketSharp.CompressionMethod.None;
_webSocket.OnMessage += (s, e) => RaiseProcessMessage(e.Data); _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(); _webSocket.Connect();
return TaskHelper.CompletedTask; 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); 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; int oldState;
bool hasWriterLock; bool hasWriterLock;