Added DataWebSocket Events

This commit is contained in:
RogueException
2015-09-15 04:58:01 -03:00
parent 8e534cb5c9
commit 024ef7d1de
4 changed files with 66 additions and 3 deletions

View File

@@ -186,6 +186,9 @@
<Compile Include="..\Discord.Net\Net\WebSockets\DataWebSocket.cs">
<Link>Net\WebSockets\DataWebSocket.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\DataWebSockets.Events.cs">
<Link>Net\DataWebSockets.Events.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\Net\WebSockets\Events.cs">
<Link>Net\WebSockets\Events.cs</Link>
</Compile>

View File

@@ -53,14 +53,17 @@ namespace Discord.Net.WebSockets
{
case 0:
{
if (msg.Type == "READY")
JToken token = msg.Payload as JToken;
if (msg.Type == "READY")
{
var payload = (msg.Payload as JToken).ToObject<Events.Ready>();
var payload = token.ToObject<Events.Ready>();
_lastSession = payload.SessionId;
_heartbeatInterval = payload.HeartbeatInterval;
QueueMessage(new Commands.UpdateStatus());
CompleteConnect();
}
RaiseOnEvent(msg.Type, token);
if (msg.Type == "READY")
CompleteConnect();
if (_logLevel >= LogMessageSeverity.Info)
RaiseOnLog(LogMessageSeverity.Info, "Got Event: " + msg.Type);
}

View File

@@ -0,0 +1,26 @@
using Newtonsoft.Json.Linq;
using System;
namespace Discord.Net.WebSockets
{
public sealed class WebSocketEventEventArgs : EventArgs
{
public readonly string Type;
public readonly JToken Payload;
internal WebSocketEventEventArgs(string type, JToken data)
{
Type = type;
Payload = data;
}
}
internal partial class DataWebSocket
{
public event EventHandler<WebSocketEventEventArgs> OnEvent;
private void RaiseOnEvent(string type, JToken payload)
{
if (OnEvent != null)
OnEvent(this, new WebSocketEventEventArgs(type, payload));
}
}
}