1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Send settings file to client.

This commit is contained in:
Starbeamrainbowlabs 2017-01-21 18:13:42 +00:00
parent 11a2c846fc
commit 8a5dda1c05
7 changed files with 94 additions and 9 deletions

View file

@ -0,0 +1,28 @@
using System;
using Newtonsoft.Json;
namespace Nibriboard.Client
{
public class ClientSettings
{
[JsonIgnore]
public bool SecureWebsocket = false;
[JsonIgnore]
public int WebsocketPort;
[JsonIgnore]
public string WebsocketHost = "localhost";
[JsonIgnore]
public string WebsocketPath;
public string WebsocketUri {
get {
return (SecureWebsocket ? "wss" : "ws") + $"://{WebsocketHost}:{WebsocketPort}{WebsocketPath}";
}
}
public ClientSettings()
{
}
}
}

View file

@ -0,0 +1,30 @@
using System;
using IotWeb.Common.Http;
using System.IO;
using Newtonsoft.Json;
namespace Nibriboard.Client
{
public class HttpClientSettingsHandler : IHttpRequestHandler
{
private ClientSettings settings;
public HttpClientSettingsHandler(ClientSettings inSettings)
{
settings = inSettings;
}
public void HandleRequest(string uri, HttpRequest request, HttpResponse response, HttpContext context) {
StreamWriter responseData = new StreamWriter(response.Content) { AutoFlush = true };
string settingsJson = JsonConvert.SerializeObject(settings);
response.ContentLength = settingsJson.Length;
response.Headers.Add("content-type", "application/json");
responseData.Write(settingsJson);
Log.WriteLine("[Http/ClientSettings] Sent settings");
}
}
}

View file

@ -7,7 +7,7 @@ using SBRLUtilities;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
namespace Nibriboard namespace Nibriboard.Client
{ {
public class HttpEmbeddedFileHandler : IHttpRequestHandler public class HttpEmbeddedFileHandler : IHttpRequestHandler
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using IotWeb.Common.Http; using IotWeb.Common.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Nibriboard namespace Nibriboard.Client
{ {
public class NibriClient public class NibriClient
{ {

View file

@ -3,7 +3,8 @@ using IotWeb.Common.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
namespace Nibriboard
namespace Nibriboard.Client
{ {
public class NibriClientManager : IWebSocketRequestHandler public class NibriClientManager : IWebSocketRequestHandler
{ {

View file

@ -60,13 +60,15 @@
<Compile Include="RippleSpace\Reference.cs" /> <Compile Include="RippleSpace\Reference.cs" />
<Compile Include="Utilities.cs" /> <Compile Include="Utilities.cs" />
<Compile Include="NibriboardServer.cs" /> <Compile Include="NibriboardServer.cs" />
<Compile Include="NibriClient.cs" />
<Compile Include="NibriClientManager.cs" />
<Compile Include="Log.cs" /> <Compile Include="Log.cs" />
<Compile Include="Utilities\EmbeddedFiles.cs" /> <Compile Include="Utilities\EmbeddedFiles.cs" />
<Compile Include="Env.cs" /> <Compile Include="Env.cs" />
<Compile Include="RippleSpace\RippleSpaceManager.cs" /> <Compile Include="RippleSpace\RippleSpaceManager.cs" />
<Compile Include="HttpEmbeddedFileHandler.cs" /> <Compile Include="Client\HttpEmbeddedFileHandler.cs" />
<Compile Include="Client\NibriClient.cs" />
<Compile Include="Client\NibriClientManager.cs" />
<Compile Include="Client\ClientSettings.cs" />
<Compile Include="Client\HttpClientSettingsHandler.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="ClientFiles\index.html" /> <EmbeddedResource Include="ClientFiles\index.html" />
@ -78,10 +80,20 @@
<Folder Include="RippleSpace\" /> <Folder Include="RippleSpace\" />
<Folder Include="Utilities\" /> <Folder Include="Utilities\" />
<Folder Include="ClientFiles\" /> <Folder Include="ClientFiles\" />
<Folder Include="Client\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="ClientFiles\index.js" /> <None Include="ClientFiles\index.js" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<DotNetNamingPolicy DirectoryNamespaceAssociation="Hierarchical" ResourceNamePolicy="FileFormatDefault" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project> </Project>

View file

@ -1,11 +1,11 @@
using System; using System;
using System.Reflection; using System.Threading.Tasks;
using IotWeb.Server; using IotWeb.Server;
using IotWeb.Common.Http; using IotWeb.Common.Http;
using Nibriboard.RippleSpace; using Nibriboard.RippleSpace;
using System.Threading.Tasks; using Nibriboard.Client;
namespace Nibriboard namespace Nibriboard
{ {
@ -13,6 +13,7 @@ namespace Nibriboard
{ {
private HttpServer httpServer; private HttpServer httpServer;
private ClientSettings clientSettings;
private RippleSpaceManager planeManager = new RippleSpaceManager(); private RippleSpaceManager planeManager = new RippleSpaceManager();
public readonly int Port = 31586; public readonly int Port = 31586;
@ -21,6 +22,13 @@ namespace Nibriboard
{ {
Port = inPort; Port = inPort;
clientSettings = new ClientSettings() {
WebsocketHost = "localhost",
WebsocketPort = Port,
WebsocketPath = "/RipplespaceLink"
};
// HTTP Server setup
httpServer = new HttpServer(Port); httpServer = new HttpServer(Port);
httpServer.AddHttpRequestHandler( httpServer.AddHttpRequestHandler(
"/", "/",
@ -31,8 +39,14 @@ namespace Nibriboard
"index.html" "index.html"
)*/ )*/
); );
httpServer.AddHttpRequestHandler(
"/Settings.json",
new HttpClientSettingsHandler(clientSettings)
);
// Websocket setup
httpServer.AddWebSocketRequestHandler( httpServer.AddWebSocketRequestHandler(
"/RipplespaceConnection", clientSettings.WebsocketPath,
new NibriClientManager() new NibriClientManager()
); );
} }