v0.1: HTTP+SSE broadcast bus + phone web UI + Linux client
Single Go module with two binaries (server, client) and an embedded phone UI. MVP transport is HTTP POST → SSE fanout; the roadmap calls for upgrading to WebRTC P2P with Sign in with Apple for identity, mDNS for discovery, and OS clipboard hooks. - server/: Go HTTP server, embedded index.html, broadcast bus with short replay history, SSE stream endpoint, single-binary deploy. - client/: subscribes to SSE feed and prints messages; -send for one-shot publish from CLI. No OS clipboard touched yet (v0.5). - web/index.html: dark phone-first UI, paste-clipboard button (uses navigator.clipboard.readText), live feed of incoming messages via EventSource. This commit is intentionally tiny — it proves the end-to-end shape so the WebRTC/SiwA/mDNS pieces can be added incrementally without restructuring. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
152
server/web/index.html
Normal file
152
server/web/index.html
Normal file
@@ -0,0 +1,152 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover" />
|
||||
<meta name="theme-color" content="#0a0a0a" />
|
||||
<title>tether</title>
|
||||
<style>
|
||||
:root { color-scheme: dark; }
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; height: 100%; }
|
||||
body {
|
||||
font: 15px -apple-system, "SF Pro Text", system-ui, sans-serif;
|
||||
background: #0a0a0a; color: #e5e5e5;
|
||||
display: flex; flex-direction: column;
|
||||
padding: 18px 16px env(safe-area-inset-bottom);
|
||||
gap: 14px;
|
||||
}
|
||||
header { display: flex; align-items: baseline; gap: 8px; }
|
||||
h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.5px; }
|
||||
.tag { font-size: 11px; color: #888; letter-spacing: 0.5px; text-transform: uppercase; }
|
||||
.row { display: flex; flex-direction: column; gap: 6px; }
|
||||
label { font-size: 11px; color: #888; letter-spacing: 0.4px; text-transform: uppercase; }
|
||||
textarea {
|
||||
width: 100%; min-height: 130px; resize: vertical;
|
||||
font: 15px -apple-system, ui-monospace, "SF Mono", monospace;
|
||||
background: #161616; color: #f5f5f5;
|
||||
border: 1px solid #232323; border-radius: 10px;
|
||||
padding: 12px; outline: none;
|
||||
}
|
||||
textarea:focus { border-color: #3a3a3a; }
|
||||
.actions { display: flex; gap: 8px; }
|
||||
button {
|
||||
flex: 1; padding: 12px 16px; font: 600 14px -apple-system, system-ui, sans-serif;
|
||||
background: #1a1a1a; color: #f5f5f5;
|
||||
border: 1px solid #2a2a2a; border-radius: 10px;
|
||||
cursor: pointer; transition: background 0.15s;
|
||||
}
|
||||
button.primary { background: #4f46e5; border-color: #6366f1; }
|
||||
button.primary:active { background: #4338ca; }
|
||||
button:active { background: #232323; }
|
||||
.status {
|
||||
font-size: 13px; color: #888;
|
||||
padding: 8px 12px; background: #131313;
|
||||
border: 1px solid #1f1f1f; border-radius: 8px;
|
||||
min-height: 38px; display: flex; align-items: center;
|
||||
}
|
||||
.status.ok { color: #4ade80; }
|
||||
.status.err { color: #f87171; }
|
||||
.feed { display: flex; flex-direction: column; gap: 6px; }
|
||||
.feed h2 { font-size: 11px; color: #888; letter-spacing: 0.5px; text-transform: uppercase; margin: 0; }
|
||||
.msg {
|
||||
background: #131313; border: 1px solid #1f1f1f; border-radius: 8px;
|
||||
padding: 10px 12px; font: 13px ui-monospace, "SF Mono", monospace;
|
||||
color: #d4d4d4; white-space: pre-wrap; word-break: break-word;
|
||||
max-height: 200px; overflow: auto;
|
||||
}
|
||||
.meta { font-size: 11px; color: #666; margin-top: 4px; }
|
||||
footer {
|
||||
margin-top: auto; padding-top: 8px;
|
||||
font-size: 11px; color: #555; text-align: center;
|
||||
}
|
||||
footer a { color: #888; text-decoration: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>tether</h1>
|
||||
<span class="tag">phone ↔ laptop</span>
|
||||
</header>
|
||||
|
||||
<div class="row">
|
||||
<label for="out">send to laptop</label>
|
||||
<textarea id="out" placeholder="paste or type something…"></textarea>
|
||||
<div class="actions">
|
||||
<button id="pasteBtn">paste clipboard</button>
|
||||
<button class="primary" id="sendBtn">send →</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status" id="status">idle</div>
|
||||
|
||||
<div class="feed">
|
||||
<h2>received from laptop</h2>
|
||||
<div id="incoming"></div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<a href="https://gitea.pecord.io/pecord/tether">tether on gitea</a> · v0.1
|
||||
</footer>
|
||||
|
||||
<script>
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const status = (msg, cls) => {
|
||||
const s = $("status");
|
||||
s.textContent = msg;
|
||||
s.className = "status" + (cls ? " " + cls : "");
|
||||
};
|
||||
|
||||
$("pasteBtn").addEventListener("click", async () => {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText();
|
||||
$("out").value = text;
|
||||
status("pasted from clipboard", "ok");
|
||||
} catch (e) {
|
||||
status("clipboard read denied — paste manually", "err");
|
||||
}
|
||||
});
|
||||
|
||||
$("sendBtn").addEventListener("click", async () => {
|
||||
const text = $("out").value;
|
||||
if (!text) { status("empty", "err"); return; }
|
||||
status("sending…");
|
||||
try {
|
||||
const r = await fetch("/api/send", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ text }),
|
||||
});
|
||||
if (r.ok) {
|
||||
status("delivered ✓", "ok");
|
||||
} else {
|
||||
status("server returned " + r.status, "err");
|
||||
}
|
||||
} catch (e) {
|
||||
status("network error", "err");
|
||||
}
|
||||
});
|
||||
|
||||
// SSE: receive incoming messages from clients
|
||||
function connectFeed() {
|
||||
const es = new EventSource("/api/stream");
|
||||
es.addEventListener("clipboard", (ev) => {
|
||||
try {
|
||||
const m = JSON.parse(ev.data);
|
||||
const el = document.createElement("div");
|
||||
el.className = "msg";
|
||||
el.textContent = m.text;
|
||||
const meta = document.createElement("div");
|
||||
meta.className = "meta";
|
||||
meta.textContent = (m.source || "client") + " @ " + new Date(m.ts).toLocaleTimeString();
|
||||
el.appendChild(meta);
|
||||
const feed = $("incoming");
|
||||
feed.insertBefore(el, feed.firstChild);
|
||||
} catch (e) {}
|
||||
});
|
||||
es.onerror = () => setTimeout(connectFeed, 2000);
|
||||
}
|
||||
connectFeed();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user