mirror of
https://github.com/sbrl/Nibriboard.git
synced 2018-01-10 21:33:49 +00:00
Add Send & Broadcast methods to Websocket handling logic
This commit is contained in:
parent
22373b82c7
commit
96c6c8e565
2 changed files with 31 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using IotWeb.Common.Http;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
using IotWeb.Common.Http;
|
||||||
|
|
||||||
namespace Nibriboard.Client
|
namespace Nibriboard.Client
|
||||||
{
|
{
|
||||||
public class NibriClient
|
public class NibriClient
|
||||||
|
@ -30,6 +33,11 @@ namespace Nibriboard.Client
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Send(string message)
|
||||||
|
{
|
||||||
|
client.Send(Encoding.UTF8.GetBytes(message));
|
||||||
|
}
|
||||||
|
|
||||||
private async Task onMessage(string frame)
|
private async Task onMessage(string frame)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,17 @@ namespace Nibriboard.Client
|
||||||
{
|
{
|
||||||
public class NibriClientManager : IWebSocketRequestHandler
|
public class NibriClientManager : IWebSocketRequestHandler
|
||||||
{
|
{
|
||||||
ClientSettings clientSettings;
|
private ClientSettings clientSettings;
|
||||||
|
private List<NibriClient> clients = new List<NibriClient>();
|
||||||
|
|
||||||
List<NibriClient> clients = new List<NibriClient>();
|
/// <summary>
|
||||||
|
/// The number of clients currently connected to this Nibriboard.
|
||||||
|
/// </summary>
|
||||||
|
public int ClientCount {
|
||||||
|
get {
|
||||||
|
return clients.Count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public NibriClientManager(ClientSettings inClientSettings)
|
public NibriClientManager(ClientSettings inClientSettings)
|
||||||
{
|
{
|
||||||
|
@ -39,5 +47,17 @@ namespace Nibriboard.Client
|
||||||
NibriClient client = new NibriClient(this, newSocket);
|
NibriClient client = new NibriClient(this, newSocket);
|
||||||
clients.Add(client);
|
clients.Add(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Broadcast(NibriClient sendingClient, string message)
|
||||||
|
{
|
||||||
|
foreach(NibriClient client in clients)
|
||||||
|
{
|
||||||
|
// Don't send the message to the sender
|
||||||
|
if (client == sendingClient)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
client.Send(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue