Compare commits

..

No commits in common. "3c2212b951970793bd5786439b6b6df100c5349d" and "94a39fbc9c4212f312894ee940b3e99495fd83ae" have entirely different histories.

7 changed files with 26 additions and 28 deletions

View File

@ -10,7 +10,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -9,17 +9,5 @@ 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 + window.location.search.replace('?','&');
"w=" + initialSize.width + "&h=" + initialSize.height;
var proto = "ws";
if (location.protocol == "https:") {

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0.5</Version>
<Version>1.0.0.1</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.1" />
<PackageReference Include="Tesses.WebServer.WebSocket" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Client.js" />

View File

@ -489,7 +489,6 @@ namespace Ooui
bool disposeElementWhenDone = true;
try {
var context = UIContext.ForListenerContext (listenerContext, variables);
context.QueryParams = listenerContext.QueryParams;
element = elementHandler.GetElement (context);
disposeElementWhenDone = elementHandler.DisposeElementWhenDone;
@ -531,7 +530,7 @@ namespace Ooui
// Create a new session and let it handle everything from here
//
try {
var session = new WebSocketSession (element, disposeElementWhenDone, w, h, Error, serverToken);
var session = new WebSocketSession (this,element, disposeElementWhenDone, w, h, Error, serverToken);
listenerContext.StartWebSocketConnection(session.Opened,
session.Arrived,
session.Closed); }
@ -610,7 +609,6 @@ 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 (Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action<string, Exception> errorLogger, CancellationToken serverToken)
public WebSocketSession (UI ui,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,6 +110,19 @@ 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;
@ -122,6 +135,7 @@ namespace Ooui
sendMsg = arg1;
Init();
}
internal UI ui;
internal void Arrived(WebSocketMessage obj)
{

View File

@ -130,5 +130,3 @@ 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