-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
420 lines (374 loc) · 15.7 KB
/
index.html
File metadata and controls
420 lines (374 loc) · 15.7 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>AIMless • P2P encrypted chat in a single file (HOSTED DEMO)</title>
<style>
/* ---------------------------
🎛️ Old‑School AIM Skin
--------------------------- */
:root{
/* Win98/AIM-ish palette */
--win-bg:#cfcfd4; /* app chrome */
--win-panel:#ececf1; /* panel face */
--win-edge:#ffffff; /* top/left light edge */
--win-shadow:#9b9ca3; /* bottom/right dark edge */
--title-start:#2a63b7; /* blue titlebar gradient start */
--title-end:#144a95; /* blue titlebar gradient end */
--ink:#0b0b0f; /* primary text */
--muted:#3b3b45; /* secondary text */
--accent:#ffdb00; /* AIM yellow */
--online:#1db954; /* online green dot */
--away:#f59e0b; /* away amber */
--danger:#e11d48; /* red */
}
*{box-sizing:border-box}
html,body{height:100%}
body{
margin:0;
background:var(--win-bg);
font:13px/1.4 Tahoma, Verdana, Segoe UI, sans-serif;
color:var(--ink);
display:flex;
justify-content:center;
padding:10px;
}
/* Window chrome */
.window{
width:100%;
max-width:980px;
background:var(--win-panel);
border:1px solid var(--win-shadow);
box-shadow:0 0 0 1px var(--win-edge) inset;
}
.titlebar{
display:flex;align-items:center;gap:8px;
padding:6px 8px;
color:#fff;
background:linear-gradient(180deg,var(--title-start),var(--title-end));
border-bottom:1px solid #0f336d;
user-select:none;
}
.titlebar .icon{width:16px;height:16px;flex:0 0 16px}
.titlebar .title{font-weight:700;letter-spacing:.2px}
.titlebar .spacer{flex:1}
.titlebar .winbtns{display:flex;gap:4px}
.winbtn{width:16px;height:16px;background:#c0c0c0;border:1px solid #6e6e6e;box-shadow:0 0 0 1px #fff inset;display:grid;place-items:center;cursor:pointer}
/* Layout: Buddy list left, chat right */
.content{display:grid;grid-template-columns:260px 1fr;gap:0}
.pane{border-right:1px solid var(--win-shadow)}
.pane:last-child{border-right:none}
.section{padding:10px;border-bottom:1px solid var(--win-shadow);background:var(--win-panel)}
.label{font-weight:700;color:#1a1a24;margin-bottom:6px}
/* Buddy List */
.buddy-search{display:flex;gap:6px}
input[type="text"], textarea{width:100%;background:#fff;border:1px solid #9b9ca3;box-shadow:0 0 0 1px #fff inset;padding:6px;border-radius:0;font:13px Tahoma, Verdana, sans-serif;color:var(--ink)}
textarea{resize:vertical}
.buddies{max-height:220px;overflow:auto;background:#fff;border:1px solid #9b9ca3;box-shadow:0 0 0 1px #fff inset;padding:6px}
.buddy{display:flex;align-items:center;gap:8px;padding:4px;cursor:default;border-radius:2px}
.buddy:hover{background:#e9eef9}
.dot{width:8px;height:8px;border-radius:50%}
.dot.online{background:var(--online);box-shadow:0 0 0 1px #0d5b2a}
.dot.away{background:var(--away);box-shadow:0 0 0 1px #7a4c05}
.sn{font-weight:700}
/* Connection / Sign-On box */
.signon{background:#fff;border:1px solid #9b9ca3;box-shadow:0 0 0 1px #fff inset;padding:8px}
.row{display:flex;gap:6px;align-items:center;flex-wrap:wrap}
.rb{display:flex;gap:8px;align-items:center}
.pill{display:inline-block;padding:2px 8px;border-radius:20px;background:#e6e6eb;color:#333;border:1px solid #c6c6cc;font-size:12px}
.pill.ok{background:#daf5e6;border-color:#b7e5c8}
.pill.warn{background:#fff6d8;border-color:#ffe9a8}
.pill.bad{background:#fde2e2;border-color:#f7b4b4}
.btn{background:#e1e1e6;border:1px solid #8a8a95;box-shadow:0 0 0 1px #fff inset;padding:6px 10px;border-radius:2px;cursor:pointer;font-weight:700}
.btn:active{box-shadow:0 0 0 1px #dcdce2 inset}
.btn.primary{background:var(--accent);border-color:#a88c00}
.btn.danger{background:#ffd5d9;border-color:#a33b52}
/* Chat area */
.chat-wrap{display:grid;grid-template-rows:auto 1fr auto}
.header{display:flex;align-items:center;gap:8px;padding:8px;border-bottom:1px solid var(--win-shadow)}
.screenname{font-weight:700}
.chatbox{background:#fff;border:1px solid #9b9ca3;box-shadow:0 0 0 1px #fff inset;height:360px;overflow:auto;padding:8px;font:13px/1.5 "MS Sans Serif", Tahoma, Verdana, sans-serif}
.line{margin:2px 0;white-space:pre-wrap}
.time{color:#6b7280}
.me .text{color:#003399}
.peer .text{color:#000}
.inputbar{display:grid;grid-template-columns:1fr auto;gap:6px;margin-top:8px}
/* Hidden advanced box for the Base64 blobs */
details.config{margin-top:8px}
details.config > summary{cursor:pointer;font-weight:700}
.status{margin-left:6px;color:#555}
/* Little AIM running man (inline SVG) */
.run svg{display:block}
</style>
</head>
<body>
<div class="window" role="application" aria-label="AIMless – Old‑School AIM Skin">
<div class="titlebar">
<span class="icon run" aria-hidden="true">
<!-- Simple AIM-inspired running man -->
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="16" cy="5" r="3" fill="#ffdb00" stroke="#000" stroke-width=".6"/>
<path d="M7 20l3-6 3 2 2 4" stroke="#000" stroke-width="1.2" stroke-linecap="round"/>
<path d="M9 12l4-4 4 2" stroke="#000" stroke-width="1.2" stroke-linecap="round"/>
</svg>
</span>
<div class="title">AIMless – Instant Messenger</div>
<div class="spacer"></div>
<div class="winbtns" aria-hidden="true">
<div class="winbtn" title="Minimize">–</div>
<div class="winbtn" title="Maximize">▢</div>
<div class="winbtn" title="Close">×</div>
</div>
</div>
<div class="content">
<!-- Left: Buddy + Sign-On -->
<aside class="pane" aria-label="Buddy List & Sign-On">
<div class="section">
<div class="label">Buddy List</div>
<div class="buddy-search"><input id="search" type="text" placeholder="Find a buddy…"></div>
<div id="buddies" class="buddies" aria-live="polite">
<!-- Filled client-side with a single pseudo-buddy 'Peer' to match P2P model -->
</div>
</div>
<div class="section">
<div class="label">Sign On</div>
<div class="signon">
<div class="row rb" style="margin-bottom:6px">
<label><input type="radio" name="role" value="host" checked> Host</label>
<label><input type="radio" name="role" value="peer"> Peer</label>
<span id="pcState" class="pill">idle</span>
<span id="iceState" class="pill">idle</span>
<span id="dcState" class="pill">idle</span>
</div>
<div class="row" style="margin-bottom:6px">
<button id="btnCreate" class="btn primary">Sign On / Create</button>
<button id="btnCopy" class="btn">Copy My Blob</button>
<button id="btnReset" class="btn danger">Reset</button>
<span id="status" class="status" aria-live="polite"></span>
</div>
<details class="config">
<summary>Advanced connection info</summary>
<div style="margin:6px 0">
<div class="label" style="font-weight:600">Your description (Base64)</div>
<textarea id="local" rows="5" class="mono" placeholder="Your Base64 blob will appear here…" readonly></textarea>
</div>
<div style="margin:6px 0">
<div class="label" style="font-weight:600">Peer description (Base64 / JSON / raw SDP)</div>
<textarea id="remote" rows="5" class="mono" placeholder="Paste the other side’s blob here…"></textarea>
</div>
<div class="row" style="margin-top:4px">
<button id="btnSetRemote" class="btn">Set Remote</button>
</div>
</details>
</div>
</div>
</aside>
<!-- Right: Chat window -->
<main class="chat-wrap" aria-label="Chat">
<div class="header">
<span class="icon run" aria-hidden="true">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="16" cy="5" r="3" fill="#ffdb00" stroke="#000" stroke-width=".6"/>
<path d="M7 20l3-6 3 2 2 4" stroke="#000" stroke-width="1.2" stroke-linecap="round"/>
<path d="M9 12l4-4 4 2" stroke="#000" stroke-width="1.2" stroke-linecap="round"/>
</svg>
</span>
<div class="screenname">Instant Message with <span id="peerName">Peer</span></div>
<span class="pill" id="presence"><span class="dot online" style="display:inline-block;vertical-align:middle;margin-right:6px"></span> Online</span>
</div>
<div id="chat" class="chatbox" aria-live="polite" aria-label="Conversation log"></div>
<div class="section" style="border-bottom:none">
<div class="label">Your Screen Name</div>
<input id="name" type="text" placeholder="e.g. nyxmesh_h4x0r"/>
</div>
<div class="section" style="border-bottom:none">
<div class="inputbar">
<input id="msg" type="text" placeholder="Type a message…" disabled />
<button id="send" class="btn primary" disabled>Send</button>
</div>
</div>
</main>
</div>
</div>
<script>
/* ---------------------------
Core behavior (from original)
with visual tweaks for AIM skin
---------------------------- */
const $ = id => document.getElementById(id);
const roleInputs = document.querySelectorAll('input[name="role"]');
let role = 'host';
let pc, dc;
const rtcConfig = {
iceServers: [
{ urls: "stun:stun.l.google.com:19302" },
{ urls: "stun:stun1.l.google.com:19302" }
],
iceCandidatePoolSize: 10
};
function pill(el, text, cls=""){ el.textContent=text; el.className="pill "+cls; }
function setStatus(t,c){ const el=$('status'); el.textContent=t; el.style.color=c||""; }
function addLine(name, text, mine=false){
const row = document.createElement('div');
row.className = 'line ' + (mine? 'me' : 'peer');
const time = new Date().toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'});
row.innerHTML = `<span class="time">(${time})</span> <span class="sn">${name?escapeHtml(name): (mine? 'Me':'Peer')}</span>: <span class="text">${escapeHtml(text)}</span>`;
$('chat').appendChild(row);
$('chat').scrollTop = $('chat').scrollHeight;
}
function enableChat(on){ $('msg').disabled=!on; $('send').disabled=!on; }
/* ---------- blob helpers ---------- */
function pack(desc) {
const json = JSON.stringify(desc);
return btoa(unescape(encodeURIComponent(json)));
}
function unpackBase64(b64) {
const json = decodeURIComponent(escape(atob(b64)));
return JSON.parse(json);
}
function looksLikeJson(s){ return /^\s*\{/.test(s.trim()); }
function looksLikeSdp(s){ return /^\s*v=0\s*/.test(s.trim()); }
/* ---------- peer connection ---------- */
function setupPC(){
if(pc){ try{pc.close();}catch{} }
pc = new RTCPeerConnection(rtcConfig);
pc.onconnectionstatechange = () => {
const s = pc.connectionState;
pill($('pcState'), s, s==='connected'?'ok':(s==='failed'||s==='closed'?'bad':'warn'));
if (s==='connected' || s==='completed') { enableChat(true); setStatus('Connected ✓','#135c2f'); }
if (s==='disconnected'||s==='failed'||s==='closed') enableChat(false);
};
pc.oniceconnectionstatechange = () => {
const s = pc.iceConnectionState;
pill($('iceState'), s, (s==='connected'||s==='completed')?'ok':(s==='failed'?'bad':'warn'));
};
let gatherTimer=null;
pc.onicecandidate = () => {
if (gatherTimer) clearTimeout(gatherTimer);
gatherTimer = setTimeout(() => {
if (pc.localDescription) $('local').value = pack(pc.localDescription);
}, 300);
};
if (role==='host') {
dc = pc.createDataChannel('chat',{ordered:true});
wireDC(dc);
} else {
pc.ondatachannel = (ev)=>{ dc = ev.channel; wireDC(dc); };
}
}
function wireDC(channel){
pill($('dcState'), 'connecting', 'warn');
channel.onopen = ()=>{
pill($('dcState'),'open','ok');
enableChat(true);
$('msg').focus();
setStatus('DataChannel open ✓','#135c2f');
};
channel.onclose = ()=>{
pill($('dcState'),'closed','bad');
enableChat(false);
setStatus('Disconnected','#7a1a1a');
};
channel.onerror = (e)=>{
pill($('dcState'),'error','bad');
setStatus('DC error','#7a5a00');
console.error('DataChannel error:', e);
};
channel.onmessage = (ev)=>{
try{
const {name,text}=JSON.parse(ev.data);
addLine(name||'Peer', text, false);
}catch{
addLine('Peer', String(ev.data), false);
}
};
}
async function createLocal(){
if(!pc) setupPC();
if(role==='host'){
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
setStatus('Gathering ICE for offer…');
} else {
if (!pc.remoteDescription){ setStatus('Set remote offer first', '#7a5a00'); return; }
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
setStatus('Gathering ICE for answer…');
}
}
async function setRemote(){
try{
const raw = $('remote').value.trim();
if (!raw) { setStatus('Paste peer blob first', '#7a5a00'); return; }
let desc;
if (looksLikeJson(raw)) {
desc = JSON.parse(raw);
} else if (/^[A-Za-z0-9+/=\s]+$/.test(raw) && !looksLikeSdp(raw)) {
desc = unpackBase64(raw.replace(/\s+/g,''));
} else if (looksLikeSdp(raw)) {
desc = { type: (role === 'host' ? 'answer' : 'offer'), sdp: raw };
} else {
throw new Error('Unrecognized blob format');
}
if(!pc) setupPC();
await pc.setRemoteDescription(desc);
setStatus(`Remote ${desc.type} set`);
}catch(e){
console.error(e);
setStatus('Invalid blob (try Base64 or raw SDP)', '#7a1a1a');
}
}
function send(){
const text = $('msg').value.trim();
if(!text) return;
if(!dc || dc.readyState!=='open'){
setStatus('Not connected (DC not open)', '#7a5a00');
return;
}
const name = $('name').value.trim();
dc.send(JSON.stringify({name, text}));
addLine(name||'Me', text, true);
$('msg').value='';
}
function resetAll(){
try{ dc&&dc.close(); }catch{} try{ pc&&pc.close(); }catch{}
pc=null; dc=null;
$('local').value=''; $('remote').value='';
$('chat').innerHTML='';
enableChat(false);
pill($('pcState'),'idle'); pill($('iceState'),'idle'); pill($('dcState'),'idle');
setStatus('reset');
}
roleInputs.forEach(r=>r.addEventListener('change',()=>{ role=r.value; resetAll(); setupPC(); }));
$('btnCreate').onclick=createLocal;
$('btnSetRemote').onclick=setRemote;
$('btnCopy').onclick=async()=>{
const t=$('local').value.trim(); if(!t){ setStatus('Nothing to copy','#7a5a00'); return; }
try{ await navigator.clipboard.writeText(t); setStatus('Copied Base64 ✓','#135c2f'); }catch{ setStatus('Copy failed','#7a1a1a'); }
};
$('btnReset').onclick=resetAll;
$('send').onclick=send;
$('msg').addEventListener('keydown',e=>{ if(e.key==='Enter'){ e.preventDefault(); send(); }});
/* Setup buddy list (pseudo-buddy to fit P2P model) */
(function initBuddies(){
const list = $('buddies');
list.innerHTML = '';
const el = document.createElement('div');
el.className='buddy';
el.innerHTML = '<span class="dot online"></span><span class="sn">Peer</span><span style="margin-left:auto;color:#666">available</span>';
list.appendChild(el);
})();
/* Utilities */
function escapeHtml(s){
return s.replace(/[&<>\"']/g, ch => ({'&':'&','<':'<','>':'>','"':'"','\'':'''}[ch]));
}
/* init */
setupPC();
enableChat(false);
if (location.protocol === 'file:') {
setStatus('Tip: use http://localhost or HTTPS (WebRTC may be restricted on file://)', '#7a5a00');
}
</script>
</body>
</html>