treesummaryrefslogcommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.zig24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/main.zig b/src/main.zig
index b8a0715..86b83b1 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -20,9 +20,8 @@ fn handle_websocket(alloc: std.mem.Allocator, websocket: *WebSocket) void {
std.debug.print("{} clients\n", .{clients.items.len});
m.unlock();
- const i = clients.items.len;
defer {
- _ = clients.swapRemove(i);
+ for (0..clients.items.len) |i| { if (std.mem.eql(u8, websocket.key, clients.items[i].key)) { _ = clients.swapRemove(i); break; } }
std.debug.print("{} clients\n", .{clients.items.len});
}
@@ -57,27 +56,26 @@ fn handle_request(alloc: std.mem.Allocator, io: Io, stream: Io.net.Stream) void
req.respond(
\\ <!doctype html>
\\ <html><head>
- \\ <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>&#128187;</text></svg>">
+ \\ <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>&#128172;</text></svg>">
\\ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
\\ <meta charset="utf-8">
\\ <style>
\\ :root { color-scheme: light dark; }
- \\ body {
+ \\ html { width: 100%; height: 100%; }
+ \\ body { width: 100%; height: 100%;
\\ margin: 0; padding: 0;
\\ line-height: 1.6;
\\ font-size: 16px;
\\ }
- \\ textarea { width: 100%; height: calc(100% - 40px); }
- \\ input { width: calc(100% - 80px); height: 40px; }
- \\ button { width: 80px; height: 40px; }
+ \\ textarea { width: calc(100% - 8px); height: calc(100% - 60px); }
\\ </style></head><body>
\\ <script>
- \\ const socket = new WebSocket(`wss://${window.location.host}`);
+ \\ const socket = new WebSocket(`ws://${window.location.host}`);
\\ socket.addEventListener("open", (event) => {
\\ tv.value += "Connected!\n";
\\ });
\\ socket.addEventListener("message", (event) => {
- \\ tv.value += `[${new Date().toLocaleString()}] ${event.data}\n`;
+ \\ socket.onmessage = (e) => { tv.value += `[${new Date().toLocaleString()}] ${e.data}\n`; }
\\ });
\\ function Send() {
\\ if (tn.value.length == 0) { window.alert("Please enter a name"); return; }
@@ -85,11 +83,13 @@ fn handle_request(alloc: std.mem.Allocator, io: Io, stream: Io.net.Stream) void
\\ socket.send(`${tn.value}: ${tb.value}`);
\\ tb.value = "";
\\ }
- \\ tb.onkeypress = (e) => if (e.key === "Enter") Send();
+ \\ window.onload = () => {
+ \\ tb.onkeypress = (e) => { if (e.key === "Enter") Send() };
+ \\ }
\\ </script>
\\ <textarea id="tv" readonly></textarea>
- \\ <div><input type="text" id="tn" /><input type="text" id="tb" />
- \\ <button onclick="Send()">Send</button></div>
+ \\ <div><input type="text" id="tn" style="width: 100px; height: 30px;" /><input type="text" id="tb" style="width: calc(100% - 170px); height: 30px;" />
+ \\ <button onclick="Send()" style="width: 50px; height: 30px;">Send</button></div>
\\ </body></html>
, .{ .status = .ok }) catch break;
},