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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="ru">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
|
| 6 |
+
<title>SemiCursors — общие курсоры</title>
|
| 7 |
+
<script src="https://unpkg.com/peerjs@1.5.4/dist/peerjs.min.js"></script>
|
| 8 |
+
<style>
|
| 9 |
+
*{box-sizing:border-box;margin:0;padding:0}
|
| 10 |
+
:root{
|
| 11 |
+
--bg:#0b0e14; --panel:#121824; --panel2:#1a2231; --border:#26303f;
|
| 12 |
+
--text:#e6edf6; --muted:#8b98ab; --accent:#7c5cff; --accent2:#22d3ee;
|
| 13 |
+
--danger:#ef4444;
|
| 14 |
+
}
|
| 15 |
+
html,body{height:100%}
|
| 16 |
+
body{
|
| 17 |
+
font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,'Helvetica Neue',sans-serif;
|
| 18 |
+
background:var(--bg); color:var(--text); overflow:hidden;
|
| 19 |
+
-webkit-font-smoothing:antialiased;
|
| 20 |
+
}
|
| 21 |
+
button{cursor:pointer;font-family:inherit;border:none;background:none;color:inherit}
|
| 22 |
+
input{font-family:inherit}
|
| 23 |
+
.hidden{display:none !important}
|
| 24 |
+
|
| 25 |
+
/* ============ LOBBY ============ */
|
| 26 |
+
#lobby{
|
| 27 |
+
height:100vh; overflow-y:auto;
|
| 28 |
+
display:flex; align-items:center; justify-content:center; padding:32px 16px;
|
| 29 |
+
background:
|
| 30 |
+
radial-gradient(900px 500px at 15% -10%, rgba(124,92,255,.18), transparent 60%),
|
| 31 |
+
radial-gradient(800px 500px at 90% 110%, rgba(34,211,238,.14), transparent 60%),
|
| 32 |
+
var(--bg);
|
| 33 |
+
}
|
| 34 |
+
.lobby-inner{width:100%;max-width:520px}
|
| 35 |
+
.logo{
|
| 36 |
+
font-size:38px;font-weight:800;letter-spacing:-.03em;text-align:center;
|
| 37 |
+
background:linear-gradient(100deg,#fff 10%,var(--accent2) 55%,var(--accent) 95%);
|
| 38 |
+
-webkit-background-clip:text;background-clip:text;color:transparent;
|
| 39 |
+
}
|
| 40 |
+
.tagline{text-align:center;color:var(--muted);font-size:14px;margin:10px 0 26px;line-height:1.55}
|
| 41 |
+
.card{
|
| 42 |
+
background:rgba(18,24,36,.85); border:1px solid var(--border);
|
| 43 |
+
border-radius:16px; padding:18px; backdrop-filter:blur(12px);
|
| 44 |
+
box-shadow:0 18px 50px rgba(0,0,0,.45);
|
| 45 |
+
}
|
| 46 |
+
.field{margin-bottom:14px}
|
| 47 |
+
.field:last-child{margin-bottom:0}
|
| 48 |
+
.field>label{display:block;font-size:12px;font-weight:600;color:var(--muted);margin-bottom:7px;text-transform:uppercase;letter-spacing:.06em}
|
| 49 |
+
input[type=text],input:not([type]){
|
| 50 |
+
width:100%; padding:11px 13px; border-radius:10px;
|
| 51 |
+
background:var(--panel2); border:1px solid var(--border); color:var(--text);
|
| 52 |
+
font-size:14px; outline:none; transition:border-color .15s, box-shadow .15s;
|
| 53 |
+
}
|
| 54 |
+
input:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(124,92,255,.18)}
|
| 55 |
+
input::placeholder{color:#5b6879}
|
| 56 |
+
|
| 57 |
+
.types{display:grid;grid-template-columns:1fr 1fr;gap:10px}
|
| 58 |
+
.type{
|
| 59 |
+
text-align:left;padding:13px;border-radius:12px;border:1.5px solid var(--border);
|
| 60 |
+
background:var(--panel2); transition:.15s; display:flex;flex-direction:column;gap:3px;
|
| 61 |
+
}
|
| 62 |
+
.type:hover{border-color:#3a4759}
|
| 63 |
+
.type.active{border-color:var(--accent);background:rgba(124,92,255,.13);box-shadow:0 0 0 3px rgba(124,92,255,.12)}
|
| 64 |
+
.type .ico{font-size:20px;line-height:1}
|
| 65 |
+
.type .tt{font-weight:700;font-size:14px;margin-top:3px}
|
| 66 |
+
.type .td{font-size:11px;color:var(--muted);line-height:1.4}
|
| 67 |
+
|
| 68 |
+
.btn{
|
| 69 |
+
padding:11px 18px;border-radius:10px;background:var(--panel2);
|
| 70 |
+
border:1px solid var(--border);font-size:14px;font-weight:600;
|
| 71 |
+
transition:.15s; white-space:nowrap;
|
| 72 |
+
}
|
| 73 |
+
.btn:hover{background:#222c3d;border-color:#3a4759}
|
| 74 |
+
.btn.primary{
|
| 75 |
+
background:linear-gradient(100deg,var(--accent),#5b8cff); border-color:transparent;
|
| 76 |
+
color:#fff; box-shadow:0 8px 24px rgba(124,92,255,.32);
|
| 77 |
+
}
|
| 78 |
+
.btn.primary:hover{filter:brightness(1.1)}
|
| 79 |
+
.btn.big{width:100%;padding:13px;font-size:15px}
|
| 80 |
+
.btn.danger{color:#ffb4b4;border-color:#4a2529;background:#241318}
|
| 81 |
+
.btn.danger:hover{background:#331a20;border-color:#6b3038}
|
| 82 |
+
.btn:disabled{opacity:.5;cursor:not-allowed}
|
| 83 |
+
|
| 84 |
+
.row{display:flex;gap:10px}
|
| 85 |
+
.row input{flex:1}
|
| 86 |
+
.or{display:flex;align-items:center;gap:14px;color:#4a5666;font-size:12px;margin:16px 0}
|
| 87 |
+
.or::before,.or::after{content:'';flex:1;height:1px;background:var(--border)}
|
| 88 |
+
.hint{text-align:center;color:#5b6879;font-size:12px;margin-top:18px;line-height:1.6}
|
| 89 |
+
|
| 90 |
+
/* ============ ROOM ============ */
|
| 91 |
+
#room{height:100vh;display:flex;flex-direction:column}
|
| 92 |
+
header{
|
| 93 |
+
display:flex;align-items:center;gap:10px;padding:9px 14px;flex-shrink:0;
|
| 94 |
+
background:var(--panel);border-bottom:1px solid var(--border);flex-wrap:wrap;
|
| 95 |
+
}
|
| 96 |
+
.brand{font-weight:800;font-size:16px;letter-spacing:-.02em;white-space:nowrap}
|
| 97 |
+
.brand span{background:linear-gradient(100deg,var(--accent2),var(--accent));-webkit-background-clip:text;background-clip:text;color:transparent}
|
| 98 |
+
.badge{
|
| 99 |
+
font-size:11px;font-weight:700;padding:5px 10px;border-radius:20px;
|
| 100 |
+
background:rgba(124,92,255,.16);border:1px solid rgba(124,92,255,.35);color:#c3b5ff;
|
| 101 |
+
white-space:nowrap;
|
| 102 |
+
}
|
| 103 |
+
.chip{
|
| 104 |
+
font-size:12px;font-weight:600;padding:6px 11px;border-radius:8px;
|
| 105 |
+
background:var(--panel2);border:1px solid var(--border);transition:.15s;white-space:nowrap;
|
| 106 |
+
}
|
| 107 |
+
.chip:hover{background:#222c3d;border-color:#3a4759}
|
| 108 |
+
.chip b{color:var(--accent2);letter-spacing:.12em;font-family:ui-monospace,monospace}
|
| 109 |
+
.spacer{flex:1}
|
| 110 |
+
.avatars{display:flex;align-items:center}
|
| 111 |
+
.av{
|
| 112 |
+
width:26px;height:26px;border-radius:50%;margin-left:-7px;
|
| 113 |
+
border:2px solid var(--panel);display:flex;align-items:center;justify-content:center;
|
| 114 |
+
font-size:10px;font-weight:800;color:#0b0e14;
|
| 115 |
+
}
|
| 116 |
+
.av:first-child{margin-left:0}
|
| 117 |
+
.dot{width:8px;height:8px;border-radius:50%;background:#4ade80;box-shadow:0 0 8px #4ade80;flex-shrink:0}
|
| 118 |
+
.dot.off{background:#64748b;box-shadow:none}
|
| 119 |
+
|
| 120 |
+
/* ============ STAGE ============ */
|
| 121 |
+
#stage{position:relative;flex:1;overflow:hidden;background:#080b11;cursor:none}
|
| 122 |
+
#sandbox{
|
| 123 |
+
position:absolute;inset:0;
|
| 124 |
+
background-image:radial-gradient(circle,#1f2836 1px,transparent 1px);
|
| 125 |
+
background-size:26px 26px;
|
| 126 |
+
}
|
| 127 |
+
#board{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none}
|
| 128 |
+
#siteFrame{position:absolute;inset:0;width:100%;height:100%;border:0;background:#fff}
|
| 129 |
+
#capture{position:absolute;inset:0;z-index:4;background:transparent}
|
| 130 |
+
#capture.off{pointer-events:none;cursor:auto}
|
| 131 |
+
#cursorLayer{position:absolute;inset:0;z-index:6;pointer-events:none;overflow:hidden}
|
| 132 |
+
|
| 133 |
+
.cursor{
|
| 134 |
+
position:absolute;left:0;top:0;pointer-events:none;will-change:transform;
|
| 135 |
+
transition:transform .09s linear;
|
| 136 |
+
}
|
| 137 |
+
.cursor.self{transition:none}
|
| 138 |
+
.cursor svg{display:block;margin:-2px 0 0 -4px;filter:drop-shadow(0 2px 4px rgba(0,0,0,.5))}
|
| 139 |
+
.clabel{
|
| 140 |
+
position:absolute;left:15px;top:15px;padding:2.5px 8px;border-radius:7px;
|
| 141 |
+
font-size:11px;font-weight:700;color:#0b0e14;white-space:nowrap;line-height:1.45;
|
| 142 |
+
box-shadow:0 3px 10px rgba(0,0,0,.35);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
/* toolbar */
|
| 146 |
+
#tools{
|
| 147 |
+
position:absolute;left:50%;bottom:18px;transform:translateX(-50%);z-index:8;
|
| 148 |
+
display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:14px;
|
| 149 |
+
background:rgba(18,24,36,.92);border:1px solid var(--border);
|
| 150 |
+
backdrop-filter:blur(14px);box-shadow:0 14px 40px rgba(0,0,0,.5);cursor:default;
|
| 151 |
+
}
|
| 152 |
+
.sw{width:22px;height:22px;border-radius:50%;border:2px solid transparent;transition:.15s;padding:0}
|
| 153 |
+
.sw:hover{transform:scale(1.12)}
|
| 154 |
+
.sw.active{border-color:#fff;transform:scale(1.12)}
|
| 155 |
+
.tdiv{width:1px;height:20px;background:var(--border);margin:0 2px}
|
| 156 |
+
#tools .btn{padding:6px 11px;font-size:12px;border-radius:8px}
|
| 157 |
+
|
| 158 |
+
/* toast */
|
| 159 |
+
#toasts{position:fixed;left:50%;bottom:26px;transform:translateX(-50%);z-index:999;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none;max-width:90vw}
|
| 160 |
+
.toast{
|
| 161 |
+
padding:10px 16px;border-radius:10px;font-size:13px;font-weight:600;
|
| 162 |
+
background:rgba(18,24,36,.96);border:1px solid var(--border);color:var(--text);
|
| 163 |
+
box-shadow:0 10px 30px rgba(0,0,0,.5);animation:tin .25s ease;text-align:center;
|
| 164 |
+
}
|
| 165 |
+
.toast.err{border-color:#5b2a30;color:#ffb4b4}
|
| 166 |
+
@keyframes tin{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:translateY(0)}}
|
| 167 |
+
|
| 168 |
+
@media (max-width:640px){
|
| 169 |
+
.types{grid-template-columns:1fr}
|
| 170 |
+
.brand{font-size:14px}
|
| 171 |
+
.chip{font-size:11px;padding:5px 8px}
|
| 172 |
+
.logo{font-size:30px}
|
| 173 |
+
}
|
| 174 |
+
</style>
|
| 175 |
+
</head>
|
| 176 |
+
<body>
|
| 177 |
+
|
| 178 |
+
<!-- ================= LOBBY ================= -->
|
| 179 |
+
<div id="lobby">
|
| 180 |
+
<div class="lobby-inner">
|
| 181 |
+
<div class="logo">SemiCursors</div>
|
| 182 |
+
<p class="tagline">Общие курсоры для тебя и друзей — в песочнице или поверх любого сайта</p>
|
| 183 |
+
|
| 184 |
+
<div class="card">
|
| 185 |
+
<div class="field">
|
| 186 |
+
<label>Твоё имя</label>
|
| 187 |
+
<input id="nameInput" maxlength="16" placeholder="Например, Алекс" autocomplete="off">
|
| 188 |
+
</div>
|
| 189 |
+
|
| 190 |
+
<div class="field">
|
| 191 |
+
<label>Тип комнаты</label>
|
| 192 |
+
<div class="types">
|
| 193 |
+
<button class="type active" data-type="sandbox">
|
| 194 |
+
<span class="ico">🎨</span>
|
| 195 |
+
<span class="tt">Sandbox</span>
|
| 196 |
+
<span class="td">Свободное поле: рисуй и показывай курсор</span>
|
| 197 |
+
</button>
|
| 198 |
+
<button class="type" data-type="site">
|
| 199 |
+
<span class="ico">🌐</span>
|
| 200 |
+
<span class="tt">Site</span>
|
| 201 |
+
<span class="td">Курсоры поверх сайта по ссылке</span>
|
| 202 |
+
</button>
|
| 203 |
+
</div>
|
| 204 |
+
</div>
|
| 205 |
+
|
| 206 |
+
<div class="field hidden" id="urlField">
|
| 207 |
+
<label>Адрес сайта</label>
|
| 208 |
+
<input id="urlInput" placeholder="https://example.com" autocomplete="off">
|
| 209 |
+
</div>
|
| 210 |
+
|
| 211 |
+
<button class="btn primary big" id="createBtn">Создать комнату</button>
|
| 212 |
+
</div>
|
| 213 |
+
|
| 214 |
+
<div class="or"><span>или</span></div>
|
| 215 |
+
|
| 216 |
+
<div class="card">
|
| 217 |
+
<div class="field" style="margin-bottom:0">
|
| 218 |
+
<label>Код приглашения</label>
|
| 219 |
+
<div class="row">
|
| 220 |
+
<input id="codeInput" maxlength="6" placeholder="ABC123" autocomplete="off"
|
| 221 |
+
style="text-transform:uppercase;letter-spacing:.22em;font-weight:800">
|
| 222 |
+
<button class="btn primary" id="joinBtn">Войти</button>
|
| 223 |
+
</div>
|
| 224 |
+
</div>
|
| 225 |
+
</div>
|
| 226 |
+
|
| 227 |
+
<p class="hint">Открой ссылку с кодом на другом устройстве — курсоры синхронизируются в реальном времени.</p>
|
| 228 |
+
</div>
|
| 229 |
+
</div>
|
| 230 |
+
|
| 231 |
+
<!-- ================= ROOM ================= -->
|
| 232 |
+
<div id="room" class="hidden">
|
| 233 |
+
<header>
|
| 234 |
+
<div class="brand">Semi<span>Cursors</span></div>
|
| 235 |
+
<span class="dot off" id="statusDot" title="Соединение"></span>
|
| 236 |
+
<span class="badge" id="typeBadge">Sandbox</span>
|
| 237 |
+
<button class="chip" id="codeChip" title="Нажми, чтобы скопировать">Код: <b id="codeText">—</b></button>
|
| 238 |
+
<button class="chip" id="copyLink">🔗 Пригласить</button>
|
| 239 |
+
<div class="spacer"></div>
|
| 240 |
+
<div class="avatars" id="avatars"></div>
|
| 241 |
+
<button class="chip hidden" id="modeToggle">🖱 Взаимодействие</button>
|
| 242 |
+
<button class="btn danger" id="leaveBtn">Выйти</button>
|
| 243 |
+
</header>
|
| 244 |
+
|
| 245 |
+
<main id="stage">
|
| 246 |
+
<div id="sandbox">
|
| 247 |
+
<canvas id="board"></canvas>
|
| 248 |
+
</div>
|
| 249 |
+
<iframe id="siteFrame" class="hidden" src="about:blank" referrerpolicy="no-referrer"
|
| 250 |
+
allow="fullscreen; clipboard-read; clipboard-write"></iframe>
|
| 251 |
+
<div id="capture" class="hidden"></div>
|
| 252 |
+
<div id="cursorLayer"></div>
|
| 253 |
+
|
| 254 |
+
<div id="tools" class="hidden">
|
| 255 |
+
<button class="sw" data-color="#ff6b81" style="background:#ff6b81"></button>
|
| 256 |
+
<button class="sw" data-color="#ffb347" style="background:#ffb347"></button>
|
| 257 |
+
<button class="sw" data-color="#4ade80" style="background:#4ade80"></button>
|
| 258 |
+
<button class="sw" data-color="#38bdf8" style="background:#38bdf8"></button>
|
| 259 |
+
<button class="sw" data-color="#a78bfa" style="background:#a78bfa"></button>
|
| 260 |
+
<button class="sw active" data-color="#ffffff" style="background:#ffffff"></button>
|
| 261 |
+
<span class="tdiv"></span>
|
| 262 |
+
<button class="btn" id="clearBtn">🗑 Очистить</button>
|
| 263 |
+
</div>
|
| 264 |
+
</main>
|
| 265 |
+
</div>
|
| 266 |
+
|
| 267 |
+
<div id="toasts"></div>
|
| 268 |
+
|
| 269 |
+
<script>
|
| 270 |
+
/* ==========================================================
|
| 271 |
+
УТИЛИТЫ
|
| 272 |
+
========================================================== */
|
| 273 |
+
const $ = s => document.querySelector(s);
|
| 274 |
+
const esc = s => String(s).replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
| 275 |
+
const PALETTE = ['#ff6b81','#ffb347','#4ade80','#38bdf8','#a78bfa','#f472b6','#22d3ee','#facc15','#fb923c','#34d399'];
|
| 276 |
+
const randPick = a => a[Math.floor(Math.random() * a.length)];
|
| 277 |
+
const IS_FILE = location.protocol === 'file:';
|
| 278 |
+
|
| 279 |
+
function genCode(){
|
| 280 |
+
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
| 281 |
+
let s = '';
|
| 282 |
+
for (let i = 0; i < 6; i++) s += chars[Math.floor(Math.random() * chars.length)];
|
| 283 |
+
return s;
|
| 284 |
+
}
|
| 285 |
+
|
| 286 |
+
function toast(msg, isErr, ms){
|
| 287 |
+
const t = document.createElement('div');
|
| 288 |
+
t.className = 'toast' + (isErr ? ' err' : '');
|
| 289 |
+
t.textContent = msg;
|
| 290 |
+
$('#toasts').appendChild(t);
|
| 291 |
+
setTimeout(() => { t.style.transition = 'opacity .3s'; t.style.opacity = '0';
|
| 292 |
+
setTimeout(() => t.remove(), 320); }, ms || 2800);
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
/* ==========================================================
|
| 296 |
+
PEERJS СЕРВЕРЫ (мульти-фолбэк)
|
| 297 |
+
========================================================== */
|
| 298 |
+
const PREFIX = 'semicursors-v1-';
|
| 299 |
+
const PEER_HOSTS = [
|
| 300 |
+
{ host: '0.peerjs.com', port: 443, secure: true },
|
| 301 |
+
{ host: '1.peerjs.com', port: 443, secure: true },
|
| 302 |
+
{ host: '2.peerjs.com', port: 443, secure: true },
|
| 303 |
+
{ host: '3.peerjs.com', port: 443, secure: true },
|
| 304 |
+
];
|
| 305 |
+
let currentHostIdx = 0;
|
| 306 |
+
let preferredHostIdx = null;
|
| 307 |
+
|
| 308 |
+
/**
|
| 309 |
+
* Открывает Peer с автоматическим перебором серверов.
|
| 310 |
+
* @param {string|null} idOrNull — желаемый peer id или null
|
| 311 |
+
* @returns {Promise<{peer, id, hostIdx}>}
|
| 312 |
+
*/
|
| 313 |
+
function openPeer(idOrNull){
|
| 314 |
+
const order = preferredHostIdx !== null
|
| 315 |
+
? [preferredHostIdx, ...[0,1,2,3].filter(i => i !== preferredHostIdx)]
|
| 316 |
+
: [0, 1, 2, 3];
|
| 317 |
+
|
| 318 |
+
return new Promise((resolve, reject) => {
|
| 319 |
+
let settled = false;
|
| 320 |
+
let idx = 0;
|
| 321 |
+
|
| 322 |
+
function tryNext(){
|
| 323 |
+
if (settled) return;
|
| 324 |
+
if (idx >= order.length){
|
| 325 |
+
settled = true;
|
| 326 |
+
reject({ type: 'all-servers-failed' });
|
| 327 |
+
return;
|
| 328 |
+
}
|
| 329 |
+
const hostIdx = order[idx++];
|
| 330 |
+
const cfg = Object.assign({}, PEER_HOSTS[hostIdx], { debug: 0 });
|
| 331 |
+
|
| 332 |
+
let p;
|
| 333 |
+
try {
|
| 334 |
+
p = idOrNull ? new Peer(idOrNull, cfg) : new Peer(cfg);
|
| 335 |
+
} catch(e){
|
| 336 |
+
tryNext();
|
| 337 |
+
return;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
let done = false;
|
| 341 |
+
const finish = (fn) => {
|
| 342 |
+
if (done || settled) return;
|
| 343 |
+
done = true;
|
| 344 |
+
clearTimeout(to);
|
| 345 |
+
fn();
|
| 346 |
+
};
|
| 347 |
+
|
| 348 |
+
const to = setTimeout(() => {
|
| 349 |
+
finish(() => {
|
| 350 |
+
try { p.destroy(); } catch(e){}
|
| 351 |
+
tryNext();
|
| 352 |
+
});
|
| 353 |
+
}, 7000);
|
| 354 |
+
|
| 355 |
+
p.on('open', id => {
|
| 356 |
+
finish(() => {
|
| 357 |
+
settled = true;
|
| 358 |
+
currentHostIdx = hostIdx;
|
| 359 |
+
resolve({ peer: p, id, hostIdx });
|
| 360 |
+
});
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
p.on('error', err => {
|
| 364 |
+
const type = err && err.type;
|
| 365 |
+
if (type === 'unavailable-id'){
|
| 366 |
+
finish(() => {
|
| 367 |
+
settled = true;
|
| 368 |
+
try { p.destroy(); } catch(e){}
|
| 369 |
+
reject(err);
|
| 370 |
+
});
|
| 371 |
+
return;
|
| 372 |
+
}
|
| 373 |
+
finish(() => {
|
| 374 |
+
try { p.destroy(); } catch(e){}
|
| 375 |
+
tryNext();
|
| 376 |
+
});
|
| 377 |
+
});
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
tryNext();
|
| 381 |
+
});
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
/* ==========================================================
|
| 385 |
+
СОСТОЯНИЕ
|
| 386 |
+
========================================================== */
|
| 387 |
+
let myName = 'Гость';
|
| 388 |
+
let myColor = randPick(PALETTE);
|
| 389 |
+
let roomType = 'sandbox';
|
| 390 |
+
let roomUrl = '';
|
| 391 |
+
let roomCode = '';
|
| 392 |
+
let isHost = false;
|
| 393 |
+
let myId = '';
|
| 394 |
+
let peer = null;
|
| 395 |
+
let hostConn = null; // гость → хост
|
| 396 |
+
const guests = new Map(); // хост: peerId -> {conn,name,color,x,y}
|
| 397 |
+
const cursors = new Map(); // id -> {el,x,y,name,color}
|
| 398 |
+
let selfCursor = null;
|
| 399 |
+
let selfEntry = null;
|
| 400 |
+
let inRoom = false;
|
| 401 |
+
let interacting = false;
|
| 402 |
+
|
| 403 |
+
let stageW = 1, stageH = 1;
|
| 404 |
+
let localX = 0.5, localY = 0.5;
|
| 405 |
+
|
| 406 |
+
const stage = $('#stage');
|
| 407 |
+
const cursorLayer= $('#cursorLayer');
|
| 408 |
+
const capture = $('#capture');
|
| 409 |
+
const sandboxEl = $('#sandbox');
|
| 410 |
+
const canvas = $('#board');
|
| 411 |
+
const siteFrame = $('#siteFrame');
|
| 412 |
+
|
| 413 |
+
/* ==========================================================
|
| 414 |
+
ОТРИСОВКА КУРСОРОВ
|
| 415 |
+
========================================================== */
|
| 416 |
+
function makeCursorEl(name, color){
|
| 417 |
+
const el = document.createElement('div');
|
| 418 |
+
el.className = 'cursor';
|
| 419 |
+
el.innerHTML =
|
| 420 |
+
'<svg viewBox="0 0 24 24" width="22" height="22">' +
|
| 421 |
+
'<path d="M4 2 L4 20 L9 15.2 L12.2 22 L15.2 20.8 L12 14.2 L19 14 Z" ' +
|
| 422 |
+
'fill="' + color + '" stroke="rgba(0,0,0,.55)" stroke-width="1.4" stroke-linejoin="round"/>' +
|
| 423 |
+
'</svg>' +
|
| 424 |
+
'<span class="clabel" style="background:' + color + '">' + esc(name) + '</span>';
|
| 425 |
+
return el;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
function placeEntry(e){
|
| 429 |
+
e.el.style.transform = 'translate3d(' + (e.x * stageW) + 'px,' + (e.y * stageH) + 'px,0)';
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
function measure(){
|
| 433 |
+
const r = stage.getBoundingClientRect();
|
| 434 |
+
stageW = r.width || 1;
|
| 435 |
+
stageH = r.height || 1;
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
function addCursor(id, name, color){
|
| 439 |
+
let e = cursors.get(id);
|
| 440 |
+
if (e){
|
| 441 |
+
e.name = name; e.color = color;
|
| 442 |
+
e.el.querySelector('.clabel').textContent = name;
|
| 443 |
+
e.el.querySelector('.clabel').style.background = color;
|
| 444 |
+
e.el.querySelector('path').setAttribute('fill', color);
|
| 445 |
+
return e;
|
| 446 |
+
}
|
| 447 |
+
const el = makeCursorEl(name, color);
|
| 448 |
+
cursorLayer.appendChild(el);
|
| 449 |
+
e = { el, x: 0.5, y: 0.5, name, color };
|
| 450 |
+
placeEntry(e);
|
| 451 |
+
cursors.set(id, e);
|
| 452 |
+
renderAvatars();
|
| 453 |
+
toast(name + ' присоединился');
|
| 454 |
+
return e;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
function moveCursor(id, x, y){
|
| 458 |
+
const e = cursors.get(id);
|
| 459 |
+
if (!e) return;
|
| 460 |
+
e.x = x; e.y = y;
|
| 461 |
+
placeEntry(e);
|
| 462 |
+
}
|
| 463 |
+
|
| 464 |
+
function removeCursor(id){
|
| 465 |
+
const e = cursors.get(id);
|
| 466 |
+
if (!e) return;
|
| 467 |
+
const nm = e.name;
|
| 468 |
+
e.el.remove();
|
| 469 |
+
cursors.delete(id);
|
| 470 |
+
renderAvatars();
|
| 471 |
+
toast(nm + ' вышел');
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
function renderAvatars(){
|
| 475 |
+
const box = $('#avatars');
|
| 476 |
+
const list = [{ name: myName, color: myColor, me: true }];
|
| 477 |
+
cursors.forEach(c => list.push({ name: c.name, color: c.color }));
|
| 478 |
+
box.innerHTML = list.slice(0, 7).map(p =>
|
| 479 |
+
'<div class="av" style="background:' + p.color + '" title="' + esc(p.name) + (p.me ? ' (вы)' : '') + '">' +
|
| 480 |
+
esc(p.name.trim().charAt(0).toUpperCase() || '?') +
|
| 481 |
+
'</div>'
|
| 482 |
+
).join('');
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
function setStatus(on){
|
| 486 |
+
$('#statusDot').className = 'dot' + (on ? '' : ' off');
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
/* ==========================================================
|
| 490 |
+
СООБЩЕНИЯ
|
| 491 |
+
========================================================== */
|
| 492 |
+
function handleHostMessage(data){
|
| 493 |
+
// сообщения от хоста → гостю
|
| 494 |
+
if (!data || typeof data !== 'object') return;
|
| 495 |
+
switch(data.t){
|
| 496 |
+
case 'join': addCursor(data.peer.id, data.peer.name, data.peer.color); break;
|
| 497 |
+
case 'cursor': moveCursor(data.id, data.x, data.y); break;
|
| 498 |
+
case 'bye': removeCursor(data.id); break;
|
| 499 |
+
case 'stroke': addStroke(data.stroke, false); break;
|
| 500 |
+
case 'clear': strokes.length = 0; redraw(); break;
|
| 501 |
+
}
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
function handleGuestMessage(conn, data){
|
| 505 |
+
// сообщения от гостя → хосту
|
| 506 |
+
if (!data || typeof data !== 'object') return;
|
| 507 |
+
const g = guests.get(conn.peer);
|
| 508 |
+
if (!g) return;
|
| 509 |
+
|
| 510 |
+
switch(data.t){
|
| 511 |
+
case 'hello': {
|
| 512 |
+
g.name = String(data.name || 'Гость').slice(0, 16);
|
| 513 |
+
g.color = data.color || randPick(PALETTE);
|
| 514 |
+
|
| 515 |
+
const peers = [{ id: 'host', name: myName, color: myColor }];
|
| 516 |
+
guests.forEach((v, k) => { if (k !== conn.peer) peers.push({ id: k, name: v.name, color: v.color }); });
|
| 517 |
+
|
| 518 |
+
try {
|
| 519 |
+
conn.send({
|
| 520 |
+
t: 'welcome',
|
| 521 |
+
id: conn.peer,
|
| 522 |
+
peers,
|
| 523 |
+
room: { type: roomType, url: roomUrl }
|
| 524 |
+
});
|
| 525 |
+
} catch(e){}
|
| 526 |
+
|
| 527 |
+
relay({ t: 'join', peer: { id: conn.peer, name: g.name, color: g.color } }, conn.peer);
|
| 528 |
+
addCursor(conn.peer, g.name, g.color);
|
| 529 |
+
break;
|
| 530 |
+
}
|
| 531 |
+
case 'cursor':
|
| 532 |
+
g.x = data.x; g.y = data.y;
|
| 533 |
+
relay({ t: 'cursor', id: conn.peer, x: data.x, y: data.y }, conn.peer);
|
| 534 |
+
moveCursor(conn.peer, data.x, data.y);
|
| 535 |
+
break;
|
| 536 |
+
case 'stroke':
|
| 537 |
+
relay({ t: 'stroke', stroke: data.stroke }, conn.peer);
|
| 538 |
+
addStroke(data.stroke, false);
|
| 539 |
+
break;
|
| 540 |
+
case 'clear':
|
| 541 |
+
relay({ t: 'clear' }, conn.peer);
|
| 542 |
+
strokes.length = 0; redraw();
|
| 543 |
+
break;
|
| 544 |
+
}
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
function relay(data, exceptId){
|
| 548 |
+
guests.forEach((v, k) => {
|
| 549 |
+
if (k === exceptId) return;
|
| 550 |
+
try { v.conn.send(data); } catch(e){}
|
| 551 |
+
});
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
/* ==========================================================
|
| 555 |
+
ХОСТ
|
| 556 |
+
========================================================== */
|
| 557 |
+
async function becomeHost(){
|
| 558 |
+
let lastError = null;
|
| 559 |
+
for (let attempt = 0; attempt < 3; attempt++){
|
| 560 |
+
try {
|
| 561 |
+
const res = await openPeer(PREFIX + roomCode);
|
| 562 |
+
peer = res.peer;
|
| 563 |
+
currentHostIdx = res.hostIdx;
|
| 564 |
+
break;
|
| 565 |
+
} catch (e){
|
| 566 |
+
lastError = e;
|
| 567 |
+
if (e && e.type === 'unavailable-id'){
|
| 568 |
+
roomCode = genCode();
|
| 569 |
+
continue;
|
| 570 |
+
}
|
| 571 |
+
throw e;
|
| 572 |
+
}
|
| 573 |
+
}
|
| 574 |
+
if (!peer) throw lastError || new Error('Не удалось создать комнату');
|
| 575 |
+
|
| 576 |
+
isHost = true;
|
| 577 |
+
myId = 'host';
|
| 578 |
+
setStatus(true);
|
| 579 |
+
|
| 580 |
+
peer.on('connection', conn => {
|
| 581 |
+
conn.on('open', () => {
|
| 582 |
+
guests.set(conn.peer, { conn, name: '…', color: '#8b98ab', x: .5, y: .5 });
|
| 583 |
+
});
|
| 584 |
+
|
| 585 |
+
conn.on('data', data => handleGuestMessage(conn, data));
|
| 586 |
+
|
| 587 |
+
const drop = () => {
|
| 588 |
+
if (guests.has(conn.peer)){
|
| 589 |
+
guests.delete(conn.peer);
|
| 590 |
+
removeCursor(conn.peer);
|
| 591 |
+
relay({ t: 'bye', id: conn.peer }, conn.peer);
|
| 592 |
+
}
|
| 593 |
+
};
|
| 594 |
+
conn.on('close', drop);
|
| 595 |
+
conn.on('error', drop);
|
| 596 |
+
});
|
| 597 |
+
|
| 598 |
+
peer.on('disconnected', () => {
|
| 599 |
+
setStatus(false);
|
| 600 |
+
try { peer.reconnect(); } catch(e){}
|
| 601 |
+
});
|
| 602 |
+
peer.on('close', () => setStatus(false));
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
/* ==========================================================
|
| 606 |
+
ГОСТЬ
|
| 607 |
+
========================================================== */
|
| 608 |
+
function tryGuestOnServer(code, hostIdx){
|
| 609 |
+
return new Promise((resolve, reject) => {
|
| 610 |
+
const cfg = Object.assign({}, PEER_HOSTS[hostIdx], { debug: 0 });
|
| 611 |
+
const p = new Peer(cfg);
|
| 612 |
+
|
| 613 |
+
let welcomed = false;
|
| 614 |
+
let finished = false;
|
| 615 |
+
|
| 616 |
+
const fail = (type) => {
|
| 617 |
+
if (finished) return;
|
| 618 |
+
finished = true;
|
| 619 |
+
clearTimeout(to);
|
| 620 |
+
try { p.destroy(); } catch(e){}
|
| 621 |
+
reject({ type });
|
| 622 |
+
};
|
| 623 |
+
|
| 624 |
+
const to = setTimeout(() => fail('timeout'), 9000);
|
| 625 |
+
|
| 626 |
+
p.on('open', () => {
|
| 627 |
+
if (finished) return;
|
| 628 |
+
let conn;
|
| 629 |
+
try {
|
| 630 |
+
conn = p.connect(PREFIX + code, { reliable: true });
|
| 631 |
+
} catch(e){ fail('connect-error'); return; }
|
| 632 |
+
hostConn = conn;
|
| 633 |
+
|
| 634 |
+
conn.on('open', () => {
|
| 635 |
+
if (finished) return;
|
| 636 |
+
try {
|
| 637 |
+
conn.send({ t: 'hello', name: myName, color: myColor });
|
| 638 |
+
} catch(e){ fail('send-error'); }
|
| 639 |
+
});
|
| 640 |
+
|
| 641 |
+
conn.on('data', data => {
|
| 642 |
+
if (!data || typeof data !== 'object') return;
|
| 643 |
+
if (data.t === 'welcome' && !welcomed){
|
| 644 |
+
welcomed = true;
|
| 645 |
+
finished = true;
|
| 646 |
+
clearTimeout(to);
|
| 647 |
+
myId = data.id;
|
| 648 |
+
if (data.room){
|
| 649 |
+
roomType = data.room.type || 'sandbox';
|
| 650 |
+
roomUrl = data.room.url || '';
|
| 651 |
+
}
|
| 652 |
+
(data.peers || []).forEach(pe => {
|
| 653 |
+
if (pe.id !== myId) addCursor(pe.id, pe.name, pe.color);
|
| 654 |
+
});
|
| 655 |
+
resolve({ peer: p, conn, hostIdx });
|
| 656 |
+
} else if (welcomed){
|
| 657 |
+
handleHostMessage(data);
|
| 658 |
+
}
|
| 659 |
+
});
|
| 660 |
+
|
| 661 |
+
conn.on('close', () => {
|
| 662 |
+
if (welcomed){
|
| 663 |
+
setStatus(false);
|
| 664 |
+
if (inRoom){ toast('Хост закрыл комнату', true); leaveRoom(); }
|
| 665 |
+
} else {
|
| 666 |
+
fail('closed');
|
| 667 |
+
}
|
| 668 |
+
});
|
| 669 |
+
conn.on('error', () => { if (!welcomed) fail('conn-error'); });
|
| 670 |
+
});
|
| 671 |
+
|
| 672 |
+
p.on('error', err => {
|
| 673 |
+
if (!welcomed) fail(err && err.type || 'peer-error');
|
| 674 |
+
});
|
| 675 |
+
});
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
async function becomeGuest(code){
|
| 679 |
+
const order = preferredHostIdx !== null
|
| 680 |
+
? [preferredHostIdx, ...[0,1,2,3].filter(i => i !== preferredHostIdx)]
|
| 681 |
+
: [0, 1, 2, 3];
|
| 682 |
+
|
| 683 |
+
let lastErr = null;
|
| 684 |
+
for (const hostIdx of order){
|
| 685 |
+
try {
|
| 686 |
+
const res = await tryGuestOnServer(code, hostIdx);
|
| 687 |
+
peer = res.peer;
|
| 688 |
+
currentHostIdx = hostIdx;
|
| 689 |
+
setStatus(true);
|
| 690 |
+
return;
|
| 691 |
+
} catch(e){
|
| 692 |
+
lastErr = e;
|
| 693 |
+
console.warn('[join] server ' + hostIdx + ' failed:', e);
|
| 694 |
+
}
|
| 695 |
+
}
|
| 696 |
+
throw { type: 'all-servers-failed', last: lastErr };
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
/* ==========================================================
|
| 700 |
+
ОТПРАВКА КУРСОРА
|
| 701 |
+
========================================================== */
|
| 702 |
+
let lastSent = 0, pendingPos = null, pendingTimer = null;
|
| 703 |
+
|
| 704 |
+
function pushCursor(x, y){
|
| 705 |
+
if (!inRoom || interacting) return;
|
| 706 |
+
const now = performance.now();
|
| 707 |
+
if (now - lastSent >= 40){
|
| 708 |
+
lastSent = now;
|
| 709 |
+
sendCursor(x, y);
|
| 710 |
+
} else {
|
| 711 |
+
pendingPos = { x, y };
|
| 712 |
+
if (!pendingTimer){
|
| 713 |
+
pendingTimer = setTimeout(() => {
|
| 714 |
+
pendingTimer = null;
|
| 715 |
+
if (pendingPos){
|
| 716 |
+
lastSent = performance.now();
|
| 717 |
+
sendCursor(pendingPos.x, pendingPos.y);
|
| 718 |
+
pendingPos = null;
|
| 719 |
+
}
|
| 720 |
+
}, 40);
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
function sendCursor(x, y){
|
| 726 |
+
if (isHost){
|
| 727 |
+
relay({ t: 'cursor', id: 'host', x, y });
|
| 728 |
+
} else if (hostConn && hostConn.open){
|
| 729 |
+
try { hostConn.send({ t: 'cursor', x, y }); } catch(e){}
|
| 730 |
+
}
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
/* ==========================================================
|
| 734 |
+
SANDBOX — РИСОВАНИЕ
|
| 735 |
+
========================================================== */
|
| 736 |
+
const strokes = [];
|
| 737 |
+
let curStroke = null;
|
| 738 |
+
let drawColor = '#ffffff';
|
| 739 |
+
|
| 740 |
+
function resizeCanvas(){
|
| 741 |
+
const dpr = window.devicePixelRatio || 1;
|
| 742 |
+
const w = canvas.clientWidth, h = canvas.clientHeight;
|
| 743 |
+
if (!w || !h) return;
|
| 744 |
+
canvas.width = Math.round(w * dpr);
|
| 745 |
+
canvas.height = Math.round(h * dpr);
|
| 746 |
+
const ctx = canvas.getContext('2d');
|
| 747 |
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
| 748 |
+
redraw();
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
function redraw(){
|
| 752 |
+
const ctx = canvas.getContext('2d');
|
| 753 |
+
const dpr = window.devicePixelRatio || 1;
|
| 754 |
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
| 755 |
+
ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight);
|
| 756 |
+
strokes.forEach(s => paintStroke(ctx, s));
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
function paintStroke(ctx, s){
|
| 760 |
+
const W = canvas.clientWidth, H = canvas.clientHeight;
|
| 761 |
+
if (!s.pts || !s.pts.length) return;
|
| 762 |
+
ctx.lineCap = 'round';
|
| 763 |
+
ctx.lineJoin = 'round';
|
| 764 |
+
ctx.strokeStyle = s.color;
|
| 765 |
+
ctx.fillStyle = s.color;
|
| 766 |
+
ctx.lineWidth = s.w;
|
| 767 |
+
if (s.pts.length === 1){
|
| 768 |
+
ctx.beginPath();
|
| 769 |
+
ctx.arc(s.pts[0][0] * W, s.pts[0][1] * H, s.w / 2, 0, Math.PI * 2);
|
| 770 |
+
ctx.fill();
|
| 771 |
+
return;
|
| 772 |
+
}
|
| 773 |
+
ctx.beginPath();
|
| 774 |
+
ctx.moveTo(s.pts[0][0] * W, s.pts[0][1] * H);
|
| 775 |
+
for (let i = 1; i < s.pts.length; i++) ctx.lineTo(s.pts[i][0] * W, s.pts[i][1] * H);
|
| 776 |
+
ctx.stroke();
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
function addStroke(s, isLocal){
|
| 780 |
+
strokes.push(s);
|
| 781 |
+
if (canvas.clientWidth) paintStroke(canvas.getContext('2d'), s);
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
function broadcastStroke(s){
|
| 785 |
+
if (isHost) relay({ t: 'stroke', stroke: s });
|
| 786 |
+
else if (hostConn && hostConn.open){ try { hostConn.send({ t: 'stroke', stroke: s }); } catch(e){} }
|
| 787 |
+
}
|
| 788 |
+
|
| 789 |
+
function broadcastClear(){
|
| 790 |
+
if (isHost) relay({ t: 'clear' });
|
| 791 |
+
else if (hostConn && hostConn.open){ try { hostConn.send({ t: 'clear' }); } catch(e){} }
|
| 792 |
+
}
|
| 793 |
+
|
| 794 |
+
/* ==========================================================
|
| 795 |
+
СОБЫТИЯ МЫШИ
|
| 796 |
+
========================================================== */
|
| 797 |
+
function stagePoint(e){
|
| 798 |
+
const r = stage.getBoundingClientRect();
|
| 799 |
+
return { x: (e.clientX - r.left) / r.width, y: (e.clientY - r.top) / r.height };
|
| 800 |
+
}
|
| 801 |
+
|
| 802 |
+
stage.addEventListener('pointermove', e => {
|
| 803 |
+
if (!inRoom) return;
|
| 804 |
+
const p = stagePoint(e);
|
| 805 |
+
if (p.x < 0 || p.x > 1 || p.y < 0 || p.y > 1) return;
|
| 806 |
+
|
| 807 |
+
localX = p.x; localY = p.y;
|
| 808 |
+
if (selfEntry && !interacting){
|
| 809 |
+
selfEntry.x = localX; selfEntry.y = localY;
|
| 810 |
+
placeEntry(selfEntry);
|
| 811 |
+
}
|
| 812 |
+
pushCursor(localX, localY);
|
| 813 |
+
|
| 814 |
+
if (roomType === 'sandbox' && curStroke){
|
| 815 |
+
curStroke.pts.push([p.x, p.y]);
|
| 816 |
+
redraw();
|
| 817 |
+
}
|
| 818 |
+
}, { passive: true });
|
| 819 |
+
|
| 820 |
+
stage.addEventListener('pointerleave', () => {
|
| 821 |
+
if (selfCursor) selfCursor.style.opacity = '0';
|
| 822 |
+
});
|
| 823 |
+
stage.addEventListener('pointerenter', () => {
|
| 824 |
+
if (selfCursor) selfCursor.style.opacity = '1';
|
| 825 |
+
});
|
| 826 |
+
|
| 827 |
+
canvas.addEventListener('pointerdown', e => {
|
| 828 |
+
if (roomType !== 'sandbox') return;
|
| 829 |
+
canvas.setPointerCapture(e.pointerId);
|
| 830 |
+
const p = stagePoint(e);
|
| 831 |
+
curStroke = { pts: [[p.x, p.y]], color: drawColor, w: 3 };
|
| 832 |
+
strokes.push(curStroke);
|
| 833 |
+
redraw();
|
| 834 |
+
});
|
| 835 |
+
|
| 836 |
+
function endStroke(){
|
| 837 |
+
if (!curStroke) return;
|
| 838 |
+
broadcastStroke(curStroke);
|
| 839 |
+
curStroke = null;
|
| 840 |
+
}
|
| 841 |
+
canvas.addEventListener('pointerup', endStroke);
|
| 842 |
+
canvas.addEventListener('pointercancel', endStroke);
|
| 843 |
+
|
| 844 |
+
/* ==========================================================
|
| 845 |
+
UI: ЛОББИ
|
| 846 |
+
========================================================== */
|
| 847 |
+
let chosenType = 'sandbox';
|
| 848 |
+
|
| 849 |
+
document.querySelectorAll('.type').forEach(btn => {
|
| 850 |
+
btn.addEventListener('click', () => {
|
| 851 |
+
document.querySelectorAll('.type').forEach(b => b.classList.remove('active'));
|
| 852 |
+
btn.classList.add('active');
|
| 853 |
+
chosenType = btn.dataset.type;
|
| 854 |
+
$('#urlField').classList.toggle('hidden', chosenType !== 'site');
|
| 855 |
+
});
|
| 856 |
+
});
|
| 857 |
+
|
| 858 |
+
$('#urlField').classList.add('hidden');
|
| 859 |
+
|
| 860 |
+
$('#createBtn').addEventListener('click', async () => {
|
| 861 |
+
const name = $('#nameInput').value.trim();
|
| 862 |
+
myName = (name || 'Гость').slice(0, 16);
|
| 863 |
+
myColor = randPick(PALETTE);
|
| 864 |
+
|
| 865 |
+
roomType = chosenType;
|
| 866 |
+
roomUrl = '';
|
| 867 |
+
if (roomType === 'site'){
|
| 868 |
+
let u = $('#urlInput').value.trim();
|
| 869 |
+
if (!u){ toast('Укажи адрес сайта', true); return; }
|
| 870 |
+
if (!/^https?:\/\//i.test(u)) u = 'https://' + u;
|
| 871 |
+
roomUrl = u;
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
const btn = $('#createBtn');
|
| 875 |
+
btn.disabled = true; btn.textContent = 'Создаю комнату…';
|
| 876 |
+
|
| 877 |
+
roomCode = genCode();
|
| 878 |
+
try {
|
| 879 |
+
await becomeHost();
|
| 880 |
+
enterRoom();
|
| 881 |
+
toast('Комната создана! Код: ' + roomCode);
|
| 882 |
+
} catch (e){
|
| 883 |
+
console.error(e);
|
| 884 |
+
if (e && e.type === 'all-servers-failed'){
|
| 885 |
+
toast('Не удалось подключиться к серверу. Проверь интернет или VPN.', true, 5000);
|
| 886 |
+
} else {
|
| 887 |
+
toast('Не удалось создать комнату.', true);
|
| 888 |
+
}
|
| 889 |
+
} finally {
|
| 890 |
+
btn.disabled = false; btn.textContent = 'Создать комнату';
|
| 891 |
+
}
|
| 892 |
+
});
|
| 893 |
+
|
| 894 |
+
$('#joinBtn').addEventListener('click', doJoin);
|
| 895 |
+
$('#codeInput').addEventListener('keydown', e => { if (e.key === 'Enter') doJoin(); });
|
| 896 |
+
|
| 897 |
+
async function doJoin(){
|
| 898 |
+
const name = $('#nameInput').value.trim();
|
| 899 |
+
myName = (name || 'Гость').slice(0, 16);
|
| 900 |
+
myColor = randPick(PALETTE);
|
| 901 |
+
|
| 902 |
+
const code = $('#codeInput').value.trim().toUpperCase();
|
| 903 |
+
if (code.length < 4){ toast('Введи код комнаты', true); return; }
|
| 904 |
+
|
| 905 |
+
roomCode = code;
|
| 906 |
+
const btn = $('#joinBtn');
|
| 907 |
+
btn.disabled = true; btn.textContent = 'Подключаюсь…';
|
| 908 |
+
|
| 909 |
+
try {
|
| 910 |
+
await becomeGuest(code);
|
| 911 |
+
enterRoom();
|
| 912 |
+
toast('Ты в комнате ' + code);
|
| 913 |
+
} catch (e){
|
| 914 |
+
console.error(e);
|
| 915 |
+
if (e && e.type === 'all-servers-failed'){
|
| 916 |
+
toast('Комната не найдена или сервер недоступен.', true, 4500);
|
| 917 |
+
} else {
|
| 918 |
+
toast('Ошибка подключения.', true);
|
| 919 |
+
}
|
| 920 |
+
try { if (peer) peer.destroy(); } catch(_){}
|
| 921 |
+
peer = null; hostConn = null;
|
| 922 |
+
} finally {
|
| 923 |
+
btn.disabled = false; btn.textContent = 'Войти';
|
| 924 |
+
}
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
/* ==========================================================
|
| 928 |
+
UI: КОМНАТА
|
| 929 |
+
========================================================== */
|
| 930 |
+
function enterRoom(){
|
| 931 |
+
if (inRoom) return;
|
| 932 |
+
inRoom = true;
|
| 933 |
+
|
| 934 |
+
$('#lobby').classList.add('hidden');
|
| 935 |
+
$('#room').classList.remove('hidden');
|
| 936 |
+
|
| 937 |
+
$('#codeText').textContent = roomCode;
|
| 938 |
+
$('#typeBadge').textContent = roomType === 'sandbox' ? '🎨 Sandbox' : '🌐 Site';
|
| 939 |
+
|
| 940 |
+
measure();
|
| 941 |
+
|
| 942 |
+
if (roomType === 'sandbox'){
|
| 943 |
+
sandboxEl.classList.remove('hidden');
|
| 944 |
+
siteFrame.classList.add('hidden');
|
| 945 |
+
capture.classList.add('hidden');
|
| 946 |
+
$('#modeToggle').classList.add('hidden');
|
| 947 |
+
$('#tools').classList.remove('hidden');
|
| 948 |
+
requestAnimationFrame(() => { resizeCanvas(); });
|
| 949 |
+
} else {
|
| 950 |
+
sandboxEl.classList.add('hidden');
|
| 951 |
+
siteFrame.classList.remove('hidden');
|
| 952 |
+
capture.classList.remove('hidden');
|
| 953 |
+
capture.classList.remove('off');
|
| 954 |
+
interacting = false;
|
| 955 |
+
$('#modeToggle').classList.remove('hidden');
|
| 956 |
+
$('#modeToggle').textContent = '🖱 Взаимодействие';
|
| 957 |
+
$('#tools').classList.add('hidden');
|
| 958 |
+
|
| 959 |
+
if (roomUrl){
|
| 960 |
+
try { siteFrame.src = roomUrl; } catch(e){ console.warn(e); }
|
| 961 |
+
}
|
| 962 |
+
|
| 963 |
+
if (IS_FILE){
|
| 964 |
+
toast('⚠️ Режим Site может не работать из file://. Запусти через локальный сервер.', true, 6000);
|
| 965 |
+
}
|
| 966 |
+
}
|
| 967 |
+
|
| 968 |
+
// свой курсор
|
| 969 |
+
selfCursor = makeCursorEl(myName + ' (вы)', myColor);
|
| 970 |
+
selfCursor.classList.add('self');
|
| 971 |
+
cursorLayer.appendChild(selfCursor);
|
| 972 |
+
selfEntry = { el: selfCursor, x: localX, y: localY };
|
| 973 |
+
placeEntry(selfEntry);
|
| 974 |
+
|
| 975 |
+
renderAvatars();
|
| 976 |
+
|
| 977 |
+
window.addEventListener('beforeunload', () => {
|
| 978 |
+
try {
|
| 979 |
+
if (isHost) relay({ t: 'bye', id: 'host' });
|
| 980 |
+
else if (hostConn && hostConn.open) hostConn.send({ t: 'bye', id: myId });
|
| 981 |
+
} catch(e){}
|
| 982 |
+
});
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
function leaveRoom(){
|
| 986 |
+
inRoom = false;
|
| 987 |
+
try {
|
| 988 |
+
if (isHost) relay({ t: 'bye', id: 'host' });
|
| 989 |
+
else if (hostConn && hostConn.open) hostConn.send({ t: 'bye', id: myId });
|
| 990 |
+
} catch(e){}
|
| 991 |
+
|
| 992 |
+
try { if (peer) peer.destroy(); } catch(e){}
|
| 993 |
+
peer = null; hostConn = null;
|
| 994 |
+
guests.clear();
|
| 995 |
+
cursors.forEach(c => c.el.remove());
|
| 996 |
+
cursors.clear();
|
| 997 |
+
if (selfCursor){ selfCursor.remove(); selfCursor = null; selfEntry = null; }
|
| 998 |
+
|
| 999 |
+
strokes.length = 0;
|
| 1000 |
+
curStroke = null;
|
| 1001 |
+
try { siteFrame.src = 'about:blank'; } catch(e){}
|
| 1002 |
+
|
| 1003 |
+
$('#room').classList.add('hidden');
|
| 1004 |
+
$('#lobby').classList.remove('hidden');
|
| 1005 |
+
setStatus(false);
|
| 1006 |
+
}
|
| 1007 |
+
|
| 1008 |
+
$('#leaveBtn').addEventListener('click', leaveRoom);
|
| 1009 |
+
|
| 1010 |
+
$('#codeChip').addEventListener('click', () => copy(roomCode, 'Код скопирован'));
|
| 1011 |
+
|
| 1012 |
+
$('#copyLink').addEventListener('click', () => {
|
| 1013 |
+
const base = location.href.split('?')[0].split('#')[0];
|
| 1014 |
+
const url = base + '?room=' + roomCode + '&s=' + currentHostIdx;
|
| 1015 |
+
if (IS_FILE){
|
| 1016 |
+
toast('Файл открыт локально — ссылка не откроется у друзей. Нужен хостинг.', true, 5000);
|
| 1017 |
+
copy(url, 'Ссылка скопирована (но file:// не откроется у друзей)');
|
| 1018 |
+
} else {
|
| 1019 |
+
copy(url, 'Ссылка-приглашение скопирована');
|
| 1020 |
+
}
|
| 1021 |
+
});
|
| 1022 |
+
|
| 1023 |
+
function copy(text, msg){
|
| 1024 |
+
const done = () => toast(msg);
|
| 1025 |
+
if (navigator.clipboard && navigator.clipboard.writeText){
|
| 1026 |
+
navigator.clipboard.writeText(text).then(done).catch(() => fallback());
|
| 1027 |
+
} else fallback();
|
| 1028 |
+
|
| 1029 |
+
function fallback(){
|
| 1030 |
+
const ta = document.createElement('textarea');
|
| 1031 |
+
ta.value = text;
|
| 1032 |
+
ta.style.position = 'fixed'; ta.style.opacity = '0';
|
| 1033 |
+
document.body.appendChild(ta); ta.select();
|
| 1034 |
+
try { document.execCommand('copy'); done(); } catch(e){ toast(text); }
|
| 1035 |
+
ta.remove();
|
| 1036 |
+
}
|
| 1037 |
+
}
|
| 1038 |
+
|
| 1039 |
+
$('#modeToggle').addEventListener('click', () => {
|
| 1040 |
+
interacting = !interacting;
|
| 1041 |
+
capture.classList.toggle('off', interacting);
|
| 1042 |
+
$('#modeToggle').textContent = interacting ? '🎯 Режим курсоров' : '🖱 Взаимодействие';
|
| 1043 |
+
if (selfCursor) selfCursor.style.opacity = interacting ? '0' : '1';
|
| 1044 |
+
toast(interacting ? 'Клики идут на сайт, твой курсор скрыт' : 'Курсоры снова видны');
|
| 1045 |
+
});
|
| 1046 |
+
|
| 1047 |
+
document.querySelectorAll('.sw').forEach(sw => {
|
| 1048 |
+
sw.addEventListener('click', () => {
|
| 1049 |
+
document.querySelectorAll('.sw').forEach(s => s.classList.remove('active'));
|
| 1050 |
+
sw.classList.add('active');
|
| 1051 |
+
drawColor = sw.dataset.color;
|
| 1052 |
+
});
|
| 1053 |
+
});
|
| 1054 |
+
|
| 1055 |
+
$('#clearBtn').addEventListener('click', () => {
|
| 1056 |
+
strokes.length = 0;
|
| 1057 |
+
redraw();
|
| 1058 |
+
broadcastClear();
|
| 1059 |
+
toast('Поле очищено');
|
| 1060 |
+
});
|
| 1061 |
+
|
| 1062 |
+
/* ==========================================================
|
| 1063 |
+
РЕСАЙЗ
|
| 1064 |
+
========================================================== */
|
| 1065 |
+
let rt = null;
|
| 1066 |
+
window.addEventListener('resize', () => {
|
| 1067 |
+
clearTimeout(rt);
|
| 1068 |
+
rt = setTimeout(() => {
|
| 1069 |
+
measure();
|
| 1070 |
+
cursors.forEach(placeEntry);
|
| 1071 |
+
if (selfEntry) placeEntry(selfEntry);
|
| 1072 |
+
if (roomType === 'sandbox' && inRoom) resizeCanvas();
|
| 1073 |
+
}, 90);
|
| 1074 |
+
});
|
| 1075 |
+
|
| 1076 |
+
/* ==========================================================
|
| 1077 |
+
СТАРТ
|
| 1078 |
+
========================================================== */
|
| 1079 |
+
(function init(){
|
| 1080 |
+
const params = new URLSearchParams(location.search);
|
| 1081 |
+
const r = params.get('room');
|
| 1082 |
+
const s = params.get('s');
|
| 1083 |
+
if (r){
|
| 1084 |
+
$('#codeInput').value = r.toUpperCase().slice(0, 6);
|
| 1085 |
+
if (s !== null){
|
| 1086 |
+
const si = parseInt(s, 10);
|
| 1087 |
+
if (si >= 0 && si < PEER_HOSTS.length) preferredHostIdx = si;
|
| 1088 |
+
}
|
| 1089 |
+
$('#nameInput').focus();
|
| 1090 |
+
setTimeout(() => toast('Введи имя и нажми «Войти»'), 400);
|
| 1091 |
+
} else {
|
| 1092 |
+
$('#nameInput').focus();
|
| 1093 |
+
}
|
| 1094 |
+
measure();
|
| 1095 |
+
|
| 1096 |
+
if (IS_FILE){
|
| 1097 |
+
setTimeout(() => {
|
| 1098 |
+
toast('💡 Файл открыт локально. Для работы с друзьями лучше залить на хостинг.', false, 6000);
|
| 1099 |
+
}, 800);
|
| 1100 |
+
}
|
| 1101 |
+
})();
|
| 1102 |
+
</script>
|
| 1103 |
+
</body>
|
| 1104 |
+
</html>
|