2017-01-10 19:51:49 +00:00
|
|
|
|
using System;
|
2017-01-10 19:52:27 +00:00
|
|
|
|
using IotWeb.Common.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-01-10 19:51:49 +00:00
|
|
|
|
namespace Nibriboard
|
|
|
|
|
{
|
2017-01-10 20:36:03 +00:00
|
|
|
|
public class NibriWebSocketHandler : IWebSocketRequestHandler
|
2017-01-10 19:51:49 +00:00
|
|
|
|
{
|
2017-01-10 20:36:03 +00:00
|
|
|
|
public NibriWebSocketHandler()
|
2017-01-10 19:51:49 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2017-01-10 19:52:27 +00:00
|
|
|
|
|
2017-01-10 20:36:03 +00:00
|
|
|
|
public void Connected(WebSocket client)
|
2017-01-10 19:52:27 +00:00
|
|
|
|
{
|
2017-01-10 20:36:03 +00:00
|
|
|
|
|
|
|
|
|
/*client.DataReceived += async (WebSocket clientSocket, string frame) => {
|
2017-01-10 19:52:27 +00:00
|
|
|
|
try {
|
|
|
|
|
await onMessage(frame);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception error) {
|
|
|
|
|
await Console.Error.WriteLineAsync(error);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Task.Run(async () => await onMessage(frame)).Wait();
|
2017-01-10 20:36:03 +00:00
|
|
|
|
};*/
|
2017-01-10 19:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether we will accept the WebSocket connection or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uri">The uri the user connected to.</param>
|
|
|
|
|
/// <param name="protocol">The protocol the user is connecting with.</param>
|
|
|
|
|
/// <returns>Whether we want to accept the WebSocket connection attempt or not.</returns>
|
|
|
|
|
public bool WillAcceptRequest(string uri, string protocol)
|
|
|
|
|
{
|
|
|
|
|
Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-01-10 19:51:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|