FunWith commited on
Commit
17c6267
Β·
verified Β·
1 Parent(s): 1c028a0

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. server.py +335 -5
  2. static/app.js +703 -17
  3. static/index.html +127 -1
  4. static/styles.css +390 -0
server.py CHANGED
@@ -1,6 +1,8 @@
1
  """
2
  Video Call Server - WebRTC Signaling via WebSockets
3
  Uses aiohttp for HTTP serving and WebSocket signaling.
 
 
4
  """
5
 
6
  import os
@@ -15,8 +17,18 @@ from aiohttp import web
15
  # ── Room State ────────────────────────────────────────────────────────────
16
  # rooms = { room_id: { peer_id: websocket, ... } }
17
  rooms: dict[str, dict[str, web.WebSocketResponse]] = {}
18
- # peer metadata: { peer_id: { "name": ..., "room": ... } }
19
  peers: dict[str, dict] = {}
 
 
 
 
 
 
 
 
 
 
20
 
21
  STATIC_DIR = Path(__file__).parent / "static"
22
 
@@ -34,6 +46,16 @@ async def room_page(request):
34
  async def create_room(request):
35
  room_id = uuid.uuid4().hex[:8]
36
  rooms[room_id] = {}
 
 
 
 
 
 
 
 
 
 
37
  return web.json_response({"room_id": room_id})
38
 
39
 
@@ -73,14 +95,54 @@ async def websocket_handler(request):
73
 
74
  if room_id not in rooms:
75
  rooms[room_id] = {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  # Register peer
78
  rooms[room_id][peer_id] = ws
79
- peers[peer_id] = {"name": name, "room": room_id}
80
 
81
  # Tell this peer about existing peers
82
  existing = [
83
- {"id": pid, "name": peers.get(pid, {}).get("name", "?")}
 
 
84
  for pid in rooms[room_id] if pid != peer_id
85
  ]
86
  await ws.send_json({
@@ -88,6 +150,8 @@ async def websocket_handler(request):
88
  "peer_id": peer_id,
89
  "peers": existing,
90
  "room_id": room_id,
 
 
91
  })
92
 
93
  # Notify others about the new peer
@@ -95,13 +159,29 @@ async def websocket_handler(request):
95
  "action": "peer-joined",
96
  "peer_id": peer_id,
97
  "name": name,
 
98
  }, exclude=peer_id)
99
 
100
- print(f"[{room_id}] {name} ({peer_id}) joined. "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  f"Room has {len(rooms[room_id])} peers.")
102
 
103
  elif action in ("offer", "answer", "ice-candidate"):
104
- # Relay signaling messages to specific peer
105
  target = data.get("target")
106
  if target and room_id and target in rooms.get(room_id, {}):
107
  target_ws = rooms[room_id][target]
@@ -123,11 +203,223 @@ async def websocket_handler(request):
123
  "time": datetime.utcnow().strftime("%H:%M"),
124
  })
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  elif msg.type == web.WSMsgType.ERROR:
127
  print(f"WebSocket error: {ws.exception()}")
128
 
129
  finally:
130
  # Clean up on disconnect
 
 
 
 
131
  if room_id and room_id in rooms:
132
  rooms[room_id].pop(peer_id, None)
133
  name = peers.get(peer_id, {}).get("name", "?")
@@ -139,9 +431,26 @@ async def websocket_handler(request):
139
  "peer_id": peer_id,
140
  })
141
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  # Clean up empty rooms
143
  if not rooms[room_id]:
144
  del rooms[room_id]
 
 
 
 
 
145
  print(f"[{room_id}] Room empty, removed.")
146
 
147
  peers.pop(peer_id, None)
@@ -149,6 +458,27 @@ async def websocket_handler(request):
149
  return ws
150
 
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  async def broadcast(room_id, message, exclude=None):
153
  """Send a message to all peers in a room, optionally excluding one."""
154
  if room_id not in rooms:
 
1
  """
2
  Video Call Server - WebRTC Signaling via WebSockets
3
  Uses aiohttp for HTTP serving and WebSocket signaling.
4
+ Zoom-like features: waiting room, host controls, hand raise, reactions,
5
+ breakout rooms, polls, whiteboard, participant management.
6
  """
7
 
8
  import os
 
17
  # ── Room State ────────────────────────────────────────────────────────────
18
  # rooms = { room_id: { peer_id: websocket, ... } }
19
  rooms: dict[str, dict[str, web.WebSocketResponse]] = {}
20
+ # peer metadata: { peer_id: { "name": ..., "room": ..., "role": ..., "hand": False } }
21
  peers: dict[str, dict] = {}
22
+ # room metadata: { room_id: { "host": peer_id, "waiting_room_enabled": bool, "locked": bool, ... } }
23
+ room_meta: dict[str, dict] = {}
24
+ # waiting room: { room_id: { peer_id: { "ws": ws, "name": name } } }
25
+ waiting_rooms: dict[str, dict] = {}
26
+ # polls: { room_id: [{ "id": str, "question": str, "options": [...], "votes": {peer_id: idx}, "active": bool }] }
27
+ room_polls: dict[str, list] = {}
28
+ # whiteboard: { room_id: [ {type, points, color, width} ] }
29
+ room_whiteboards: dict[str, list] = {}
30
+ # breakout rooms: { room_id: { "rooms": { sub_id: { "name": str, "peers": [peer_id] } }, "active": bool } }
31
+ room_breakouts: dict[str, dict] = {}
32
 
33
  STATIC_DIR = Path(__file__).parent / "static"
34
 
 
46
  async def create_room(request):
47
  room_id = uuid.uuid4().hex[:8]
48
  rooms[room_id] = {}
49
+ room_meta[room_id] = {
50
+ "host": None,
51
+ "waiting_room_enabled": False,
52
+ "locked": False,
53
+ "created": datetime.utcnow().isoformat(),
54
+ }
55
+ waiting_rooms[room_id] = {}
56
+ room_polls[room_id] = []
57
+ room_whiteboards[room_id] = []
58
+ room_breakouts[room_id] = {"rooms": {}, "active": False}
59
  return web.json_response({"room_id": room_id})
60
 
61
 
 
95
 
96
  if room_id not in rooms:
97
  rooms[room_id] = {}
98
+ room_meta[room_id] = {
99
+ "host": None,
100
+ "waiting_room_enabled": False,
101
+ "locked": False,
102
+ "created": datetime.utcnow().isoformat(),
103
+ }
104
+ waiting_rooms[room_id] = {}
105
+ room_polls[room_id] = []
106
+ room_whiteboards[room_id] = []
107
+ room_breakouts[room_id] = {"rooms": {}, "active": False}
108
+
109
+ meta = room_meta[room_id]
110
+
111
+ # Check if room is locked
112
+ if meta.get("locked") and meta.get("host"):
113
+ await ws.send_json({"action": "error", "message": "This meeting is locked"})
114
+ continue
115
+
116
+ # Check waiting room
117
+ if meta.get("waiting_room_enabled") and meta.get("host") and meta["host"] != peer_id:
118
+ waiting_rooms[room_id][peer_id] = {"ws": ws, "name": name}
119
+ await ws.send_json({"action": "waiting-room", "message": "Please wait for the host to admit you"})
120
+ # Notify host
121
+ host_id = meta["host"]
122
+ if host_id in rooms[room_id]:
123
+ await rooms[room_id][host_id].send_json({
124
+ "action": "waiting-room-update",
125
+ "waiting": [
126
+ {"id": pid, "name": winfo["name"]}
127
+ for pid, winfo in waiting_rooms[room_id].items()
128
+ ]
129
+ })
130
+ continue
131
+
132
+ # Assign host if first participant
133
+ is_host = not meta.get("host") or meta["host"] not in rooms.get(room_id, {})
134
+ if is_host:
135
+ meta["host"] = peer_id
136
 
137
  # Register peer
138
  rooms[room_id][peer_id] = ws
139
+ peers[peer_id] = {"name": name, "room": room_id, "role": "host" if is_host else "participant", "hand": False}
140
 
141
  # Tell this peer about existing peers
142
  existing = [
143
+ {"id": pid, "name": peers.get(pid, {}).get("name", "?"),
144
+ "role": peers.get(pid, {}).get("role", "participant"),
145
+ "hand": peers.get(pid, {}).get("hand", False)}
146
  for pid in rooms[room_id] if pid != peer_id
147
  ]
148
  await ws.send_json({
 
150
  "peer_id": peer_id,
151
  "peers": existing,
152
  "room_id": room_id,
153
+ "role": "host" if is_host else "participant",
154
+ "waiting_room_enabled": meta.get("waiting_room_enabled", False),
155
  })
156
 
157
  # Notify others about the new peer
 
159
  "action": "peer-joined",
160
  "peer_id": peer_id,
161
  "name": name,
162
+ "role": peers[peer_id]["role"],
163
  }, exclude=peer_id)
164
 
165
+ # Send existing whiteboard state
166
+ if room_whiteboards.get(room_id):
167
+ await ws.send_json({
168
+ "action": "whiteboard-sync",
169
+ "strokes": room_whiteboards[room_id],
170
+ })
171
+
172
+ # Send active polls
173
+ active_polls = [p for p in room_polls.get(room_id, []) if p.get("active")]
174
+ if active_polls:
175
+ for poll in active_polls:
176
+ await ws.send_json({
177
+ "action": "poll-started",
178
+ "poll": _sanitize_poll(poll, peer_id),
179
+ })
180
+
181
+ print(f"[{room_id}] {name} ({peer_id}) joined as {'host' if is_host else 'participant'}. "
182
  f"Room has {len(rooms[room_id])} peers.")
183
 
184
  elif action in ("offer", "answer", "ice-candidate"):
 
185
  target = data.get("target")
186
  if target and room_id and target in rooms.get(room_id, {}):
187
  target_ws = rooms[room_id][target]
 
203
  "time": datetime.utcnow().strftime("%H:%M"),
204
  })
205
 
206
+ # ── Hand Raise ────────────────────────────────────────
207
+ elif action == "hand-raise":
208
+ raised = data.get("raised", True)
209
+ if peer_id in peers:
210
+ peers[peer_id]["hand"] = raised
211
+ name = peers.get(peer_id, {}).get("name", "?")
212
+ await broadcast(room_id, {
213
+ "action": "hand-raise",
214
+ "peer_id": peer_id,
215
+ "name": name,
216
+ "raised": raised,
217
+ })
218
+
219
+ # ── Reactions ─────────────────────────────────────────
220
+ elif action == "reaction":
221
+ emoji = data.get("emoji", "")[:4]
222
+ if emoji and room_id:
223
+ name = peers.get(peer_id, {}).get("name", "?")
224
+ await broadcast(room_id, {
225
+ "action": "reaction",
226
+ "peer_id": peer_id,
227
+ "name": name,
228
+ "emoji": emoji,
229
+ })
230
+
231
+ # ── Waiting Room: Admit / Deny ────────────────────────
232
+ elif action == "admit-peer":
233
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
234
+ target_id = data.get("target")
235
+ if target_id in waiting_rooms.get(room_id, {}):
236
+ winfo = waiting_rooms[room_id].pop(target_id)
237
+ target_ws = winfo["ws"]
238
+ target_name = winfo["name"]
239
+
240
+ rooms[room_id][target_id] = target_ws
241
+ peers[target_id] = {"name": target_name, "room": room_id, "role": "participant", "hand": False}
242
+
243
+ existing = [
244
+ {"id": pid, "name": peers.get(pid, {}).get("name", "?"),
245
+ "role": peers.get(pid, {}).get("role", "participant"),
246
+ "hand": peers.get(pid, {}).get("hand", False)}
247
+ for pid in rooms[room_id] if pid != target_id
248
+ ]
249
+ await target_ws.send_json({
250
+ "action": "joined",
251
+ "peer_id": target_id,
252
+ "peers": existing,
253
+ "room_id": room_id,
254
+ "role": "participant",
255
+ "waiting_room_enabled": room_meta[room_id].get("waiting_room_enabled", False),
256
+ })
257
+ await broadcast(room_id, {
258
+ "action": "peer-joined",
259
+ "peer_id": target_id,
260
+ "name": target_name,
261
+ "role": "participant",
262
+ }, exclude=target_id)
263
+
264
+ elif action == "deny-peer":
265
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
266
+ target_id = data.get("target")
267
+ if target_id in waiting_rooms.get(room_id, {}):
268
+ winfo = waiting_rooms[room_id].pop(target_id)
269
+ await winfo["ws"].send_json({"action": "denied", "message": "The host denied your request to join"})
270
+
271
+ # ── Host Controls ─────────────────────────────────────
272
+ elif action == "toggle-waiting-room":
273
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
274
+ enabled = data.get("enabled", True)
275
+ room_meta[room_id]["waiting_room_enabled"] = enabled
276
+ await broadcast(room_id, {
277
+ "action": "setting-changed",
278
+ "setting": "waiting_room",
279
+ "value": enabled,
280
+ })
281
+
282
+ elif action == "lock-meeting":
283
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
284
+ locked = data.get("locked", True)
285
+ room_meta[room_id]["locked"] = locked
286
+ await broadcast(room_id, {
287
+ "action": "setting-changed",
288
+ "setting": "locked",
289
+ "value": locked,
290
+ })
291
+
292
+ elif action == "mute-peer":
293
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
294
+ target = data.get("target")
295
+ if target in rooms.get(room_id, {}):
296
+ await rooms[room_id][target].send_json({
297
+ "action": "muted-by-host",
298
+ "message": "The host muted you",
299
+ })
300
+
301
+ elif action == "kick-peer":
302
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
303
+ target = data.get("target")
304
+ if target in rooms.get(room_id, {}):
305
+ await rooms[room_id][target].send_json({
306
+ "action": "kicked",
307
+ "message": "You have been removed from the meeting",
308
+ })
309
+
310
+ elif action == "mute-all":
311
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
312
+ await broadcast(room_id, {
313
+ "action": "muted-by-host",
314
+ "message": "The host muted everyone",
315
+ }, exclude=peer_id)
316
+
317
+ elif action == "lower-all-hands":
318
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
319
+ for pid in rooms.get(room_id, {}):
320
+ if pid in peers:
321
+ peers[pid]["hand"] = False
322
+ await broadcast(room_id, {"action": "all-hands-lowered"})
323
+
324
+ # ── Polls ─────────────────────────────────────────────
325
+ elif action == "create-poll":
326
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
327
+ question = data.get("question", "").strip()[:200]
328
+ options = [o.strip()[:100] for o in data.get("options", []) if o.strip()][:10]
329
+ if question and len(options) >= 2:
330
+ poll = {
331
+ "id": uuid.uuid4().hex[:8],
332
+ "question": question,
333
+ "options": options,
334
+ "votes": {},
335
+ "active": True,
336
+ }
337
+ room_polls.setdefault(room_id, []).append(poll)
338
+ await broadcast(room_id, {
339
+ "action": "poll-started",
340
+ "poll": _sanitize_poll(poll, None),
341
+ })
342
+
343
+ elif action == "vote-poll":
344
+ poll_id = data.get("poll_id")
345
+ choice = data.get("choice")
346
+ polls = room_polls.get(room_id, [])
347
+ for poll in polls:
348
+ if poll["id"] == poll_id and poll["active"]:
349
+ if isinstance(choice, int) and 0 <= choice < len(poll["options"]):
350
+ poll["votes"][peer_id] = choice
351
+ await broadcast(room_id, {
352
+ "action": "poll-update",
353
+ "poll_id": poll_id,
354
+ "results": _poll_results(poll),
355
+ "total_votes": len(poll["votes"]),
356
+ })
357
+ break
358
+
359
+ elif action == "end-poll":
360
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
361
+ poll_id = data.get("poll_id")
362
+ for poll in room_polls.get(room_id, []):
363
+ if poll["id"] == poll_id:
364
+ poll["active"] = False
365
+ await broadcast(room_id, {
366
+ "action": "poll-ended",
367
+ "poll_id": poll_id,
368
+ "results": _poll_results(poll),
369
+ "total_votes": len(poll["votes"]),
370
+ })
371
+ break
372
+
373
+ # ── Whiteboard ────────────────────────────────────────
374
+ elif action == "whiteboard-stroke":
375
+ stroke = data.get("stroke")
376
+ if stroke and room_id:
377
+ room_whiteboards.setdefault(room_id, []).append(stroke)
378
+ # Limit stored strokes
379
+ if len(room_whiteboards[room_id]) > 5000:
380
+ room_whiteboards[room_id] = room_whiteboards[room_id][-3000:]
381
+ await broadcast(room_id, {
382
+ "action": "whiteboard-stroke",
383
+ "stroke": stroke,
384
+ "from": peer_id,
385
+ }, exclude=peer_id)
386
+
387
+ elif action == "whiteboard-clear":
388
+ if room_id:
389
+ room_whiteboards[room_id] = []
390
+ await broadcast(room_id, {"action": "whiteboard-clear"})
391
+
392
+ # ── Breakout Rooms ────────────────────────────────────
393
+ elif action == "create-breakout":
394
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
395
+ br_rooms = data.get("rooms", [])
396
+ breakout = {"rooms": {}, "active": True}
397
+ for br in br_rooms[:10]:
398
+ br_id = uuid.uuid4().hex[:6]
399
+ breakout["rooms"][br_id] = {
400
+ "name": br.get("name", f"Room {br_id}")[:30],
401
+ "peers": [p for p in br.get("peers", []) if p in rooms.get(room_id, {})],
402
+ }
403
+ room_breakouts[room_id] = breakout
404
+ await broadcast(room_id, {
405
+ "action": "breakout-started",
406
+ "rooms": {rid: {"name": r["name"], "peers": r["peers"]} for rid, r in breakout["rooms"].items()},
407
+ })
408
+
409
+ elif action == "end-breakout":
410
+ if room_id and room_meta.get(room_id, {}).get("host") == peer_id:
411
+ room_breakouts[room_id] = {"rooms": {}, "active": False}
412
+ await broadcast(room_id, {"action": "breakout-ended"})
413
+
414
  elif msg.type == web.WSMsgType.ERROR:
415
  print(f"WebSocket error: {ws.exception()}")
416
 
417
  finally:
418
  # Clean up on disconnect
419
+ # Remove from waiting room if applicable
420
+ if room_id and room_id in waiting_rooms:
421
+ waiting_rooms[room_id].pop(peer_id, None)
422
+
423
  if room_id and room_id in rooms:
424
  rooms[room_id].pop(peer_id, None)
425
  name = peers.get(peer_id, {}).get("name", "?")
 
431
  "peer_id": peer_id,
432
  })
433
 
434
+ # Transfer host if host left
435
+ if room_meta.get(room_id, {}).get("host") == peer_id and rooms[room_id]:
436
+ new_host = next(iter(rooms[room_id]))
437
+ room_meta[room_id]["host"] = new_host
438
+ if new_host in peers:
439
+ peers[new_host]["role"] = "host"
440
+ await broadcast(room_id, {
441
+ "action": "host-changed",
442
+ "new_host": new_host,
443
+ "name": peers.get(new_host, {}).get("name", "?"),
444
+ })
445
+
446
  # Clean up empty rooms
447
  if not rooms[room_id]:
448
  del rooms[room_id]
449
+ room_meta.pop(room_id, None)
450
+ waiting_rooms.pop(room_id, None)
451
+ room_polls.pop(room_id, None)
452
+ room_whiteboards.pop(room_id, None)
453
+ room_breakouts.pop(room_id, None)
454
  print(f"[{room_id}] Room empty, removed.")
455
 
456
  peers.pop(peer_id, None)
 
458
  return ws
459
 
460
 
461
+ def _sanitize_poll(poll, peer_id):
462
+ """Return poll data safe for sending to clients."""
463
+ return {
464
+ "id": poll["id"],
465
+ "question": poll["question"],
466
+ "options": poll["options"],
467
+ "results": _poll_results(poll),
468
+ "total_votes": len(poll["votes"]),
469
+ "active": poll["active"],
470
+ "my_vote": poll["votes"].get(peer_id) if peer_id else None,
471
+ }
472
+
473
+ def _poll_results(poll):
474
+ """Count votes per option."""
475
+ counts = [0] * len(poll["options"])
476
+ for choice in poll["votes"].values():
477
+ if 0 <= choice < len(counts):
478
+ counts[choice] += 1
479
+ return counts
480
+
481
+
482
  async def broadcast(room_id, message, exclude=None):
483
  """Send a message to all peers in a room, optionally excluding one."""
484
  if room_id not in rooms:
static/app.js CHANGED
@@ -16,6 +16,14 @@ let mediaRecorder = null;
16
  let recordedChunks = [];
17
  let recordingStartTime = null;
18
  let recordingTimerInterval = null;
 
 
 
 
 
 
 
 
19
 
20
  // Map of peer_id -> { pc: RTCPeerConnection, videoEl, tile, name }
21
  const peerConnections = {};
@@ -203,9 +211,9 @@ async function handleSignal(msg) {
203
  switch (msg.action) {
204
  case "joined":
205
  myPeerId = msg.peer_id;
206
- console.log("[me] My peer ID:", myPeerId);
 
207
  enterCallScreen();
208
- // Create peer connections to all existing peers (I am the initiator)
209
  for (const peer of msg.peers) {
210
  console.log("[init] Creating offer to existing peer:", peer.id, peer.name);
211
  await getOrCreatePeer(peer.id, peer.name);
@@ -215,24 +223,23 @@ async function handleSignal(msg) {
215
 
216
  case "peer-joined":
217
  showToast(`${msg.name} joined`);
218
- console.log("[peer-joined]", msg.peer_id, msg.name, "- waiting for their offer");
219
- // Just register the peer, don't create offer β€” they will send us one
220
  getOrCreatePeer(msg.peer_id, msg.name);
221
  updatePeerCount();
 
222
  break;
223
 
224
  case "peer-left":
225
  removePeer(msg.peer_id);
226
  updatePeerCount();
 
227
  break;
228
 
229
  case "offer":
230
- console.log("[offer] from", msg.from);
231
  await handleOffer(msg.from, msg.data);
232
  break;
233
 
234
  case "answer":
235
- console.log("[answer] from", msg.from);
236
  await handleAnswer(msg.from, msg.data);
237
  break;
238
 
@@ -248,6 +255,106 @@ async function handleSignal(msg) {
248
  case "error":
249
  showToast(msg.message);
250
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  }
252
  }
253
 
@@ -256,28 +363,36 @@ function enterCallScreen() {
256
  joinScreen.classList.remove("active");
257
  callScreen.classList.add("active");
258
 
259
- // Set local video
260
  if (localStream) {
261
  localVideo.srcObject = localStream;
262
- localVideo.muted = true; // Must stay muted to prevent echo
263
  }
264
  localVideoOff.style.display = camEnabled ? "none" : "";
265
  localName.textContent = `${myName} (You)`;
266
  localMicIndicator.textContent = micEnabled ? "🎀" : "πŸ”‡";
267
  localMicIndicator.classList.toggle("muted", !micEnabled);
268
 
269
- // Update URL
270
  history.replaceState(null, "", `/room/${roomId}`);
271
  document.title = `QuickMeet - ${roomId}`;
272
  roomInfo.textContent = `Room: ${roomId}`;
273
 
274
- // Sync button states
275
  micBtn.classList.toggle("active", micEnabled);
276
  camBtn.classList.toggle("active", camEnabled);
277
 
278
  setupCallControls();
279
  updateGridLayout();
280
  updatePeerCount();
 
 
 
 
 
 
 
 
 
 
 
281
  }
282
 
283
  // ── Call Control Listeners ───────────────────────────────────────────────
@@ -288,10 +403,12 @@ function setupCallControls() {
288
  recordBtn.addEventListener("click", toggleRecording);
289
  leaveBtn.addEventListener("click", leaveCall);
290
 
 
291
  chatBtn.addEventListener("click", () => {
292
  chatOpen = !chatOpen;
293
  chatPanel.classList.toggle("open", chatOpen);
294
  chatBtn.classList.toggle("active", chatOpen);
 
295
  if (chatOpen) chatInput.focus();
296
  });
297
 
@@ -314,6 +431,121 @@ function setupCallControls() {
314
  chatInput.addEventListener("keydown", (e) => {
315
  if (e.key === "Enter") sendChat();
316
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
 
319
  function toggleMic() {
@@ -394,36 +626,45 @@ function stopScreenShare() {
394
  }
395
 
396
  function leaveCall() {
397
- // Stop recording if active
398
  if (recording) stopRecording();
399
 
400
- // Close all peer connections
401
  for (const pid in peerConnections) {
402
  peerConnections[pid].pc.close();
403
  peerConnections[pid].tile.remove();
404
  delete peerConnections[pid];
405
  }
406
 
407
- if (ws) {
408
- ws.close();
409
- ws = null;
410
- }
411
 
412
  if (screenStream) {
413
  screenStream.getTracks().forEach(t => t.stop());
414
  screenStream = null;
415
  }
416
 
 
 
 
 
 
 
417
  screenSharing = false;
418
  chatOpen = false;
 
 
419
  chatPanel.classList.remove("open");
 
 
 
 
 
 
 
420
 
421
  callScreen.classList.remove("active");
422
  joinScreen.classList.add("active");
423
  history.replaceState(null, "", "/");
424
  document.title = "QuickMeet - Video Calls";
425
 
426
- // Restart preview
427
  if (localStream) {
428
  previewVideo.srcObject = localStream;
429
  }
@@ -816,3 +1057,448 @@ function showToast(message) {
816
  toast.classList.add("visible");
817
  setTimeout(() => toast.classList.remove("visible"), 3000);
818
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  let recordedChunks = [];
17
  let recordingStartTime = null;
18
  let recordingTimerInterval = null;
19
+ let myRole = "participant";
20
+ let handRaised = false;
21
+ let meetingStartTime = null;
22
+ let meetingTimerInterval = null;
23
+ let bgBlurEnabled = false;
24
+ let bgBlurCanvas = null;
25
+ let bgBlurCtx = null;
26
+ let bgBlurStream = null;
27
 
28
  // Map of peer_id -> { pc: RTCPeerConnection, videoEl, tile, name }
29
  const peerConnections = {};
 
211
  switch (msg.action) {
212
  case "joined":
213
  myPeerId = msg.peer_id;
214
+ myRole = msg.role || "participant";
215
+ console.log("[me] My peer ID:", myPeerId, "role:", myRole);
216
  enterCallScreen();
 
217
  for (const peer of msg.peers) {
218
  console.log("[init] Creating offer to existing peer:", peer.id, peer.name);
219
  await getOrCreatePeer(peer.id, peer.name);
 
223
 
224
  case "peer-joined":
225
  showToast(`${msg.name} joined`);
226
+ console.log("[peer-joined]", msg.peer_id, msg.name);
 
227
  getOrCreatePeer(msg.peer_id, msg.name);
228
  updatePeerCount();
229
+ updateParticipantList();
230
  break;
231
 
232
  case "peer-left":
233
  removePeer(msg.peer_id);
234
  updatePeerCount();
235
+ updateParticipantList();
236
  break;
237
 
238
  case "offer":
 
239
  await handleOffer(msg.from, msg.data);
240
  break;
241
 
242
  case "answer":
 
243
  await handleAnswer(msg.from, msg.data);
244
  break;
245
 
 
255
  case "error":
256
  showToast(msg.message);
257
  break;
258
+
259
+ // ── Waiting room ────────────────────────────────────
260
+ case "waiting-room":
261
+ showWaitingRoom(msg.message);
262
+ break;
263
+
264
+ case "waiting-room-update":
265
+ updateWaitingList(msg.waiting);
266
+ break;
267
+
268
+ case "denied":
269
+ showToast(msg.message);
270
+ leaveCall();
271
+ break;
272
+
273
+ // ── Hand raise ──────────────────────────────────────
274
+ case "hand-raise":
275
+ handleHandRaise(msg.peer_id, msg.name, msg.raised);
276
+ break;
277
+
278
+ case "all-hands-lowered":
279
+ handleAllHandsLowered();
280
+ break;
281
+
282
+ // ── Reactions ───────────────────────────────────────
283
+ case "reaction":
284
+ showReaction(msg.emoji, msg.name);
285
+ break;
286
+
287
+ // ── Host controls ───────────────────────────────────
288
+ case "host-changed":
289
+ if (msg.new_host === myPeerId) {
290
+ myRole = "host";
291
+ showToast("You are now the host");
292
+ showHostControls();
293
+ } else {
294
+ showToast(`${msg.name} is now the host`);
295
+ }
296
+ updateParticipantList();
297
+ break;
298
+
299
+ case "muted-by-host":
300
+ micEnabled = false;
301
+ micBtn.classList.remove("active");
302
+ if (localStream) localStream.getAudioTracks().forEach(t => t.enabled = false);
303
+ localMicIndicator.textContent = "πŸ”‡";
304
+ localMicIndicator.classList.add("muted");
305
+ showToast(msg.message);
306
+ break;
307
+
308
+ case "kicked":
309
+ showToast(msg.message);
310
+ leaveCall();
311
+ break;
312
+
313
+ case "setting-changed":
314
+ showToast(`${msg.setting.replace('_', ' ')} ${msg.value ? 'enabled' : 'disabled'}`);
315
+ if (msg.setting === "waiting_room") {
316
+ const toggle = document.getElementById("waitingRoomToggle");
317
+ if (toggle) toggle.checked = msg.value;
318
+ }
319
+ break;
320
+
321
+ // ── Polls ───────────────────────────────────────────
322
+ case "poll-started":
323
+ renderPoll(msg.poll);
324
+ showToast("New poll started!");
325
+ break;
326
+
327
+ case "poll-update":
328
+ updatePollResults(msg.poll_id, msg.results, msg.total_votes);
329
+ break;
330
+
331
+ case "poll-ended":
332
+ endPollDisplay(msg.poll_id, msg.results, msg.total_votes);
333
+ break;
334
+
335
+ // ── Whiteboard ──────────────────────────────────────
336
+ case "whiteboard-sync":
337
+ replayWhiteboardStrokes(msg.strokes);
338
+ break;
339
+
340
+ case "whiteboard-stroke":
341
+ drawRemoteStroke(msg.stroke);
342
+ break;
343
+
344
+ case "whiteboard-clear":
345
+ clearWhiteboardLocal();
346
+ break;
347
+
348
+ // ── Breakout rooms ──────────────────────────────────
349
+ case "breakout-started":
350
+ showToast("Breakout rooms started!");
351
+ renderBreakoutActive(msg.rooms);
352
+ break;
353
+
354
+ case "breakout-ended":
355
+ showToast("Breakout rooms ended");
356
+ hideBreakoutActive();
357
+ break;
358
  }
359
  }
360
 
 
363
  joinScreen.classList.remove("active");
364
  callScreen.classList.add("active");
365
 
 
366
  if (localStream) {
367
  localVideo.srcObject = localStream;
368
+ localVideo.muted = true;
369
  }
370
  localVideoOff.style.display = camEnabled ? "none" : "";
371
  localName.textContent = `${myName} (You)`;
372
  localMicIndicator.textContent = micEnabled ? "🎀" : "πŸ”‡";
373
  localMicIndicator.classList.toggle("muted", !micEnabled);
374
 
 
375
  history.replaceState(null, "", `/room/${roomId}`);
376
  document.title = `QuickMeet - ${roomId}`;
377
  roomInfo.textContent = `Room: ${roomId}`;
378
 
 
379
  micBtn.classList.toggle("active", micEnabled);
380
  camBtn.classList.toggle("active", camEnabled);
381
 
382
  setupCallControls();
383
  updateGridLayout();
384
  updatePeerCount();
385
+ updateParticipantList();
386
+
387
+ // Start meeting timer
388
+ meetingStartTime = Date.now();
389
+ meetingTimerInterval = setInterval(updateMeetingTimer, 1000);
390
+ updateMeetingTimer();
391
+
392
+ // Show host controls if host
393
+ if (myRole === "host") {
394
+ showHostControls();
395
+ }
396
  }
397
 
398
  // ── Call Control Listeners ───────────────────────────────────────────────
 
403
  recordBtn.addEventListener("click", toggleRecording);
404
  leaveBtn.addEventListener("click", leaveCall);
405
 
406
+ // Chat
407
  chatBtn.addEventListener("click", () => {
408
  chatOpen = !chatOpen;
409
  chatPanel.classList.toggle("open", chatOpen);
410
  chatBtn.classList.toggle("active", chatOpen);
411
+ closeSidePanels("chatPanel");
412
  if (chatOpen) chatInput.focus();
413
  });
414
 
 
431
  chatInput.addEventListener("keydown", (e) => {
432
  if (e.key === "Enter") sendChat();
433
  });
434
+
435
+ // Hand raise
436
+ document.getElementById("handBtn").addEventListener("click", toggleHandRaise);
437
+
438
+ // Reactions
439
+ document.querySelectorAll(".reaction-btn").forEach(btn => {
440
+ btn.addEventListener("click", () => {
441
+ if (ws) ws.send(JSON.stringify({ action: "reaction", emoji: btn.dataset.emoji }));
442
+ });
443
+ });
444
+
445
+ // Participants panel
446
+ document.getElementById("participantsBtn").addEventListener("click", () => {
447
+ const panel = document.getElementById("participantsPanel");
448
+ const open = !panel.classList.contains("open");
449
+ closeSidePanels("participantsPanel");
450
+ panel.classList.toggle("open", open);
451
+ document.getElementById("participantsBtn").classList.toggle("active", open);
452
+ if (open) updateParticipantList();
453
+ });
454
+ document.getElementById("closeParticipantsBtn").addEventListener("click", () => {
455
+ document.getElementById("participantsPanel").classList.remove("open");
456
+ document.getElementById("participantsBtn").classList.remove("active");
457
+ });
458
+
459
+ // Host controls
460
+ document.getElementById("muteAllBtn").addEventListener("click", () => {
461
+ if (ws) ws.send(JSON.stringify({ action: "mute-all" }));
462
+ });
463
+ document.getElementById("lowerAllHandsBtn").addEventListener("click", () => {
464
+ if (ws) ws.send(JSON.stringify({ action: "lower-all-hands" }));
465
+ });
466
+ document.getElementById("waitingRoomToggle").addEventListener("change", (e) => {
467
+ if (ws) ws.send(JSON.stringify({ action: "toggle-waiting-room", enabled: e.target.checked }));
468
+ });
469
+ document.getElementById("lockMeetingToggle").addEventListener("change", (e) => {
470
+ if (ws) ws.send(JSON.stringify({ action: "lock-meeting", locked: e.target.checked }));
471
+ });
472
+
473
+ // Waiting room leave
474
+ document.getElementById("waitingLeaveBtn").addEventListener("click", leaveCall);
475
+
476
+ // Whiteboard
477
+ document.getElementById("whiteboardBtn").addEventListener("click", () => {
478
+ const panel = document.getElementById("whiteboardPanel");
479
+ const open = !panel.classList.contains("open");
480
+ closeSidePanels("whiteboardPanel");
481
+ panel.classList.toggle("open", open);
482
+ if (open) initWhiteboard();
483
+ });
484
+ document.getElementById("closeWhiteboardBtn").addEventListener("click", () => {
485
+ document.getElementById("whiteboardPanel").classList.remove("open");
486
+ });
487
+
488
+ // Polls
489
+ document.getElementById("pollsBtn").addEventListener("click", () => {
490
+ const panel = document.getElementById("pollsPanel");
491
+ const open = !panel.classList.contains("open");
492
+ closeSidePanels("pollsPanel");
493
+ panel.classList.toggle("open", open);
494
+ if (open && myRole === "host") {
495
+ document.getElementById("createPollSection").style.display = "block";
496
+ }
497
+ });
498
+ document.getElementById("closePollsBtn").addEventListener("click", () => {
499
+ document.getElementById("pollsPanel").classList.remove("open");
500
+ });
501
+ document.getElementById("addPollOption").addEventListener("click", () => {
502
+ const container = document.getElementById("pollOptionsContainer");
503
+ const count = container.children.length + 1;
504
+ const input = document.createElement("input");
505
+ input.type = "text";
506
+ input.className = "poll-option-input";
507
+ input.placeholder = `Option ${count}`;
508
+ input.maxLength = 100;
509
+ container.appendChild(input);
510
+ });
511
+ document.getElementById("launchPollBtn").addEventListener("click", () => {
512
+ const question = document.getElementById("pollQuestion").value.trim();
513
+ const options = [...document.querySelectorAll(".poll-option-input")]
514
+ .map(i => i.value.trim()).filter(Boolean);
515
+ if (!question || options.length < 2) {
516
+ showToast("Need a question and at least 2 options");
517
+ return;
518
+ }
519
+ if (ws) ws.send(JSON.stringify({ action: "create-poll", question, options }));
520
+ document.getElementById("pollQuestion").value = "";
521
+ document.querySelectorAll(".poll-option-input").forEach((i, idx) => {
522
+ i.value = "";
523
+ if (idx >= 2) i.remove();
524
+ });
525
+ });
526
+
527
+ // Breakout rooms
528
+ document.getElementById("breakoutBtn").addEventListener("click", () => {
529
+ const panel = document.getElementById("breakoutPanel");
530
+ const open = !panel.classList.contains("open");
531
+ closeSidePanels("breakoutPanel");
532
+ panel.classList.toggle("open", open);
533
+ if (open && myRole === "host") {
534
+ document.getElementById("breakoutSetup").style.display = "block";
535
+ initBreakoutSetup();
536
+ }
537
+ });
538
+ document.getElementById("closeBreakoutBtn").addEventListener("click", () => {
539
+ document.getElementById("breakoutPanel").classList.remove("open");
540
+ });
541
+ document.getElementById("addBreakoutRoom").addEventListener("click", addBreakoutRoomRow);
542
+ document.getElementById("startBreakoutBtn").addEventListener("click", startBreakout);
543
+ document.getElementById("endBreakoutBtn").addEventListener("click", () => {
544
+ if (ws) ws.send(JSON.stringify({ action: "end-breakout" }));
545
+ });
546
+
547
+ // Background blur
548
+ document.getElementById("bgBlurBtn").addEventListener("click", toggleBgBlur);
549
  }
550
 
551
  function toggleMic() {
 
626
  }
627
 
628
  function leaveCall() {
 
629
  if (recording) stopRecording();
630
 
 
631
  for (const pid in peerConnections) {
632
  peerConnections[pid].pc.close();
633
  peerConnections[pid].tile.remove();
634
  delete peerConnections[pid];
635
  }
636
 
637
+ if (ws) { ws.close(); ws = null; }
 
 
 
638
 
639
  if (screenStream) {
640
  screenStream.getTracks().forEach(t => t.stop());
641
  screenStream = null;
642
  }
643
 
644
+ if (bgBlurStream) {
645
+ bgBlurStream.getTracks().forEach(t => t.stop());
646
+ bgBlurStream = null;
647
+ }
648
+ bgBlurEnabled = false;
649
+
650
  screenSharing = false;
651
  chatOpen = false;
652
+ handRaised = false;
653
+ myRole = "participant";
654
  chatPanel.classList.remove("open");
655
+ document.querySelectorAll(".side-panel").forEach(p => p.classList.remove("open"));
656
+
657
+ clearInterval(meetingTimerInterval);
658
+ meetingTimerInterval = null;
659
+
660
+ // Hide waiting room overlay
661
+ document.getElementById("waitingRoomOverlay").style.display = "none";
662
 
663
  callScreen.classList.remove("active");
664
  joinScreen.classList.add("active");
665
  history.replaceState(null, "", "/");
666
  document.title = "QuickMeet - Video Calls";
667
 
 
668
  if (localStream) {
669
  previewVideo.srcObject = localStream;
670
  }
 
1057
  toast.classList.add("visible");
1058
  setTimeout(() => toast.classList.remove("visible"), 3000);
1059
  }
1060
+
1061
+ // ═══════════════════════════════════════════════════════════════════════════
1062
+ // NEW ZOOM-LIKE FEATURES
1063
+ // ═══════════════════════════════════════════════════════════════════════════
1064
+
1065
+ // ── Side Panel Helper ───────────────────────────────────────────────────
1066
+ function closeSidePanels(except) {
1067
+ const panels = ["chatPanel", "participantsPanel", "whiteboardPanel", "pollsPanel", "breakoutPanel"];
1068
+ panels.forEach(id => {
1069
+ if (id !== except) document.getElementById(id).classList.remove("open");
1070
+ });
1071
+ if (except !== "chatPanel") { chatOpen = false; chatBtn.classList.remove("active"); }
1072
+ }
1073
+
1074
+ // ── Meeting Timer ───────────────────────────────────────────────────────
1075
+ function updateMeetingTimer() {
1076
+ if (!meetingStartTime) return;
1077
+ const elapsed = Math.floor((Date.now() - meetingStartTime) / 1000);
1078
+ const h = Math.floor(elapsed / 3600);
1079
+ const m = String(Math.floor((elapsed % 3600) / 60)).padStart(2, "0");
1080
+ const s = String(elapsed % 60).padStart(2, "0");
1081
+ const el = document.getElementById("meetingTimer");
1082
+ if (el) el.textContent = h > 0 ? `${h}:${m}:${s}` : `${m}:${s}`;
1083
+ }
1084
+
1085
+ // ── Host Controls ───────────────────────────────────────────────────────
1086
+ function showHostControls() {
1087
+ const el = document.getElementById("hostControls");
1088
+ if (el) el.style.display = "flex";
1089
+ const createPoll = document.getElementById("createPollSection");
1090
+ if (createPoll) createPoll.style.display = "block";
1091
+ const breakout = document.getElementById("breakoutSetup");
1092
+ if (breakout) breakout.style.display = "block";
1093
+ }
1094
+
1095
+ // ── Hand Raise ──────────────────────────────────────────────────────────
1096
+ function toggleHandRaise() {
1097
+ handRaised = !handRaised;
1098
+ const btn = document.getElementById("handBtn");
1099
+ btn.classList.toggle("raised", handRaised);
1100
+ document.getElementById("localHand").style.display = handRaised ? "" : "none";
1101
+ if (ws) ws.send(JSON.stringify({ action: "hand-raise", raised: handRaised }));
1102
+ showToast(handRaised ? "Hand raised" : "Hand lowered");
1103
+ }
1104
+
1105
+ function handleHandRaise(peerId, name, raised) {
1106
+ const conn = peerConnections[peerId];
1107
+ if (conn) {
1108
+ let indicator = conn.tile.querySelector(".hand-indicator");
1109
+ if (!indicator) {
1110
+ indicator = document.createElement("div");
1111
+ indicator.className = "hand-indicator";
1112
+ indicator.textContent = "βœ‹";
1113
+ conn.tile.appendChild(indicator);
1114
+ }
1115
+ indicator.style.display = raised ? "" : "none";
1116
+ conn.hand = raised;
1117
+ }
1118
+ if (raised) showToast(`${name} raised hand βœ‹`);
1119
+ updateParticipantList();
1120
+ }
1121
+
1122
+ function handleAllHandsLowered() {
1123
+ handRaised = false;
1124
+ document.getElementById("handBtn").classList.remove("raised");
1125
+ document.getElementById("localHand").style.display = "none";
1126
+ for (const pid in peerConnections) {
1127
+ peerConnections[pid].hand = false;
1128
+ const indicator = peerConnections[pid].tile.querySelector(".hand-indicator");
1129
+ if (indicator) indicator.style.display = "none";
1130
+ }
1131
+ showToast("All hands lowered");
1132
+ updateParticipantList();
1133
+ }
1134
+
1135
+ // ── Reactions ───────────────────────────────────────────────────────────
1136
+ function showReaction(emoji, name) {
1137
+ const overlay = document.getElementById("reactionsOverlay");
1138
+ const el = document.createElement("div");
1139
+ el.className = "reaction-float";
1140
+ el.textContent = emoji;
1141
+ el.style.left = Math.random() * 250 + "px";
1142
+ overlay.appendChild(el);
1143
+ setTimeout(() => el.remove(), 2600);
1144
+ }
1145
+
1146
+ // ── Waiting Room ────────────────────────────────────────────────────────
1147
+ function showWaitingRoom(message) {
1148
+ joinScreen.classList.remove("active");
1149
+ callScreen.classList.add("active");
1150
+ document.getElementById("waitingRoomOverlay").style.display = "flex";
1151
+ document.getElementById("waitingRoomMsg").textContent = message;
1152
+ }
1153
+
1154
+ function updateWaitingList(waiting) {
1155
+ const container = document.getElementById("waitingListContent");
1156
+ const wrapper = document.getElementById("waitingList");
1157
+ if (!waiting || !waiting.length) {
1158
+ wrapper.style.display = "none";
1159
+ return;
1160
+ }
1161
+ wrapper.style.display = "block";
1162
+ container.innerHTML = waiting.map(w => `
1163
+ <div class="waiting-item">
1164
+ <span class="w-name">${escapeHtml(w.name)}</span>
1165
+ <button class="btn-admit" onclick="admitPeer('${w.id}')">Admit</button>
1166
+ <button class="btn-deny" onclick="denyPeer('${w.id}')">Deny</button>
1167
+ </div>
1168
+ `).join("");
1169
+ }
1170
+
1171
+ function admitPeer(targetId) {
1172
+ if (ws) ws.send(JSON.stringify({ action: "admit-peer", target: targetId }));
1173
+ }
1174
+
1175
+ function denyPeer(targetId) {
1176
+ if (ws) ws.send(JSON.stringify({ action: "deny-peer", target: targetId }));
1177
+ }
1178
+
1179
+ // ── Participant List ────────────────────────────────────────────────────
1180
+ function updateParticipantList() {
1181
+ const list = document.getElementById("participantList");
1182
+ if (!list) return;
1183
+
1184
+ const count = Object.keys(peerConnections).length + 1;
1185
+ document.getElementById("participantCountTitle").textContent = `In Meeting (${count})`;
1186
+
1187
+ let html = `
1188
+ <div class="participant-item">
1189
+ <span class="p-name">${escapeHtml(myName)} (You)</span>
1190
+ ${myRole === "host" ? '<span class="p-role">Host</span>' : ""}
1191
+ ${handRaised ? '<span class="p-hand">βœ‹</span>' : ""}
1192
+ </div>
1193
+ `;
1194
+
1195
+ for (const pid in peerConnections) {
1196
+ const c = peerConnections[pid];
1197
+ const isHost = false; // Server tracks this, simplified here
1198
+ html += `
1199
+ <div class="participant-item">
1200
+ <span class="p-name">${escapeHtml(c.name || "Peer")}</span>
1201
+ ${c.hand ? '<span class="p-hand">βœ‹</span>' : ""}
1202
+ ${myRole === "host" ? `
1203
+ <span class="p-actions">
1204
+ <button onclick="mutePeer('${pid}')" title="Mute"><span class="material-icons-round" style="font-size:16px">mic_off</span></button>
1205
+ <button onclick="kickPeer('${pid}')" title="Remove"><span class="material-icons-round" style="font-size:16px">person_remove</span></button>
1206
+ </span>
1207
+ ` : ""}
1208
+ </div>
1209
+ `;
1210
+ }
1211
+ list.innerHTML = html;
1212
+ }
1213
+
1214
+ function mutePeer(targetId) {
1215
+ if (ws) ws.send(JSON.stringify({ action: "mute-peer", target: targetId }));
1216
+ }
1217
+
1218
+ function kickPeer(targetId) {
1219
+ if (ws) ws.send(JSON.stringify({ action: "kick-peer", target: targetId }));
1220
+ }
1221
+
1222
+ // ── Polls ───────────────────────────────────────────────────────────────
1223
+ const activePolls = {};
1224
+
1225
+ function renderPoll(poll) {
1226
+ activePolls[poll.id] = poll;
1227
+ const container = document.getElementById("activePollsList");
1228
+ let card = document.getElementById(`poll-${poll.id}`);
1229
+ if (!card) {
1230
+ card = document.createElement("div");
1231
+ card.id = `poll-${poll.id}`;
1232
+ card.className = "poll-card";
1233
+ container.prepend(card);
1234
+ }
1235
+
1236
+ const total = poll.total_votes || 0;
1237
+ const results = poll.results || poll.options.map(() => 0);
1238
+
1239
+ card.innerHTML = `
1240
+ <h4>${escapeHtml(poll.question)}</h4>
1241
+ ${poll.options.map((opt, i) => {
1242
+ const count = results[i] || 0;
1243
+ const pct = total > 0 ? Math.round(count / total * 100) : 0;
1244
+ const voted = poll.my_vote === i;
1245
+ return `
1246
+ <div class="poll-option-row ${voted ? 'voted' : ''}" onclick="votePoll('${poll.id}', ${i})">
1247
+ <span class="poll-option-text">${escapeHtml(opt)}</span>
1248
+ <div class="poll-bar"><div class="poll-bar-fill" style="width:${pct}%"></div></div>
1249
+ <span class="poll-option-pct">${pct}%</span>
1250
+ </div>
1251
+ `;
1252
+ }).join("")}
1253
+ <div class="poll-total">${total} vote${total !== 1 ? 's' : ''}</div>
1254
+ ${myRole === "host" && poll.active ? `<button class="btn btn-small btn-outline" style="margin-top:8px;width:100%" onclick="endPoll('${poll.id}')">End Poll</button>` : ""}
1255
+ ${!poll.active ? '<div style="color:var(--text-hint);font-size:12px;margin-top:4px">Poll ended</div>' : ""}
1256
+ `;
1257
+ }
1258
+
1259
+ function votePoll(pollId, choice) {
1260
+ if (ws) ws.send(JSON.stringify({ action: "vote-poll", poll_id: pollId, choice }));
1261
+ if (activePolls[pollId]) activePolls[pollId].my_vote = choice;
1262
+ }
1263
+
1264
+ function endPoll(pollId) {
1265
+ if (ws) ws.send(JSON.stringify({ action: "end-poll", poll_id: pollId }));
1266
+ }
1267
+
1268
+ function updatePollResults(pollId, results, totalVotes) {
1269
+ if (activePolls[pollId]) {
1270
+ activePolls[pollId].results = results;
1271
+ activePolls[pollId].total_votes = totalVotes;
1272
+ renderPoll(activePolls[pollId]);
1273
+ }
1274
+ }
1275
+
1276
+ function endPollDisplay(pollId, results, totalVotes) {
1277
+ if (activePolls[pollId]) {
1278
+ activePolls[pollId].active = false;
1279
+ activePolls[pollId].results = results;
1280
+ activePolls[pollId].total_votes = totalVotes;
1281
+ renderPoll(activePolls[pollId]);
1282
+ }
1283
+ }
1284
+
1285
+ // ── Whiteboard ──────────────────────────────────────────────────────────
1286
+ let wbDrawing = false;
1287
+ let wbCurrentStroke = null;
1288
+ let wbEraser = false;
1289
+
1290
+ function initWhiteboard() {
1291
+ const canvas = document.getElementById("whiteboardCanvas");
1292
+ if (canvas._initialized) return;
1293
+ canvas._initialized = true;
1294
+
1295
+ const ctx = canvas.getContext("2d");
1296
+ ctx.lineCap = "round";
1297
+ ctx.lineJoin = "round";
1298
+
1299
+ canvas.addEventListener("pointerdown", (e) => {
1300
+ wbDrawing = true;
1301
+ const rect = canvas.getBoundingClientRect();
1302
+ const x = (e.clientX - rect.left) / rect.width * canvas.width;
1303
+ const y = (e.clientY - rect.top) / rect.height * canvas.height;
1304
+ const color = wbEraser ? "#ffffff" : document.getElementById("wbColor").value;
1305
+ const width = wbEraser ? 20 : parseInt(document.getElementById("wbSize").value);
1306
+ wbCurrentStroke = { points: [[x, y]], color, width };
1307
+ ctx.strokeStyle = color;
1308
+ ctx.lineWidth = width;
1309
+ ctx.beginPath();
1310
+ ctx.moveTo(x, y);
1311
+ });
1312
+
1313
+ canvas.addEventListener("pointermove", (e) => {
1314
+ if (!wbDrawing || !wbCurrentStroke) return;
1315
+ const rect = canvas.getBoundingClientRect();
1316
+ const x = (e.clientX - rect.left) / rect.width * canvas.width;
1317
+ const y = (e.clientY - rect.top) / rect.height * canvas.height;
1318
+ wbCurrentStroke.points.push([x, y]);
1319
+ const ctx2 = canvas.getContext("2d");
1320
+ ctx2.strokeStyle = wbCurrentStroke.color;
1321
+ ctx2.lineWidth = wbCurrentStroke.width;
1322
+ ctx2.lineTo(x, y);
1323
+ ctx2.stroke();
1324
+ });
1325
+
1326
+ const endDraw = () => {
1327
+ if (wbDrawing && wbCurrentStroke && wbCurrentStroke.points.length > 1) {
1328
+ if (ws) ws.send(JSON.stringify({ action: "whiteboard-stroke", stroke: wbCurrentStroke }));
1329
+ }
1330
+ wbDrawing = false;
1331
+ wbCurrentStroke = null;
1332
+ };
1333
+ canvas.addEventListener("pointerup", endDraw);
1334
+ canvas.addEventListener("pointerleave", endDraw);
1335
+
1336
+ document.getElementById("wbEraser").addEventListener("click", () => {
1337
+ wbEraser = !wbEraser;
1338
+ document.getElementById("wbEraser").classList.toggle("active", wbEraser);
1339
+ canvas.style.cursor = wbEraser ? "cell" : "crosshair";
1340
+ });
1341
+
1342
+ document.getElementById("wbClear").addEventListener("click", () => {
1343
+ if (ws) ws.send(JSON.stringify({ action: "whiteboard-clear" }));
1344
+ clearWhiteboardLocal();
1345
+ });
1346
+ }
1347
+
1348
+ function drawRemoteStroke(stroke) {
1349
+ const canvas = document.getElementById("whiteboardCanvas");
1350
+ const ctx = canvas.getContext("2d");
1351
+ if (!stroke.points || stroke.points.length < 2) return;
1352
+ ctx.strokeStyle = stroke.color || "#000";
1353
+ ctx.lineWidth = stroke.width || 3;
1354
+ ctx.lineCap = "round";
1355
+ ctx.lineJoin = "round";
1356
+ ctx.beginPath();
1357
+ ctx.moveTo(stroke.points[0][0], stroke.points[0][1]);
1358
+ for (let i = 1; i < stroke.points.length; i++) {
1359
+ ctx.lineTo(stroke.points[i][0], stroke.points[i][1]);
1360
+ }
1361
+ ctx.stroke();
1362
+ }
1363
+
1364
+ function replayWhiteboardStrokes(strokes) {
1365
+ const canvas = document.getElementById("whiteboardCanvas");
1366
+ const ctx = canvas.getContext("2d");
1367
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
1368
+ for (const stroke of strokes) drawRemoteStroke(stroke);
1369
+ }
1370
+
1371
+ function clearWhiteboardLocal() {
1372
+ const canvas = document.getElementById("whiteboardCanvas");
1373
+ const ctx = canvas.getContext("2d");
1374
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
1375
+ }
1376
+
1377
+ // ── Breakout Rooms ──────────────────────────────────────────────────────
1378
+ function initBreakoutSetup() {
1379
+ const container = document.getElementById("breakoutRoomsList");
1380
+ if (container.children.length === 0) {
1381
+ addBreakoutRoomRow();
1382
+ addBreakoutRoomRow();
1383
+ }
1384
+ }
1385
+
1386
+ function addBreakoutRoomRow() {
1387
+ const container = document.getElementById("breakoutRoomsList");
1388
+ const idx = container.children.length + 1;
1389
+ const row = document.createElement("div");
1390
+ row.className = "breakout-room-row";
1391
+ row.innerHTML = `
1392
+ <input type="text" value="Room ${idx}" placeholder="Room name" maxlength="30">
1393
+ <div class="br-peers"></div>
1394
+ `;
1395
+ container.appendChild(row);
1396
+ updateBreakoutAssignments();
1397
+ }
1398
+
1399
+ function updateBreakoutAssignments() {
1400
+ const peersInCall = Object.entries(peerConnections).map(([id, c]) => ({ id, name: c.name || "Peer" }));
1401
+ const rows = document.querySelectorAll("#breakoutRoomsList .breakout-room-row");
1402
+ rows.forEach(row => {
1403
+ const peersDiv = row.querySelector(".br-peers");
1404
+ peersDiv.innerHTML = peersInCall.map(p =>
1405
+ `<span class="br-peer-chip" data-pid="${p.id}" onclick="this.classList.toggle('assigned')">${escapeHtml(p.name)}</span>`
1406
+ ).join("");
1407
+ });
1408
+ }
1409
+
1410
+ function startBreakout() {
1411
+ const rows = document.querySelectorAll("#breakoutRoomsList .breakout-room-row");
1412
+ const breakoutRooms = [];
1413
+ rows.forEach(row => {
1414
+ const name = row.querySelector("input").value.trim() || "Room";
1415
+ const assignedPeers = [...row.querySelectorAll(".br-peer-chip.assigned")].map(el => el.dataset.pid);
1416
+ breakoutRooms.push({ name, peers: assignedPeers });
1417
+ });
1418
+ if (ws) ws.send(JSON.stringify({ action: "create-breakout", rooms: breakoutRooms }));
1419
+ }
1420
+
1421
+ function renderBreakoutActive(rooms) {
1422
+ const setup = document.getElementById("breakoutSetup");
1423
+ const active = document.getElementById("breakoutActive");
1424
+ const list = document.getElementById("breakoutActiveList");
1425
+ setup.style.display = "none";
1426
+ active.style.display = "block";
1427
+
1428
+ list.innerHTML = Object.entries(rooms).map(([rid, r]) => `
1429
+ <div class="breakout-room-row">
1430
+ <strong>${escapeHtml(r.name)}</strong>
1431
+ <div class="br-peers">${r.peers.map(pid => {
1432
+ const name = peerConnections[pid]?.name || (pid === myPeerId ? myName : "Peer");
1433
+ return `<span class="br-peer-chip assigned">${escapeHtml(name)}</span>`;
1434
+ }).join("")}</div>
1435
+ </div>
1436
+ `).join("");
1437
+ }
1438
+
1439
+ function hideBreakoutActive() {
1440
+ document.getElementById("breakoutSetup").style.display = myRole === "host" ? "block" : "none";
1441
+ document.getElementById("breakoutActive").style.display = "none";
1442
+ }
1443
+
1444
+ // ── Background Blur ─────────────────────────────────────────────────────
1445
+ function toggleBgBlur() {
1446
+ bgBlurEnabled = !bgBlurEnabled;
1447
+ const btn = document.getElementById("bgBlurBtn");
1448
+ showToast(bgBlurEnabled ? "Background blur on" : "Background blur off");
1449
+
1450
+ if (bgBlurEnabled) {
1451
+ if (!localStream) return;
1452
+ const videoTrack = localStream.getVideoTracks()[0];
1453
+ if (!videoTrack) return;
1454
+
1455
+ bgBlurCanvas = document.createElement("canvas");
1456
+ bgBlurCanvas.width = 640;
1457
+ bgBlurCanvas.height = 480;
1458
+ bgBlurCtx = bgBlurCanvas.getContext("2d");
1459
+
1460
+ const tempVideo = document.createElement("video");
1461
+ tempVideo.srcObject = new MediaStream([videoTrack]);
1462
+ tempVideo.muted = true;
1463
+ tempVideo.play();
1464
+
1465
+ const draw = () => {
1466
+ if (!bgBlurEnabled) return;
1467
+ bgBlurCtx.filter = "blur(10px)";
1468
+ bgBlurCtx.drawImage(tempVideo, 0, 0, bgBlurCanvas.width, bgBlurCanvas.height);
1469
+ bgBlurCtx.filter = "none";
1470
+
1471
+ // Draw center region sharp (person approximation)
1472
+ const cx = bgBlurCanvas.width * 0.15;
1473
+ const cy = bgBlurCanvas.height * 0.05;
1474
+ const cw = bgBlurCanvas.width * 0.7;
1475
+ const ch = bgBlurCanvas.height * 0.9;
1476
+ bgBlurCtx.drawImage(tempVideo, cx, cy, cw, ch, cx, cy, cw, ch);
1477
+
1478
+ requestAnimationFrame(draw);
1479
+ };
1480
+ draw();
1481
+
1482
+ bgBlurStream = bgBlurCanvas.captureStream(30);
1483
+ const blurTrack = bgBlurStream.getVideoTracks()[0];
1484
+
1485
+ // Replace in all peer connections
1486
+ for (const pid in peerConnections) {
1487
+ const sender = peerConnections[pid].pc.getSenders().find(s => s.track?.kind === "video");
1488
+ if (sender) sender.replaceTrack(blurTrack);
1489
+ }
1490
+ localVideo.srcObject = bgBlurStream;
1491
+ } else {
1492
+ // Restore original camera
1493
+ const camTrack = localStream ? localStream.getVideoTracks()[0] : null;
1494
+ for (const pid in peerConnections) {
1495
+ const sender = peerConnections[pid].pc.getSenders().find(s => s.track?.kind === "video");
1496
+ if (sender && camTrack) sender.replaceTrack(camTrack);
1497
+ }
1498
+ localVideo.srcObject = localStream;
1499
+ if (bgBlurStream) {
1500
+ bgBlurStream.getTracks().forEach(t => t.stop());
1501
+ bgBlurStream = null;
1502
+ }
1503
+ }
1504
+ }
static/index.html CHANGED
@@ -55,6 +55,19 @@
55
 
56
  <!-- Call Screen -->
57
  <div id="callScreen" class="screen">
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  <div class="call-layout">
59
  <!-- Video Grid -->
60
  <div class="video-grid" id="videoGrid">
@@ -64,6 +77,7 @@
64
  <div class="video-off-overlay" id="localVideoOff" style="display:none">
65
  <div class="avatar"><span class="material-icons-round">person</span></div>
66
  </div>
 
67
  <div class="tile-label">
68
  <span class="tile-name" id="localName">You</span>
69
  <span class="mic-indicator" id="localMicIndicator"><span class="material-icons-round">mic</span></span>
@@ -71,7 +85,8 @@
71
  </div>
72
  </div>
73
 
74
- <!-- Chat Panel (hidden by default) -->
 
75
  <div class="chat-panel" id="chatPanel">
76
  <div class="chat-header">
77
  <h3>Chat</h3>
@@ -83,6 +98,79 @@
83
  <button id="sendChatBtn" class="btn btn-small">Send</button>
84
  </div>
85
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  </div>
87
 
88
  <!-- Bottom Controls -->
@@ -90,6 +178,7 @@
90
  <div class="controls-left">
91
  <span class="room-info" id="roomInfo"></span>
92
  <button id="copyLinkBtn" class="text-btn" title="Copy invite link"><span class="material-icons-round">content_copy</span> Copy link</button>
 
93
  </div>
94
  <div class="controls-center">
95
  <button id="micBtn" class="ctrl-btn active" title="Toggle microphone">
@@ -108,10 +197,47 @@
108
  <span class="icon-on"><span class="material-icons-round">fiber_manual_record</span></span>
109
  <span class="icon-off"><span class="material-icons-round">stop_circle</span></span>
110
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  <button id="chatBtn" class="ctrl-btn" title="Toggle chat">
112
  <span class="icon-on"><span class="material-icons-round">chat</span></span>
113
  <span class="icon-off"><span class="material-icons-round">chat_bubble_outline</span></span>
114
  </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  <button id="leaveBtn" class="ctrl-btn leave" title="Leave call">
116
  <span class="material-icons-round">call_end</span>
117
  </button>
 
55
 
56
  <!-- Call Screen -->
57
  <div id="callScreen" class="screen">
58
+ <!-- Waiting Room Overlay -->
59
+ <div id="waitingRoomOverlay" class="overlay-screen" style="display:none">
60
+ <div class="overlay-card">
61
+ <span class="material-icons-round" style="font-size:48px;color:var(--blue-600)">hourglass_top</span>
62
+ <h2>Waiting Room</h2>
63
+ <p id="waitingRoomMsg">Please wait for the host to let you in...</p>
64
+ <button id="waitingLeaveBtn" class="btn btn-secondary" style="margin-top:16px">Leave</button>
65
+ </div>
66
+ </div>
67
+
68
+ <!-- Reactions Overlay -->
69
+ <div id="reactionsOverlay" class="reactions-overlay"></div>
70
+
71
  <div class="call-layout">
72
  <!-- Video Grid -->
73
  <div class="video-grid" id="videoGrid">
 
77
  <div class="video-off-overlay" id="localVideoOff" style="display:none">
78
  <div class="avatar"><span class="material-icons-round">person</span></div>
79
  </div>
80
+ <div class="hand-indicator" id="localHand" style="display:none">βœ‹</div>
81
  <div class="tile-label">
82
  <span class="tile-name" id="localName">You</span>
83
  <span class="mic-indicator" id="localMicIndicator"><span class="material-icons-round">mic</span></span>
 
85
  </div>
86
  </div>
87
 
88
+ <!-- Side Panels -->
89
+ <!-- Chat Panel -->
90
  <div class="chat-panel" id="chatPanel">
91
  <div class="chat-header">
92
  <h3>Chat</h3>
 
98
  <button id="sendChatBtn" class="btn btn-small">Send</button>
99
  </div>
100
  </div>
101
+
102
+ <!-- Participants Panel -->
103
+ <div class="side-panel" id="participantsPanel">
104
+ <div class="panel-header-bar">
105
+ <h3>Participants</h3>
106
+ <button id="closeParticipantsBtn" class="icon-btn">βœ•</button>
107
+ </div>
108
+ <div class="host-controls" id="hostControls" style="display:none">
109
+ <button id="muteAllBtn" class="btn btn-small btn-outline">Mute All</button>
110
+ <button id="lowerAllHandsBtn" class="btn btn-small btn-outline">Lower All Hands</button>
111
+ <div class="toggle-row">
112
+ <label><input type="checkbox" id="waitingRoomToggle"> Waiting Room</label>
113
+ <label><input type="checkbox" id="lockMeetingToggle"> Lock Meeting</label>
114
+ </div>
115
+ </div>
116
+ <!-- Waiting list (host only) -->
117
+ <div id="waitingList" style="display:none">
118
+ <h4 class="section-title">Waiting Room</h4>
119
+ <div id="waitingListContent"></div>
120
+ </div>
121
+ <h4 class="section-title" id="participantCountTitle">In Meeting (1)</h4>
122
+ <div id="participantList"></div>
123
+ </div>
124
+
125
+ <!-- Whiteboard Panel -->
126
+ <div class="side-panel wide-panel" id="whiteboardPanel">
127
+ <div class="panel-header-bar">
128
+ <h3>Whiteboard</h3>
129
+ <div class="wb-tools">
130
+ <input type="color" id="wbColor" value="#1a73e8" title="Brush color">
131
+ <input type="range" id="wbSize" min="1" max="20" value="3" title="Brush size">
132
+ <button id="wbEraser" class="btn btn-small btn-outline">Eraser</button>
133
+ <button id="wbClear" class="btn btn-small btn-outline">Clear</button>
134
+ </div>
135
+ <button id="closeWhiteboardBtn" class="icon-btn">βœ•</button>
136
+ </div>
137
+ <canvas id="whiteboardCanvas" width="900" height="500"></canvas>
138
+ </div>
139
+
140
+ <!-- Polls Panel -->
141
+ <div class="side-panel" id="pollsPanel">
142
+ <div class="panel-header-bar">
143
+ <h3>Polls</h3>
144
+ <button id="closePollsBtn" class="icon-btn">βœ•</button>
145
+ </div>
146
+ <div id="createPollSection" style="display:none">
147
+ <input type="text" id="pollQuestion" placeholder="Poll question..." maxlength="200">
148
+ <div id="pollOptionsContainer">
149
+ <input type="text" class="poll-option-input" placeholder="Option 1" maxlength="100">
150
+ <input type="text" class="poll-option-input" placeholder="Option 2" maxlength="100">
151
+ </div>
152
+ <button id="addPollOption" class="text-btn">+ Add option</button>
153
+ <button id="launchPollBtn" class="btn btn-small" style="width:100%;margin-top:8px">Launch Poll</button>
154
+ </div>
155
+ <div id="activePollsList"></div>
156
+ </div>
157
+
158
+ <!-- Breakout Rooms Panel -->
159
+ <div class="side-panel" id="breakoutPanel">
160
+ <div class="panel-header-bar">
161
+ <h3>Breakout Rooms</h3>
162
+ <button id="closeBreakoutBtn" class="icon-btn">βœ•</button>
163
+ </div>
164
+ <div id="breakoutSetup" style="display:none">
165
+ <div id="breakoutRoomsList"></div>
166
+ <button id="addBreakoutRoom" class="text-btn">+ Add room</button>
167
+ <button id="startBreakoutBtn" class="btn btn-small" style="width:100%;margin-top:8px">Start Breakout</button>
168
+ </div>
169
+ <div id="breakoutActive" style="display:none">
170
+ <div id="breakoutActiveList"></div>
171
+ <button id="endBreakoutBtn" class="btn btn-small" style="width:100%;margin-top:8px;background:var(--red-500)">End Breakout</button>
172
+ </div>
173
+ </div>
174
  </div>
175
 
176
  <!-- Bottom Controls -->
 
178
  <div class="controls-left">
179
  <span class="room-info" id="roomInfo"></span>
180
  <button id="copyLinkBtn" class="text-btn" title="Copy invite link"><span class="material-icons-round">content_copy</span> Copy link</button>
181
+ <span class="meeting-timer" id="meetingTimer">00:00</span>
182
  </div>
183
  <div class="controls-center">
184
  <button id="micBtn" class="ctrl-btn active" title="Toggle microphone">
 
197
  <span class="icon-on"><span class="material-icons-round">fiber_manual_record</span></span>
198
  <span class="icon-off"><span class="material-icons-round">stop_circle</span></span>
199
  </button>
200
+
201
+ <!-- Reactions dropdown -->
202
+ <div class="ctrl-dropdown">
203
+ <button id="reactBtn" class="ctrl-btn" title="Reactions">
204
+ <span class="material-icons-round">sentiment_satisfied_alt</span>
205
+ </button>
206
+ <div class="dropdown-menu" id="reactionsMenu">
207
+ <button class="reaction-btn" data-emoji="πŸ‘">πŸ‘</button>
208
+ <button class="reaction-btn" data-emoji="πŸ‘">πŸ‘</button>
209
+ <button class="reaction-btn" data-emoji="❀️">❀️</button>
210
+ <button class="reaction-btn" data-emoji="πŸ˜‚">πŸ˜‚</button>
211
+ <button class="reaction-btn" data-emoji="πŸŽ‰">πŸŽ‰</button>
212
+ <button class="reaction-btn" data-emoji="πŸ€”">πŸ€”</button>
213
+ </div>
214
+ </div>
215
+
216
+ <button id="handBtn" class="ctrl-btn" title="Raise hand">
217
+ <span class="material-icons-round">pan_tool</span>
218
+ </button>
219
+
220
  <button id="chatBtn" class="ctrl-btn" title="Toggle chat">
221
  <span class="icon-on"><span class="material-icons-round">chat</span></span>
222
  <span class="icon-off"><span class="material-icons-round">chat_bubble_outline</span></span>
223
  </button>
224
+ <button id="participantsBtn" class="ctrl-btn" title="Participants">
225
+ <span class="material-icons-round">people</span>
226
+ </button>
227
+
228
+ <!-- More menu -->
229
+ <div class="ctrl-dropdown">
230
+ <button id="moreBtn" class="ctrl-btn" title="More">
231
+ <span class="material-icons-round">more_vert</span>
232
+ </button>
233
+ <div class="dropdown-menu dropdown-up" id="moreMenu">
234
+ <button id="whiteboardBtn" class="dropdown-item"><span class="material-icons-round">draw</span> Whiteboard</button>
235
+ <button id="pollsBtn" class="dropdown-item"><span class="material-icons-round">poll</span> Polls</button>
236
+ <button id="breakoutBtn" class="dropdown-item"><span class="material-icons-round">dashboard</span> Breakout Rooms</button>
237
+ <button id="bgBlurBtn" class="dropdown-item"><span class="material-icons-round">blur_on</span> Background Blur</button>
238
+ </div>
239
+ </div>
240
+
241
  <button id="leaveBtn" class="ctrl-btn leave" title="Leave call">
242
  <span class="material-icons-round">call_end</span>
243
  </button>
static/styles.css CHANGED
@@ -714,3 +714,393 @@ input[type="text"]::placeholder {
714
 
715
  .video-grid[data-count="2"] { grid-template-columns: 1fr; }
716
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
714
 
715
  .video-grid[data-count="2"] { grid-template-columns: 1fr; }
716
  }
717
+
718
+ /* ─── Overlay Screen (Waiting Room) ──────────────────────── */
719
+ .overlay-screen {
720
+ position: absolute;
721
+ inset: 0;
722
+ z-index: 50;
723
+ background: rgba(255,255,255,.95);
724
+ display: flex;
725
+ align-items: center;
726
+ justify-content: center;
727
+ backdrop-filter: blur(8px);
728
+ }
729
+ .overlay-card {
730
+ text-align: center;
731
+ padding: 40px;
732
+ max-width: 400px;
733
+ }
734
+ .overlay-card h2 { margin: 16px 0 8px; font-size: 22px; }
735
+ .overlay-card p { color: var(--text-secondary); font-size: 14px; }
736
+
737
+ /* ─── Reactions Overlay ──────────────────────────────────── */
738
+ .reactions-overlay {
739
+ position: absolute;
740
+ bottom: 80px;
741
+ left: 50%;
742
+ transform: translateX(-50%);
743
+ pointer-events: none;
744
+ z-index: 40;
745
+ width: 300px;
746
+ height: 200px;
747
+ }
748
+ .reaction-float {
749
+ position: absolute;
750
+ bottom: 0;
751
+ font-size: 32px;
752
+ animation: float-up 2.5s ease-out forwards;
753
+ pointer-events: none;
754
+ }
755
+ @keyframes float-up {
756
+ 0% { opacity: 1; transform: translateY(0) scale(1); }
757
+ 70% { opacity: 1; }
758
+ 100% { opacity: 0; transform: translateY(-180px) scale(1.3); }
759
+ }
760
+
761
+ /* ─── Hand Indicator ─────────────────────────────────────── */
762
+ .hand-indicator {
763
+ position: absolute;
764
+ top: 8px;
765
+ right: 8px;
766
+ font-size: 24px;
767
+ z-index: 5;
768
+ animation: hand-wave 0.6s ease-in-out infinite alternate;
769
+ filter: drop-shadow(0 2px 4px rgba(0,0,0,.3));
770
+ }
771
+ @keyframes hand-wave {
772
+ 0% { transform: rotate(-10deg); }
773
+ 100% { transform: rotate(10deg); }
774
+ }
775
+
776
+ /* ─── Side Panels ────────────────────────────────────────── */
777
+ .side-panel {
778
+ display: none;
779
+ width: 320px;
780
+ border-left: 1px solid var(--hairline);
781
+ background: var(--surface);
782
+ flex-direction: column;
783
+ overflow-y: auto;
784
+ }
785
+ .side-panel.open { display: flex; }
786
+ .side-panel.wide-panel { width: 50vw; min-width: 400px; max-width: 900px; }
787
+
788
+ .panel-header-bar {
789
+ display: flex;
790
+ align-items: center;
791
+ justify-content: space-between;
792
+ padding: 12px 16px;
793
+ border-bottom: 1px solid var(--hairline);
794
+ flex-wrap: wrap;
795
+ gap: 8px;
796
+ }
797
+ .panel-header-bar h3 { font-size: 14px; font-weight: 600; }
798
+
799
+ .section-title {
800
+ font-size: 11px;
801
+ text-transform: uppercase;
802
+ letter-spacing: 0.06em;
803
+ color: var(--text-hint);
804
+ padding: 12px 16px 4px;
805
+ font-weight: 600;
806
+ }
807
+
808
+ /* ─── Host Controls ──────────────────────────────────────── */
809
+ .host-controls {
810
+ padding: 12px 16px;
811
+ border-bottom: 1px solid var(--hairline);
812
+ display: flex;
813
+ flex-wrap: wrap;
814
+ gap: 8px;
815
+ }
816
+ .toggle-row {
817
+ display: flex;
818
+ gap: 12px;
819
+ width: 100%;
820
+ font-size: 13px;
821
+ color: var(--text-secondary);
822
+ margin-top: 4px;
823
+ }
824
+ .toggle-row label {
825
+ display: flex;
826
+ align-items: center;
827
+ gap: 4px;
828
+ cursor: pointer;
829
+ }
830
+ .toggle-row input[type="checkbox"] { accent-color: var(--blue-600); }
831
+
832
+ .btn-outline {
833
+ background: var(--surface);
834
+ border: 1px solid var(--hairline);
835
+ color: var(--text-primary);
836
+ }
837
+ .btn-outline:hover { background: var(--surface-alt); border-color: var(--blue-600); color: var(--blue-600); }
838
+
839
+ /* ─── Participant List Items ─────────────────────────────── */
840
+ .participant-item {
841
+ display: flex;
842
+ align-items: center;
843
+ gap: 10px;
844
+ padding: 8px 16px;
845
+ font-size: 13px;
846
+ transition: background var(--transition);
847
+ }
848
+ .participant-item:hover { background: var(--surface-alt); }
849
+ .participant-item .p-name { flex: 1; font-weight: 500; }
850
+ .participant-item .p-role {
851
+ font-size: 10px;
852
+ text-transform: uppercase;
853
+ color: var(--blue-600);
854
+ font-weight: 600;
855
+ letter-spacing: 0.04em;
856
+ }
857
+ .participant-item .p-hand { font-size: 16px; }
858
+ .participant-item .p-actions { display: flex; gap: 4px; }
859
+ .participant-item .p-actions button {
860
+ background: none;
861
+ border: none;
862
+ cursor: pointer;
863
+ color: var(--text-hint);
864
+ font-size: 18px;
865
+ padding: 2px;
866
+ border-radius: var(--radius-full);
867
+ transition: all var(--transition);
868
+ display: flex;
869
+ align-items: center;
870
+ }
871
+ .participant-item .p-actions button:hover { color: var(--red-500); background: rgba(234,67,53,.08); }
872
+
873
+ /* ─── Waiting List Items ─────────────────────────────────── */
874
+ .waiting-item {
875
+ display: flex;
876
+ align-items: center;
877
+ gap: 8px;
878
+ padding: 8px 16px;
879
+ font-size: 13px;
880
+ }
881
+ .waiting-item .w-name { flex: 1; font-weight: 500; }
882
+ .waiting-item .btn-admit {
883
+ background: var(--green-500);
884
+ color: #fff;
885
+ border: none;
886
+ padding: 4px 12px;
887
+ border-radius: 6px;
888
+ font-size: 12px;
889
+ cursor: pointer;
890
+ font-weight: 500;
891
+ }
892
+ .waiting-item .btn-deny {
893
+ background: var(--red-500);
894
+ color: #fff;
895
+ border: none;
896
+ padding: 4px 12px;
897
+ border-radius: 6px;
898
+ font-size: 12px;
899
+ cursor: pointer;
900
+ font-weight: 500;
901
+ }
902
+
903
+ /* ─── Dropdown Menu ──────────────────────────────────────── */
904
+ .ctrl-dropdown { position: relative; }
905
+ .dropdown-menu {
906
+ display: none;
907
+ position: absolute;
908
+ bottom: 56px;
909
+ left: 50%;
910
+ transform: translateX(-50%);
911
+ background: var(--surface);
912
+ border: 1px solid var(--hairline);
913
+ border-radius: var(--radius-md);
914
+ box-shadow: var(--elevation-3);
915
+ z-index: 30;
916
+ overflow: hidden;
917
+ min-width: 180px;
918
+ }
919
+ .ctrl-dropdown:hover .dropdown-menu,
920
+ .ctrl-dropdown:focus-within .dropdown-menu { display: flex; }
921
+
922
+ #reactionsMenu {
923
+ flex-direction: row;
924
+ padding: 8px;
925
+ gap: 4px;
926
+ min-width: auto;
927
+ }
928
+ .reaction-btn {
929
+ font-size: 22px;
930
+ background: none;
931
+ border: none;
932
+ cursor: pointer;
933
+ padding: 6px 8px;
934
+ border-radius: var(--radius-sm);
935
+ transition: background var(--transition);
936
+ }
937
+ .reaction-btn:hover { background: var(--surface-alt); }
938
+
939
+ .dropdown-item {
940
+ display: flex;
941
+ align-items: center;
942
+ gap: 10px;
943
+ padding: 10px 16px;
944
+ background: none;
945
+ border: none;
946
+ font-size: 13px;
947
+ font-family: inherit;
948
+ color: var(--text-primary);
949
+ cursor: pointer;
950
+ width: 100%;
951
+ text-align: left;
952
+ transition: background var(--transition);
953
+ }
954
+ .dropdown-item:hover { background: var(--surface-alt); }
955
+ .dropdown-item .material-icons-round { font-size: 18px; color: var(--text-secondary); }
956
+
957
+ /* ─── Hand Raise Button Active ───────────────────────────── */
958
+ #handBtn.raised {
959
+ background: #fbbf24 !important;
960
+ color: #000 !important;
961
+ }
962
+ #handBtn.raised:hover { background: #f59e0b !important; }
963
+
964
+ /* ─── Participants Button Badge ──────────────────────────── */
965
+ #participantsBtn:not(.active),
966
+ #handBtn:not(.raised),
967
+ #moreBtn {
968
+ background: #3c4043;
969
+ color: #e8eaed;
970
+ }
971
+ #participantsBtn:not(.active):hover,
972
+ #handBtn:not(.raised):hover,
973
+ #moreBtn:hover {
974
+ background: #4e5256;
975
+ }
976
+
977
+ /* ─── Meeting Timer ──────────────────────────────────────── */
978
+ .meeting-timer {
979
+ font-size: 13px;
980
+ color: var(--text-hint);
981
+ font-weight: 500;
982
+ font-variant-numeric: tabular-nums;
983
+ }
984
+
985
+ /* ─── Whiteboard ─────────────────────────────────────────── */
986
+ #whiteboardCanvas {
987
+ background: #fff;
988
+ border: 1px solid var(--hairline);
989
+ border-radius: var(--radius-sm);
990
+ cursor: crosshair;
991
+ width: 100%;
992
+ height: auto;
993
+ display: block;
994
+ }
995
+ .wb-tools {
996
+ display: flex;
997
+ align-items: center;
998
+ gap: 8px;
999
+ flex: 1;
1000
+ justify-content: center;
1001
+ }
1002
+ .wb-tools input[type="color"] {
1003
+ width: 28px;
1004
+ height: 28px;
1005
+ border: none;
1006
+ padding: 0;
1007
+ cursor: pointer;
1008
+ border-radius: 4px;
1009
+ }
1010
+ .wb-tools input[type="range"] {
1011
+ width: 80px;
1012
+ }
1013
+
1014
+ /* ─── Polls ──────────────────────────────────────────────── */
1015
+ #createPollSection, #activePollsList {
1016
+ padding: 12px 16px;
1017
+ }
1018
+ #createPollSection { border-bottom: 1px solid var(--hairline); }
1019
+ .poll-option-input {
1020
+ margin-top: 6px;
1021
+ }
1022
+ .poll-card {
1023
+ background: var(--surface-alt);
1024
+ border-radius: var(--radius-sm);
1025
+ padding: 12px;
1026
+ margin-bottom: 12px;
1027
+ }
1028
+ .poll-card h4 { font-size: 14px; margin-bottom: 8px; }
1029
+ .poll-option-row {
1030
+ display: flex;
1031
+ align-items: center;
1032
+ gap: 8px;
1033
+ margin-bottom: 6px;
1034
+ cursor: pointer;
1035
+ padding: 6px 8px;
1036
+ border-radius: 6px;
1037
+ transition: background var(--transition);
1038
+ }
1039
+ .poll-option-row:hover { background: rgba(26,115,232,.06); }
1040
+ .poll-option-row.voted { background: rgba(26,115,232,.1); font-weight: 600; }
1041
+ .poll-bar {
1042
+ height: 6px;
1043
+ background: var(--hairline);
1044
+ border-radius: 3px;
1045
+ flex: 1;
1046
+ position: relative;
1047
+ overflow: hidden;
1048
+ }
1049
+ .poll-bar-fill {
1050
+ position: absolute;
1051
+ left: 0;
1052
+ top: 0;
1053
+ height: 100%;
1054
+ background: var(--blue-600);
1055
+ border-radius: 3px;
1056
+ transition: width 0.3s ease;
1057
+ }
1058
+ .poll-option-text { font-size: 13px; min-width: 80px; }
1059
+ .poll-option-pct { font-size: 12px; color: var(--text-hint); min-width: 40px; text-align: right; }
1060
+ .poll-total { font-size: 11px; color: var(--text-hint); margin-top: 4px; }
1061
+
1062
+ /* ─── Breakout ───────────────────────────────────────────── */
1063
+ #breakoutSetup, #breakoutActive { padding: 12px 16px; }
1064
+ .breakout-room-row {
1065
+ background: var(--surface-alt);
1066
+ border-radius: var(--radius-sm);
1067
+ padding: 10px 12px;
1068
+ margin-bottom: 8px;
1069
+ }
1070
+ .breakout-room-row input {
1071
+ margin-bottom: 6px;
1072
+ }
1073
+ .breakout-room-row .br-peers {
1074
+ display: flex;
1075
+ flex-wrap: wrap;
1076
+ gap: 4px;
1077
+ }
1078
+ .br-peer-chip {
1079
+ font-size: 11px;
1080
+ padding: 2px 8px;
1081
+ background: var(--blue-50);
1082
+ color: var(--blue-600);
1083
+ border-radius: 12px;
1084
+ cursor: pointer;
1085
+ }
1086
+ .br-peer-chip.assigned { background: var(--blue-600); color: #fff; }
1087
+
1088
+ /* ─── Background Blur Active Indicator ───────────────────── */
1089
+ .bgblur-active #localVideo {
1090
+ /* Handled via JS canvas, but visual marker */
1091
+ }
1092
+
1093
+ @media (max-width: 768px) {
1094
+ .side-panel, .side-panel.wide-panel {
1095
+ position: absolute;
1096
+ right: 0;
1097
+ top: 0;
1098
+ bottom: 60px;
1099
+ z-index: 10;
1100
+ width: 100%;
1101
+ min-width: unset;
1102
+ max-width: unset;
1103
+ }
1104
+ .controls-center { gap: 4px; }
1105
+ .ctrl-dropdown .dropdown-menu { min-width: 160px; }
1106
+ }