Compare commits

...

10 Commits

7 changed files with 28 additions and 26 deletions

View File

@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Ooui\Ooui.csproj" />
<ItemGroup>
<ProjectReference Include="..\Ooui\Ooui.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
<ItemGroup>
<PackageReference Include="Tesses.WebServer.EasyServer" Version="1.0.1" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -9,5 +9,17 @@ btn.Click += (sender,e)=>{
btn.Text = $"Clicked {++i} time(s)";
};
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);

View File

@ -125,7 +125,7 @@ function connectWebSocket() {
saveSize (initialSize);
var wsArgs = (rootElementPath.indexOf("?") >= 0 ? "&" : "?") +
"w=" + initialSize.width + "&h=" + initialSize.height;
"w=" + initialSize.width + "&h=" + initialSize.height + window.location.search.replace('?','&');
var proto = "ws";
if (location.protocol == "https:") {

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<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>
<PackageTags>Ooui;UI;CrossPlatform</PackageTags>
<PackageIcon>Icon.png</PackageIcon>
@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<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>
<EmbeddedResource Include="Client.js" />

View File

@ -489,6 +489,7 @@ namespace Ooui
bool disposeElementWhenDone = true;
try {
var context = UIContext.ForListenerContext (listenerContext, variables);
context.QueryParams = listenerContext.QueryParams;
element = elementHandler.GetElement (context);
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
@ -530,7 +531,7 @@ namespace Ooui
// Create a new session and let it handle everything from here
//
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,
session.Arrived,
session.Closed); }
@ -609,6 +610,7 @@ namespace Ooui
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> ();
public string RequestUrl { get; }

View File

@ -24,11 +24,11 @@ namespace Ooui
DateTime lastTransmitTime = DateTime.MinValue;
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)
{
this.ui = ui;
//
// Create a new session cancellation token that will trigger
// 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) {
Error ("Failed to send queued messages, aborting session", ex);
element.MessageSent -= handleElementMessageSent;
@ -135,7 +122,6 @@ namespace Ooui
sendMsg = arg1;
Init();
}
internal UI ui;
internal void Arrived(WebSocketMessage obj)
{

View File

@ -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
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