1
0
Fork 0
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:
Starbeamrainbowlabs 2017-01-22 20:56:31 +00:00
parent 22373b82c7
commit 96c6c8e565
2 changed files with 31 additions and 3 deletions

View file

@ -1,6 +1,9 @@
using System;
using IotWeb.Common.Http;
using System.Threading.Tasks;
using System.Text;
using IotWeb.Common.Http;
namespace Nibriboard.Client
{
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)
{

View file

@ -8,9 +8,17 @@ namespace Nibriboard.Client
{
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)
{
@ -39,5 +47,17 @@ namespace Nibriboard.Client
NibriClient client = new NibriClient(this, newSocket);
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);
}
}
}
}