Files
marqdo/examples/web-net-site/public/live.js
T
cflmyandCursor 7645dd4c1f Extend network stack: session/auth, WebSocket, cookie/multipart primitives
Add the network-extension wave to lib/net and the web ABI plugin:
- lib/net cookie_parse / multipart_parse host primitives (EN/ZH)
- plugins/web session store + /admin login gate + WebSocket client/server
- ext/web author surface (EN/ZH) for session, auth, ws
- form update flow and page-level validation echo tests
- fix string escapes: \xHH, \u{...}, unknown escapes kept verbatim
- map Chinese component slots (导航/侧栏/页脚) so sidebar renders
- resolve relative static/db paths against the entry script dir (entry_dir)
- new tutorial chapter 14, EN/ZH example sites, and gold tests

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-25 14:58:46 +08:00

41 lines
1.2 KiB
JavaScript

// Live widget for the /live WebSocket endpoint.
// Connects to ws://host/live, sends the input, shows the echo.
(function () {
var out = document.getElementById("live-out");
var input = document.getElementById("live-msg");
var btn = document.getElementById("live-send");
var status = document.getElementById("live-status");
if (!out || !input || !btn || !status) return;
var proto = location.protocol === "https:" ? "wss" : "ws";
var ws = new WebSocket(proto + "://" + location.host + "/live");
status.textContent = "connecting…";
ws.onopen = function () {
status.textContent = "connected";
btn.disabled = false;
};
ws.onmessage = function (ev) {
var p = document.createElement("p");
p.textContent = "echo: " + ev.data;
out.appendChild(p);
out.scrollTop = out.scrollHeight;
};
ws.onclose = function () {
status.textContent = "closed";
btn.disabled = true;
};
ws.onerror = function () {
status.textContent = "error";
btn.disabled = true;
};
btn.onclick = function () {
var m = input.value.trim();
if (m) ws.send(m);
};
input.addEventListener("keydown", function (e) {
if (e.key === "Enter") btn.onclick();
});
})();