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:
parent
11a2c846fc
commit
8a5dda1c05
7 changed files with 94 additions and 9 deletions
28
Nibriboard/Client/ClientSettings.cs
Normal file
28
Nibriboard/Client/ClientSettings.cs
Normal 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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
30
Nibriboard/Client/HttpClientSettingsHandler.cs
Normal file
30
Nibriboard/Client/HttpClientSettingsHandler.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ using SBRLUtilities;
|
|||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Nibriboard
|
||||
namespace Nibriboard.Client
|
||||
{
|
||||
public class HttpEmbeddedFileHandler : IHttpRequestHandler
|
||||
{
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using IotWeb.Common.Http;
|
||||
using System.Threading.Tasks;
|
||||
namespace Nibriboard
|
||||
namespace Nibriboard.Client
|
||||
{
|
||||
public class NibriClient
|
||||
{
|
|
@ -3,7 +3,8 @@ using IotWeb.Common.Http;
|
|||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
namespace Nibriboard
|
||||
|
||||
namespace Nibriboard.Client
|
||||
{
|
||||
public class NibriClientManager : IWebSocketRequestHandler
|
||||
{
|
|
@ -60,13 +60,15 @@
|
|||
<Compile Include="RippleSpace\Reference.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="NibriboardServer.cs" />
|
||||
<Compile Include="NibriClient.cs" />
|
||||
<Compile Include="NibriClientManager.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Utilities\EmbeddedFiles.cs" />
|
||||
<Compile Include="Env.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>
|
||||
<EmbeddedResource Include="ClientFiles\index.html" />
|
||||
|
@ -78,10 +80,20 @@
|
|||
<Folder Include="RippleSpace\" />
|
||||
<Folder Include="Utilities\" />
|
||||
<Folder Include="ClientFiles\" />
|
||||
<Folder Include="Client\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="ClientFiles\index.js" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
<MonoDevelop>
|
||||
<Properties>
|
||||
<Policies>
|
||||
<DotNetNamingPolicy DirectoryNamespaceAssociation="Hierarchical" ResourceNamePolicy="FileFormatDefault" />
|
||||
</Policies>
|
||||
</Properties>
|
||||
</MonoDevelop>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using IotWeb.Server;
|
||||
using IotWeb.Common.Http;
|
||||
|
||||
using Nibriboard.RippleSpace;
|
||||
using System.Threading.Tasks;
|
||||
using Nibriboard.Client;
|
||||
|
||||
namespace Nibriboard
|
||||
{
|
||||
|
@ -13,6 +13,7 @@ namespace Nibriboard
|
|||
{
|
||||
private HttpServer httpServer;
|
||||
|
||||
private ClientSettings clientSettings;
|
||||
private RippleSpaceManager planeManager = new RippleSpaceManager();
|
||||
|
||||
public readonly int Port = 31586;
|
||||
|
@ -21,6 +22,13 @@ namespace Nibriboard
|
|||
{
|
||||
Port = inPort;
|
||||
|
||||
clientSettings = new ClientSettings() {
|
||||
WebsocketHost = "localhost",
|
||||
WebsocketPort = Port,
|
||||
WebsocketPath = "/RipplespaceLink"
|
||||
};
|
||||
|
||||
// HTTP Server setup
|
||||
httpServer = new HttpServer(Port);
|
||||
httpServer.AddHttpRequestHandler(
|
||||
"/",
|
||||
|
@ -31,8 +39,14 @@ namespace Nibriboard
|
|||
"index.html"
|
||||
)*/
|
||||
);
|
||||
httpServer.AddHttpRequestHandler(
|
||||
"/Settings.json",
|
||||
new HttpClientSettingsHandler(clientSettings)
|
||||
);
|
||||
|
||||
// Websocket setup
|
||||
httpServer.AddWebSocketRequestHandler(
|
||||
"/RipplespaceConnection",
|
||||
clientSettings.WebsocketPath,
|
||||
new NibriClientManager()
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue