Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,19 @@
|
||||
body {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
color: #eee;
|
||||
background-color: #333;
|
||||
background-image: url("v-logo.svg");
|
||||
background-repeat: no-repeat;
|
||||
background-size: 10em;
|
||||
margin: 0;
|
||||
padding-left: 11em;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: #6699CC;
|
||||
}
|
||||
|
||||
img.logo {
|
||||
float: left;
|
||||
width: 10em;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill="#536b8a" d="M 323.509,471.167 480.202,32.185 C 482.857,24.74 478.671,19.312 470.853,20.071 L 347.629,32.03 c -7.816,0.759 -16.259,7.44 -18.841,14.911 L 183.753,466.465 c -2.583,7.47 1.693,13.535 9.546,13.535 h 119.938 c 3.925,0 8.192,-3.02 9.52,-6.744 l 0.746,-2.089 v 0 0 z"/>
|
||||
<path fill="#5d87be" d="M 30.055,20.07 152.165,32.029 c 7.745,0.76 16.122,7.438 18.692,14.905 l 146.766,426.302 c 1.284,3.735 -0.83,6.764 -4.721,6.764 H 193.294 c -7.781,0 -16.239,-6.044 -18.871,-13.489 L 20.791,32.185 c -2.633,-7.445 1.518,-12.874 9.264,-12.114 v 0 0 z"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 671 B |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,38 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>@title</title>
|
||||
<meta charset="utf-8"/>
|
||||
@css 'assets/site.css'
|
||||
</head>
|
||||
<body>
|
||||
<h1>@title</h1>
|
||||
<button>Close the connection</button>
|
||||
<ul></ul>
|
||||
<script>
|
||||
"use strict";
|
||||
var button = document.querySelector('button');
|
||||
var eventList = document.querySelector('ul');
|
||||
const evtSource = new EventSource('/sse');
|
||||
evtSource.onerror = function() { console.log("EventSource failed."); };
|
||||
console.log(evtSource.withCredentials);
|
||||
console.log(evtSource.readyState);
|
||||
console.log(evtSource.url);
|
||||
evtSource.onopen = function() {
|
||||
console.log("Connection to server opened.");
|
||||
};
|
||||
evtSource.onmessage = function(e) {
|
||||
var newElement = document.createElement("li");
|
||||
newElement.textContent = "message: " + e.data;
|
||||
eventList.appendChild(newElement);
|
||||
};
|
||||
evtSource.addEventListener("ping", function(e) {
|
||||
console.log(e)
|
||||
var newElement = document.createElement("li");
|
||||
var obj = JSON.parse(e.data);
|
||||
newElement.innerHTML = "ping at " + obj.time + ' server data: ' + e.data;
|
||||
eventList.appendChild(newElement);
|
||||
}, false);
|
||||
button.onclick = function() { console.log('Connection closed'); evtSource.close(); };
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,46 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import rand
|
||||
import time
|
||||
import veb
|
||||
import veb.sse
|
||||
|
||||
struct App {
|
||||
veb.StaticHandler
|
||||
}
|
||||
|
||||
struct Context {
|
||||
veb.Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut app := &App{}
|
||||
app.serve_static('/favicon.ico', 'favicon.ico')!
|
||||
app.mount_static_folder_at(os.resource_abs_path('.'), '/')!
|
||||
veb.run[App, Context](mut app, 8081)
|
||||
}
|
||||
|
||||
// XTODO template broken (@)
|
||||
pub fn (mut app App) index() veb.Result {
|
||||
title := 'SSE Example'
|
||||
return $veb.html()
|
||||
}
|
||||
|
||||
fn (mut app App) sse() veb.Result {
|
||||
ctx.takeover_conn()
|
||||
spawn handle_sse_conn(mut ctx)
|
||||
return veb.no_result()
|
||||
}
|
||||
|
||||
fn handle_sse_conn(mut ctx Context) {
|
||||
mut session := sse.start_connection(mut ctx.Context)
|
||||
session.send_message(data: 'ok') or { return }
|
||||
for {
|
||||
data := '{"time": "${time.now().str()}", "random_id": "${rand.ulid()}"}'
|
||||
session.send_message(event: 'ping', data: data) or { break }
|
||||
println('> sent event: ${data}')
|
||||
time.sleep(1 * time.second)
|
||||
}
|
||||
session.close()
|
||||
}
|
||||
Reference in new issue
Block a user