diff --git a/Nibriboard/Log.cs b/Nibriboard/Log.cs index 95ec04c..b3f7d69 100644 --- a/Nibriboard/Log.cs +++ b/Nibriboard/Log.cs @@ -1,10 +1,13 @@ using System; namespace Nibriboard { - public class Log + public static class Log { - public Log() + public static int WriteLine(string text, params object[] args) { + string outputText = $"[{DateTime.Now}] " + string.Format(text, args); + Console.WriteLine(outputText); + return outputText.Length; } } } diff --git a/Nibriboard/NibriWebSocketClient.cs b/Nibriboard/NibriWebSocketClient.cs index af3a78d..918e52d 100644 --- a/Nibriboard/NibriWebSocketClient.cs +++ b/Nibriboard/NibriWebSocketClient.cs @@ -1,10 +1,47 @@ using System; +using IotWeb.Common.Http; +using System.Threading.Tasks; namespace Nibriboard { - public class NibriWebSocketClient + public class NibriWebSocketClient : IWebSocketRequestHandler { + WebSocket client; + public NibriWebSocketClient() { } + + public void Connected(WebSocket socket) + { + client = socket; + client.DataReceived += async (WebSocket clientSocket, string frame) => { + try { + await onMessage(frame); + } + catch(Exception error) { + await Console.Error.WriteLineAsync(error); + throw; + } + + //Task.Run(async () => await onMessage(frame)).Wait(); + }; + } + + /// + /// Whether we will accept the WebSocket connection or not. + /// + /// The uri the user connected to. + /// The protocol the user is connecting with. + /// Whether we want to accept the WebSocket connection attempt or not. + public bool WillAcceptRequest(string uri, string protocol) + { + Log.WriteLine("[Nibriboard/Websocket] Accepting {0} via {1}.", uri, protocol); + return true; + } + + private async Task onMessage(string frame) + { + + } } } diff --git a/Nibriboard/Nibriboard.csproj b/Nibriboard/Nibriboard.csproj index ba28bc5..b6473f0 100644 --- a/Nibriboard/Nibriboard.csproj +++ b/Nibriboard/Nibriboard.csproj @@ -24,7 +24,7 @@ BeforeBuild npm run build - ${ProjectDir}\Client + ${ProjectDir}/Client @@ -56,7 +56,9 @@ - + + + diff --git a/Nibriboard/NibriboardServer.cs b/Nibriboard/NibriboardServer.cs index 7aea3dd..cac7a3f 100644 --- a/Nibriboard/NibriboardServer.cs +++ b/Nibriboard/NibriboardServer.cs @@ -2,15 +2,16 @@ using System.Reflection; using IotWeb.Server; using IotWeb.Common.Http; +using System.Net; namespace Nibriboard { - public class Nibriboard + public class NibriboardServer { private HttpServer httpServer; public readonly int Port = 31586; - public Nibriboard() + public NibriboardServer() { } @@ -22,10 +23,20 @@ namespace Nibriboard new HttpResourceHandler( Assembly.GetExecutingAssembly(), "Nibriboard", - "index.hmtl" + "index.html" ) ); + httpServer.AddWebSocketRequestHandler( + "/RipplespaceConnection", + + ); httpServer.Start(); + Log.WriteLine("[NibriboardServer] Started on port {0}", Port); + } + + private void Test() + { + HttpListener. } } } diff --git a/Nibriboard/RippleSpace/Chunk.cs b/Nibriboard/RippleSpace/Chunk.cs index f3f0a0b..a248ef9 100644 --- a/Nibriboard/RippleSpace/Chunk.cs +++ b/Nibriboard/RippleSpace/Chunk.cs @@ -8,7 +8,7 @@ using System.Runtime.Serialization; namespace Nibriboard.RippleSpace { /// - /// Represents a single chunk of an infinite . + /// Represents a single chunk of an infinite . /// [Serializable] public class Chunk : IEnumerable, IDeserializationCallback diff --git a/Nibriboard/RippleSpace/ChunkReference.cs b/Nibriboard/RippleSpace/ChunkReference.cs index 14e386d..b1d54d6 100644 --- a/Nibriboard/RippleSpace/ChunkReference.cs +++ b/Nibriboard/RippleSpace/ChunkReference.cs @@ -8,7 +8,7 @@ namespace Nibriboard.RippleSpace /// /// /// Defaults to chunk-space, but absolute plane-space can also be calculated - /// and obtained (A + /// and obtained (A /// is returned). /// public class ChunkReference : Reference diff --git a/Nibriboard/RippleSpace/DrawnLine.cs b/Nibriboard/RippleSpace/DrawnLine.cs index 6a34efe..5c2a5a5 100644 --- a/Nibriboard/RippleSpace/DrawnLine.cs +++ b/Nibriboard/RippleSpace/DrawnLine.cs @@ -9,7 +9,7 @@ namespace Nibriboard.RippleSpace public class DrawnLine { /// - /// The id of line that this is part of. + /// The id of line that this is part of. /// Note that this id may not be unique - several lines that were all /// drawn at once may also have the same id. This is such that a single /// line that was split across multiple chunks can still be referenced.