Added DataWebSocket Events
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
26
src/Discord.Net/Net/WebSockets/DataWebSockets.Events.cs
Normal file
26
src/Discord.Net/Net/WebSockets/DataWebSockets.Events.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user