Ooui-tws-port/README.md

133 lines
5.5 KiB
Markdown
Raw Normal View History

2021-05-13 00:57:29 +00:00
# Ooui Web Framework <img src="https://raw.githubusercontent.com/praeclarum/Ooui/master/Documentation/Icon.png" height="32">
2023-03-17 08:08:32 +00:00
2017-11-29 03:52:24 +00:00
| Version | Package | Description |
| ------- | ------- | ----------- |
2023-03-17 08:08:32 +00:00
| [![NuGet Package](https://img.shields.io/nuget/v/Tesses.WebServer.Ooui.svg)](https://www.nuget.org/packages/Tesses.WebServer.Ooui) | [Ooui](https://www.nuget.org/packages/Ooui) | Core library with HTML elements and a server |
| [![NuGet Package](https://img.shields.io/nuget/v/Tesses.WebServer.Ooui.Forms.svg)](https://www.nuget.org/packages/Tesses.WebServer.Ooui.Forms) | [Ooui.Forms](https://www.nuget.org/packages/Tesses.WebServer.Ooui.Forms) | Xamarin.Forms backend using Ooui for Tesses.WebServer ([Status](Documentation/OouiFormsStatus.md)) |
This is a Tesses.WebServer port of [Ooui](https://github.com/praeclarum/Ooui), this port is GPL3.0 unlike the original
2017-06-14 02:39:36 +00:00
2018-02-07 23:42:45 +00:00
Ooui (pronounced *weee!*) is a small cross-platform UI library for .NET that uses web technologies.
2017-06-13 19:33:06 +00:00
It presents a classic object-oriented UI API that controls a dumb browser. With Ooui, you get the full power of your favorite .NET programming language *plus* the ability to interact with your app using any device.
2017-06-13 19:02:57 +00:00
2017-06-17 00:59:35 +00:00
## Try it Online
2017-11-16 05:51:02 +00:00
Head on over to [http://ooui.mecha.parts](http://ooui.mecha.parts) to tryout the samples.
2017-06-17 00:59:35 +00:00
2018-03-15 01:00:03 +00:00
You can also load [https://s3.amazonaws.com/praeclarum.org/wasm/index.html](https://s3.amazonaws.com/praeclarum.org/wasm/index.html) to try the WebAssembly mode of Ooui running Xamarin.Forms. (That's Xamarin.Forms running right in your browser!)
2018-03-13 04:12:19 +00:00
2017-06-17 00:59:35 +00:00
## Try the Samples Locally
2017-06-16 23:02:38 +00:00
```bash
2023-03-17 08:08:32 +00:00
git clone https://gitlab.tesses.net/tesses50/Ooui-tws-port.git
cd Ooui-tws-port
2017-06-14 01:10:37 +00:00
2019-01-05 18:35:16 +00:00
dotnet run --project Samples/Samples.csproj
2017-06-14 01:10:37 +00:00
```
This will open the default starting page for the Samples. Now point your browser at [http://localhost:8080/shared-button](http://localhost:8080/shared-button)
2017-06-16 23:02:38 +00:00
2018-02-07 23:42:45 +00:00
You should see a button that tracks the number of times it was clicked. The source code for that button is shown in the example below.
2017-06-16 23:02:38 +00:00
2017-06-14 01:10:37 +00:00
2018-02-07 23:42:45 +00:00
## Example App
2017-06-14 01:10:37 +00:00
2017-06-16 23:02:38 +00:00
Here is the complete source code to a fully collaborative button clicking app.
2017-06-13 19:02:57 +00:00
```csharp
2017-06-16 23:02:38 +00:00
using System;
2017-06-13 19:02:57 +00:00
using Ooui;
2023-03-17 08:08:32 +00:00
using Tesses.WebServer;
2017-06-16 23:02:38 +00:00
class Program
{
static void Main(string[] args)
{
2023-03-17 08:08:32 +00:00
//unlike the original UI is an instance that inherits Tesses.WebServer.Server
UI Ui = new Ui();
2017-06-16 23:02:38 +00:00
// Create the UI
var button = new Button("Click me!");
// Add some logic to it
var count = 0;
button.Click += (s, e) => {
2017-06-16 23:02:38 +00:00
count++;
button.Text = $"Clicked {count} times";
};
// Publishing makes an object available at a given URL
// The user should be directed to http://localhost:8080/shared-button
2023-03-17 08:08:32 +00:00
Ui.Publish ("/shared-button", button);
2017-06-16 23:02:38 +00:00
2023-03-17 08:08:32 +00:00
//Listen until someone hits CTRL+C
Ui.StartServer(8080);
2017-06-16 23:02:38 +00:00
}
}
```
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
Make sure to add a reference to Ooui before you start running!
2017-06-13 19:02:57 +00:00
2017-06-16 23:02:38 +00:00
```bash
dotnet add package Ooui
2018-02-07 23:42:45 +00:00
dotnet run
2017-06-13 19:02:57 +00:00
```
2018-02-07 23:42:45 +00:00
With just that code, a web server that serves the HTML and web socket logic necessary for an interactive button will start.
2017-06-13 19:33:06 +00:00
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
## The Many Ways to Ooui
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
Ooui has been broken up into several packages to increase the variety of ways that it can be used. Here are some combinations to help you decide which way is best for you.
2017-06-13 19:02:57 +00:00
<table>
2018-03-14 01:26:56 +00:00
<thead><tr><th>Ooui</th><th>Ooui.AspNetCore</th><th>Ooui.Forms</th><th>Ooui.Wasm</th><th></th></tr></thead>
2017-06-13 19:02:57 +00:00
<tr>
2018-03-14 20:51:30 +00:00
<td>&check;</td><td></td><td></td><td></td><td><a href="https://github.com/praeclarum/Ooui/wiki/Web-DOM-with-the-Built-in-Web-Server">Web DOM with the Built-in Web Server</a></td>
2017-06-13 19:02:57 +00:00
</tr>
2018-03-14 01:26:56 +00:00
<tr>
<td>&check;</td><td>&check;</td><td></td><td></td><td>Web DOM with ASP.NET Core</td>
</tr>
<tr>
<td>&check;</td><td>&check;</td><td>&check;</td><td></td><td>Xamarin.Forms with ASP.NET Core</td>
</tr>
2017-06-13 19:02:57 +00:00
<tr>
2018-03-14 01:26:56 +00:00
<td>&check;</td><td></td><td>&check;</td><td></td><td>Xamarin.Forms with the built-in web server</td>
2017-06-13 19:02:57 +00:00
</tr>
2018-03-14 01:26:56 +00:00
2017-06-13 19:02:57 +00:00
<tr>
2018-03-14 20:51:30 +00:00
<td>&check;</td><td></td><td></td><td>&check;</td><td><a href="https://github.com/praeclarum/Ooui/wiki/Web DOM-with-Web-Assembly">Web DOM with Web Assembly</a></td>
2017-06-13 19:02:57 +00:00
</tr>
2018-03-14 01:26:56 +00:00
2017-06-13 19:02:57 +00:00
<tr>
2018-03-14 20:51:30 +00:00
<td>&check;</td><td></td><td>&check;</td><td>&check;</td><td><a href="https://github.com/praeclarum/Ooui/wiki/Xamarin.Forms-with-Web-Assembly">Xamarin.Forms with Web Assembly</a></td>
2017-06-13 19:02:57 +00:00
</tr>
2018-02-07 23:42:45 +00:00
</table>
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
## How it works
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
When the user requests a page, the page will connect to the server using a web socket. This socket is used to keep the server's in-memory model of the UI (the one you work with as a programmer) in sync with the actual UI shown to the user in their browser. This is done using a simple messaging protocol with JSON packets.
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
When the user clicks or otherwise interacts with the UI, those events are sent back over the web socket so that your code can deal with them.
2017-06-13 19:02:57 +00:00
2018-03-14 01:26:56 +00:00
In the case of web assembly, this same dataflow takes place. However, sockets are not used as all communication is done locally in the browser process.
2017-06-13 19:02:57 +00:00
2018-02-07 23:42:45 +00:00
## Contributing
2017-06-13 19:02:57 +00:00
2023-03-17 08:08:32 +00:00
Ooui is open source and I love merging PRs. Please fork away, and please obey the .editorconfig file. :-) Try to file issues for things that you want to work on *before* you start the work so that there's no duplicated effort. If you just want to help out, check out the issues and dive in!, please contribute to the [original](https://github.com/praeclarum/Ooui) not this port (you can fork this port if you want)
## 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