37 lines
1005 B
C#
37 lines
1005 B
C#
|
using System;
|
|||
|
using System.Text;
|
|||
|
namespace ln.http.websocket
|
|||
|
{
|
|||
|
public enum WebSocketEventType { OPEN, CLOSE, MESSAGE, ERROR }
|
|||
|
|
|||
|
public class WebSocketEventArgs
|
|||
|
{
|
|||
|
public WebSocketFrame Frame { get; }
|
|||
|
|
|||
|
public WebSocketEventType EventType { get; }
|
|||
|
public byte[] BinaryMessage { get; }
|
|||
|
public String TextMessage => Encoding.UTF8.GetString(BinaryMessage);
|
|||
|
|
|||
|
public bool IsBinary { get; }
|
|||
|
|
|||
|
public String ErrorMessage { get; }
|
|||
|
|
|||
|
public WebSocketEventArgs(WebSocketFrame frame)
|
|||
|
{
|
|||
|
Frame = frame;
|
|||
|
|
|||
|
switch (frame.Opcode)
|
|||
|
{
|
|||
|
case WebSocketOpcode.BINARY:
|
|||
|
case WebSocketOpcode.TEXT:
|
|||
|
IsBinary = (frame.Opcode == WebSocketOpcode.BINARY);
|
|||
|
EventType = WebSocketEventType.MESSAGE;
|
|||
|
BinaryMessage = frame.ApplicationData;
|
|||
|
ErrorMessage = null;
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|