Compare commits
10 Commits
94a39fbc9c
...
3c2212b951
Author | SHA1 | Date |
---|---|---|
Mike Nolan | 3c2212b951 | |
Mike Nolan | 786e20bf3a | |
Mike Nolan | c3ea0b0766 | |
Mike Nolan | d636e7ce2d | |
Mike Nolan | b9034b1f07 | |
Mike Nolan | 90b01d7046 | |
Mike Nolan | 3572f7297d | |
Mike Nolan | 3aa03a719c | |
Mike Nolan | 9308b9495f | |
Mike Nolan | 9aa05b2d15 |
|
@ -1,16 +1,16 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
|
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
@ -9,5 +9,17 @@ btn.Click += (sender,e)=>{
|
||||||
btn.Text = $"Clicked {++i} time(s)";
|
btn.Text = $"Clicked {++i} time(s)";
|
||||||
};
|
};
|
||||||
ui.Publish("/",btn);
|
ui.Publish("/",btn);
|
||||||
|
ui.Publish("/query",(ctx)=>{
|
||||||
|
Ooui.List list=new List();
|
||||||
|
foreach(var item in ctx.QueryParams)
|
||||||
|
{
|
||||||
|
foreach(var v in item.Value)
|
||||||
|
{
|
||||||
|
Ooui.ListItem listItem=new ListItem();
|
||||||
|
listItem.Text = $"{item.Key}: {v}";
|
||||||
|
list.AppendChild(listItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
});
|
||||||
ui.StartServer(45252);
|
ui.StartServer(45252);
|
|
@ -125,7 +125,7 @@ function connectWebSocket() {
|
||||||
saveSize (initialSize);
|
saveSize (initialSize);
|
||||||
|
|
||||||
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
|
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
|
||||||
"w=" + initialSize.width + "&h=" + initialSize.height;
|
"w=" + initialSize.width + "&h=" + initialSize.height + window.location.search.replace('?','&');
|
||||||
|
|
||||||
var proto = "ws";
|
var proto = "ws";
|
||||||
if (location.protocol == "https:") {
|
if (location.protocol == "https:") {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.0.0.1</Version>
|
<Version>1.0.0.5</Version>
|
||||||
<Description>A tesses webserver port of https://github.com/praeclarum/Ooui</Description>
|
<Description>A tesses webserver port of https://github.com/praeclarum/Ooui</Description>
|
||||||
<PackageTags>Ooui;UI;CrossPlatform</PackageTags>
|
<PackageTags>Ooui;UI;CrossPlatform</PackageTags>
|
||||||
<PackageIcon>Icon.png</PackageIcon>
|
<PackageIcon>Icon.png</PackageIcon>
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
<PackageReference Include="Tesses.WebServer" Version="1.0.4" />
|
<PackageReference Include="Tesses.WebServer" Version="1.0.4" />
|
||||||
<PackageReference Include="Tesses.WebServer.WebSocket" Version="1.0.1" />
|
<PackageReference Include="Tesses.WebServer.WebSocket" Version="1.0.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Client.js" />
|
<EmbeddedResource Include="Client.js" />
|
||||||
|
|
|
@ -489,6 +489,7 @@ namespace Ooui
|
||||||
bool disposeElementWhenDone = true;
|
bool disposeElementWhenDone = true;
|
||||||
try {
|
try {
|
||||||
var context = UIContext.ForListenerContext (listenerContext, variables);
|
var context = UIContext.ForListenerContext (listenerContext, variables);
|
||||||
|
context.QueryParams = listenerContext.QueryParams;
|
||||||
element = elementHandler.GetElement (context);
|
element = elementHandler.GetElement (context);
|
||||||
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
|
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
|
||||||
|
|
||||||
|
@ -530,7 +531,7 @@ namespace Ooui
|
||||||
// Create a new session and let it handle everything from here
|
// Create a new session and let it handle everything from here
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
var session = new WebSocketSession (this,element, disposeElementWhenDone, w, h, Error, serverToken);
|
var session = new WebSocketSession (element, disposeElementWhenDone, w, h, Error, serverToken);
|
||||||
listenerContext.StartWebSocketConnection(session.Opened,
|
listenerContext.StartWebSocketConnection(session.Opened,
|
||||||
session.Arrived,
|
session.Arrived,
|
||||||
session.Closed); }
|
session.Closed); }
|
||||||
|
@ -609,6 +610,7 @@ namespace Ooui
|
||||||
|
|
||||||
public class UIContext
|
public class UIContext
|
||||||
{
|
{
|
||||||
|
public Dictionary<string,List<string>> QueryParams {get;set;}=new Dictionary<string, List<string>>();
|
||||||
readonly Dictionary<string, string> variables = new Dictionary<string, string> ();
|
readonly Dictionary<string, string> variables = new Dictionary<string, string> ();
|
||||||
|
|
||||||
public string RequestUrl { get; }
|
public string RequestUrl { get; }
|
||||||
|
|
|
@ -24,11 +24,11 @@ namespace Ooui
|
||||||
DateTime lastTransmitTime = DateTime.MinValue;
|
DateTime lastTransmitTime = DateTime.MinValue;
|
||||||
readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps);
|
readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps);
|
||||||
|
|
||||||
public WebSocketSession (UI ui,Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action<string, Exception> errorLogger, CancellationToken serverToken)
|
public WebSocketSession (Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action<string, Exception> errorLogger, CancellationToken serverToken)
|
||||||
: base (element, disposeElementAfterSession, initialWidth, initialHeight, errorLogger)
|
: base (element, disposeElementAfterSession, initialWidth, initialHeight, errorLogger)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.ui = ui;
|
|
||||||
//
|
//
|
||||||
// Create a new session cancellation token that will trigger
|
// Create a new session cancellation token that will trigger
|
||||||
// automatically if the server shutsdown or the session shutsdown.
|
// automatically if the server shutsdown or the session shutsdown.
|
||||||
|
@ -110,19 +110,6 @@ namespace Ooui
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( System.AggregateException ex)
|
|
||||||
{
|
|
||||||
if(ex.ToString().Replace(" ","").ToLower().Contains("mutexisnotowned"))
|
|
||||||
{
|
|
||||||
if(ui.Verbose)
|
|
||||||
Console.WriteLine("Mutex is not owned error, continue going");
|
|
||||||
}else{
|
|
||||||
Error ("Failed to send queued messages, aborting session", ex);
|
|
||||||
element.MessageSent -= handleElementMessageSent;
|
|
||||||
sessionCts.Cancel ();
|
|
||||||
}
|
|
||||||
_=ex;
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Error ("Failed to send queued messages, aborting session", ex);
|
Error ("Failed to send queued messages, aborting session", ex);
|
||||||
element.MessageSent -= handleElementMessageSent;
|
element.MessageSent -= handleElementMessageSent;
|
||||||
|
@ -135,7 +122,6 @@ namespace Ooui
|
||||||
sendMsg = arg1;
|
sendMsg = arg1;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
internal UI ui;
|
|
||||||
|
|
||||||
internal void Arrived(WebSocketMessage obj)
|
internal void Arrived(WebSocketMessage obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,3 +130,5 @@ Ooui is open source and I love merging PRs. Please fork away, and please obey th
|
||||||
|
|
||||||
## Why I ported this library to Tesses.WebServer
|
## Why I ported this library to Tesses.WebServer
|
||||||
Well so this would work on mono (mono to my knowledge doesn't support System.Net.WebSockets) and I would like to integrate this library into my webserver
|
Well so this would work on mono (mono to my knowledge doesn't support System.Net.WebSockets) and I would like to integrate this library into my webserver
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue