2017-01-10 20:53:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-01-22 20:56:31 +00:00
|
|
|
|
using System.Text;
|
2017-01-27 21:24:58 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-01-22 20:56:31 +00:00
|
|
|
|
|
|
|
|
|
using IotWeb.Common.Http;
|
2017-01-27 21:24:58 +00:00
|
|
|
|
using SBRL.Utilities;
|
2017-01-22 20:56:31 +00:00
|
|
|
|
|
2017-01-21 18:13:42 +00:00
|
|
|
|
namespace Nibriboard.Client
|
2017-01-10 20:53:50 +00:00
|
|
|
|
{
|
|
|
|
|
public class NibriClient
|
|
|
|
|
{
|
|
|
|
|
private readonly NibriClientManager manager;
|
|
|
|
|
private readonly WebSocket client;
|
|
|
|
|
|
2017-01-27 21:24:58 +00:00
|
|
|
|
private Dictionary<string, Type> messageEventTypes = new Dictionary<string, Type>()
|
|
|
|
|
{
|
2017-01-27 21:25:49 +00:00
|
|
|
|
["handshake"] =
|
2017-01-27 21:24:58 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-01-10 20:53:50 +00:00
|
|
|
|
public NibriClient(NibriClientManager inManager, WebSocket inClient)
|
|
|
|
|
{
|
|
|
|
|
manager = inManager;
|
|
|
|
|
client = inClient;
|
|
|
|
|
|
|
|
|
|
client.DataReceived += async (WebSocket clientSocket, string frame) => {
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-01-27 21:24:58 +00:00
|
|
|
|
await handleMessage(frame);
|
2017-01-10 20:53:50 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception error)
|
|
|
|
|
{
|
|
|
|
|
await Console.Error.WriteLineAsync(error.ToString());
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Task.Run(async () => await onMessage(frame)).Wait();
|
|
|
|
|
};
|
2017-01-19 13:13:35 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-10 20:53:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-22 20:56:31 +00:00
|
|
|
|
public void Send(string message)
|
|
|
|
|
{
|
|
|
|
|
client.Send(Encoding.UTF8.GetBytes(message));
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 21:24:58 +00:00
|
|
|
|
private async Task handleMessage(string frame)
|
2017-01-10 20:53:50 +00:00
|
|
|
|
{
|
2017-01-27 21:24:58 +00:00
|
|
|
|
string eventName = JsonUtilities.DeserializeProperty(frame, "event");
|
|
|
|
|
|
2017-01-10 20:53:50 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|