-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadmin.html
More file actions
198 lines (177 loc) · 6.15 KB
/
admin.html
File metadata and controls
198 lines (177 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fonstr Relay Admin</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: monospace;
max-width: 600px;
margin: 0 auto;
padding: 20px;
background: #1a1a1a;
color: #0f0;
}
button {
background: #0f0;
color: #000;
border: none;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
font-family: monospace;
font-weight: bold;
}
button:active { background: #090; }
#status {
background: #000;
padding: 15px;
margin: 20px 0;
border: 1px solid #0f0;
min-height: 100px;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
overflow-wrap: break-word;
}
#stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 20px 0;
}
.stat-box {
background: #000;
border: 1px solid #0f0;
padding: 10px;
}
input {
background: #000;
color: #0f0;
border: 1px solid #0f0;
padding: 5px;
width: 100%;
margin: 5px 0;
}
</style>
</head>
<body>
<h1>📡 Fonstr Relay Admin</h1>
<div id="stats">
<div class="stat-box">Status: <span id="ws-status">Disconnected</span></div>
<div class="stat-box">Events: <span id="event-count">0</span></div>
<div class="stat-box">Connections: <span id="conn-count">0</span></div>
<div class="stat-box">Memory: <span id="memory">0MB</span></div>
</div>
<div>
<input type="text" id="relay-url" placeholder="ws://localhost:4444" value="ws://localhost:4444">
<button onclick="connect()">Connect</button>
<button onclick="disconnect()">Disconnect</button>
</div>
<div>
<h3>Test Commands:</h3>
<button onclick="getStats()">Get Stats</button>
<button onclick="testReq()">Test REQ</button>
<button onclick="clearLogs()">Clear Logs</button>
</div>
<div id="status">Ready to connect...</div>
<script>
let ws = null;
let subId = 'admin-' + Math.random().toString(36).substr(2, 9);
function connect() {
const url = document.getElementById('relay-url').value;
if (ws) ws.close();
ws = new WebSocket(url);
ws.onopen = () => {
document.getElementById('ws-status').textContent = 'Connected';
log('Connected to ' + url);
// Subscribe to recent events
ws.send(JSON.stringify(['REQ', subId, {limit: 10}]));
};
ws.onmessage = (e) => {
const msg = JSON.parse(e.data);
if (msg[0] === 'EVENT') {
updateEventCount();
}
log('← ' + e.data);
};
ws.onclose = () => {
document.getElementById('ws-status').textContent = 'Disconnected';
log('Disconnected');
};
ws.onerror = (e) => {
log('Error: ' + e.message);
};
}
function disconnect() {
if (ws) {
ws.send(JSON.stringify(['CLOSE', subId]));
ws.close();
ws = null;
}
}
function getStats() {
if (!ws || ws.readyState !== WebSocket.OPEN) {
log('Not connected');
return;
}
// Request recent events to gauge activity
const statsId = 'stats-' + Date.now();
ws.send(JSON.stringify(['REQ', statsId, {limit: 1000}]));
setTimeout(() => {
ws.send(JSON.stringify(['CLOSE', statsId]));
}, 1000);
}
function testReq() {
if (!ws || ws.readyState !== WebSocket.OPEN) {
log('Not connected');
return;
}
// Test request for recent events
const testId = 'test-' + Date.now();
ws.send(JSON.stringify(['REQ', testId, {
kinds: [0, 1, 3],
limit: 5
}]));
log('→ Sent test REQ for recent events (kinds: 0,1,3, limit: 5)');
// Auto-close after 2 seconds
setTimeout(() => {
if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify(['CLOSE', testId]));
log('→ Closed test subscription');
}
}, 2000);
}
function log(message) {
const status = document.getElementById('status');
const timestamp = new Date().toTimeString().split(' ')[0];
status.textContent = `[${timestamp}] ${message}\n` + status.textContent;
// Keep only last 20 lines
const lines = status.textContent.split('\n');
if (lines.length > 20) {
status.textContent = lines.slice(0, 20).join('\n');
}
}
function clearLogs() {
document.getElementById('status').textContent = 'Logs cleared';
}
let eventCount = 0;
function updateEventCount() {
eventCount++;
document.getElementById('event-count').textContent = eventCount;
}
// Auto-connect if on same host
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
setTimeout(connect, 500);
}
// Update memory estimate
setInterval(() => {
if (performance.memory) {
const mb = (performance.memory.usedJSHeapSize / 1048576).toFixed(1);
document.getElementById('memory').textContent = mb + 'MB';
}
}, 5000);
</script>
</body>
</html>