File size: 25,401 Bytes
581f60b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ConnectHub - Video Calling Platform</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .video-container {
            position: relative;
            width: 100%;
            height: 100%;
            border-radius: 8px;
            overflow: hidden;
            background-color: #1e293b;
        }
        
        .video-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 16px;
            padding: 16px;
            height: calc(100vh - 120px);
        }
        
        .video-item {
            position: relative;
            border-radius: 8px;
            overflow: hidden;
            transition: all 0.3s ease;
        }
        
        .video-info {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, 0.5);
            color: white;
            padding: 8px;
            font-size: 14px;
        }
        
        .controls {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            padding: 12px;
            display: flex;
            justify-content: center;
            gap: 16px;
            box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .control-btn {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s ease;
        }
        
        .end-call {
            background-color: #ef4444;
            color: white;
        }
        
        .muted {
            background-color: #ef4444;
            color: white;
        }
        
        .video-off {
            background-color: #ef4444;
            color: white;
        }
        
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.7);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background-color: white;
            padding: 24px;
            border-radius: 8px;
            width: 90%;
            max-width: 500px;
        }
        
        #local-video {
            transform: scaleX(-1); /* Mirror effect for self-view */
        }
    </style>
</head>
<body class="bg-gray-100">
    <!-- Pre-call screen -->
    <div id="pre-call" class="flex flex-col items-center justify-center h-screen">
        <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">
            <h1 class="text-3xl font-bold text-center text-blue-600 mb-6">ConnectHub</h1>
            <div class="mb-6">
                <label for="room-id" class="block text-sm font-medium text-gray-700 mb-1">Meeting ID</label>
                <input type="text" id="room-id" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter or create meeting ID">
            </div>
            <div class="mb-6">
                <label for="user-name" class="block text-sm font-medium text-gray-700 mb-1">Your Name</label>
                <input type="text" id="user-name" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter your name">
            </div>
            <div class="flex space-x-4">
                <button id="new-meeting" class="flex-1 bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
                    <i class="fas fa-video mr-2"></i> New Meeting
                </button>
                <button id="join-meeting" class="flex-1 bg-green-600 text-white py-2 px-4 rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-offset-2">
                    <i class="fas fa-sign-in-alt mr-2"></i> Join
                </button>
            </div>
        </div>
    </div>
    
    <!-- Call screen -->
    <div id="call-screen" class="hidden">
        <div class="bg-gray-800 text-white p-4 flex justify-between items-center">
            <div class="flex items-center">
                <i class="fas fa-video mr-2"></i>
                <h2 id="current-room-id" class="font-semibold">Meeting ID: </h2>
            </div>
            <div class="flex items-center">
                <span id="current-time" class="text-sm"></span>
            </div>
        </div>
        
        <div id="video-grid" class="video-grid">
            <!-- Video streams will be added here dynamically -->
        </div>
        
        <div class="controls">
            <div class="control-btn bg-gray-200" id="toggle-mic" title="Mute/Unmute">
                <i class="fas fa-microphone"></i>
            </div>
            <div class="control-btn bg-gray-200" id="toggle-video" title="Video On/Off">
                <i class="fas fa-video"></i>
            </div>
            <div class="control-btn bg-blue-500 text-white" id="share-screen" title="Share Screen">
                <i class="fas fa-desktop"></i>
            </div>
            <div class="control-btn bg-gray-200" id="participants" title="Participants">
                <i class="fas fa-users"></i>
            </div>
            <div class="control-btn end-call" id="end-call" title="End Call">
                <i class="fas fa-phone-slash"></i>
            </div>
        </div>
    </div>
    
    <!-- Participants modal -->
    <div id="participants-modal" class="modal">
        <div class="modal-content">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-semibold">Participants</h3>
                <button id="close-participants" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            <ul id="participants-list" class="divide-y divide-gray-200">
                <!-- Participants will be added here -->
            </ul>
        </div>
    </div>

    <script>
        // DOM elements
        const preCallScreen = document.getElementById('pre-call');
        const callScreen = document.getElementById('call-screen');
        const roomIdInput = document.getElementById('room-id');
        const userNameInput = document.getElementById('user-name');
        const newMeetingBtn = document.getElementById('new-meeting');
        const joinMeetingBtn = document.getElementById('join-meeting');
        const videoGrid = document.getElementById('video-grid');
        const toggleMicBtn = document.getElementById('toggle-mic');
        const toggleVideoBtn = document.getElementById('toggle-video');
        const endCallBtn = document.getElementById('end-call');
        const shareScreenBtn = document.getElementById('share-screen');
        const participantsBtn = document.getElementById('participants');
        const currentRoomId = document.getElementById('current-room-id');
        const currentTime = document.getElementById('current-time');
        const participantsModal = document.getElementById('participants-modal');
        const closeParticipantsBtn = document.getElementById('close-participants');
        const participantsList = document.getElementById('participants-list');

        // App state
        let roomId = '';
        let userName = '';
        let localStream;
        let peerConnections = {};
        let isMicOn = true;
        let isVideoOn = true;
        let isScreenSharing = false;
        let participants = {};
        let callStartTime;
        let socket;

        // Configuration (in a real app, you'd use your own signaling server)
        const configuration = {
            iceServers: [
                { urls: 'stun:stun.l.google.com:19302' },
                { urls: 'stun:stun1.l.google.com:19302' },
                { urls: 'stun:stun2.l.google.com:19302' }
            ]
        };

        // Generate a random room ID if not provided
        function generateRoomId() {
            return Math.random().toString(36).substring(2, 8).toUpperCase();
        }

        // Update the current time display
        function updateCurrentTime() {
            const now = new Date();
            currentTime.textContent = now.toLocaleTimeString();
            
            if (callStartTime) {
                const duration = Math.floor((now - callStartTime) / 1000);
                const hours = Math.floor(duration / 3600);
                const minutes = Math.floor((duration % 3600) / 60);
                const seconds = duration % 60;
                
                document.getElementById('call-duration')?.textContent = 
                    `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
            }
        }

        // Add a video stream to the grid
        function addVideoStream(userId, stream, name, isLocal = false) {
            if (document.getElementById(`video-${userId}`)) return;

            const videoContainer = document.createElement('div');
            videoContainer.className = 'video-item';
            videoContainer.id = `container-${userId}`;
            
            const videoElement = document.createElement('video');
            videoElement.id = `video-${userId}`;
            videoElement.autoplay = true;
            videoElement.playsInline = true;
            videoElement.srcObject = stream;
            
            if (isLocal) {
                videoElement.muted = true;
                videoElement.id = 'local-video';
            }
            
            const videoInfo = document.createElement('div');
            videoInfo.className = 'video-info';
            videoInfo.innerHTML = `
                <span>${name}</span>
                ${isLocal ? '<span class="float-right">(You)</span>' : ''}
            `;
            
            videoContainer.appendChild(videoElement);
            videoContainer.appendChild(videoInfo);
            videoGrid.appendChild(videoContainer);
            
            // Add to participants list
            participants[userId] = { name, stream, audio: true, video: true };
            updateParticipantsList();
            
            // Adjust video grid layout
            adjustVideoGrid();
        }

        // Adjust video grid layout based on number of participants
        function adjustVideoGrid() {
            const participantCount = Object.keys(participants).length;
            
            if (participantCount === 1) {
                videoGrid.style.gridTemplateColumns = '1fr';
            } else if (participantCount === 2) {
                videoGrid.style.gridTemplateColumns = '1fr 1fr';
            } else if (participantCount <= 4) {
                videoGrid.style.gridTemplateColumns = '1fr 1fr';
            } else {
                videoGrid.style.gridTemplateColumns = 'repeat(auto-fill, minmax(300px, 1fr))';
            }
        }

        // Remove a video stream from the grid
        function removeVideoStream(userId) {
            const videoContainer = document.getElementById(`container-${userId}`);
            if (videoContainer) {
                videoContainer.remove();
                delete participants[userId];
                updateParticipantsList();
                adjustVideoGrid();
            }
        }

        // Update participants list in the modal
        function updateParticipantsList() {
            participantsList.innerHTML = '';
            
            Object.entries(participants).forEach(([userId, participant]) => {
                const li = document.createElement('li');
                li.className = 'py-2 flex items-center';
                li.innerHTML = `
                    <div class="flex-shrink-0 h-10 w-10 rounded-full bg-gray-300 flex items-center justify-center mr-3">
                        <i class="fas fa-user text-gray-600"></i>
                    </div>
                    <div class="flex-1 min-w-0">
                        <p class="text-sm font-medium text-gray-900 truncate">${participant.name}</p>
                        <p class="text-sm text-gray-500 truncate">${userId === 'local' ? 'Host' : 'Participant'}</p>
                    </div>
                    <div class="flex items-center">
                        <span class="w-2 h-2 rounded-full ${participant.audio ? 'bg-green-500' : 'bg-red-500'} mr-1"></span>
                        <i class="fas ${participant.video ? 'fa-video' : 'fa-video-slash'} text-sm ${participant.video ? 'text-green-500' : 'text-red-500'}"></i>
                    </div>
                `;
                participantsList.appendChild(li);
            });
        }

        // Toggle microphone
        async function toggleMic() {
            isMicOn = !isMicOn;
            
            if (localStream) {
                const audioTracks = localStream.getAudioTracks();
                audioTracks.forEach(track => {
                    track.enabled = isMicOn;
                });
            }
            
            if (isMicOn) {
                toggleMicBtn.innerHTML = '<i class="fas fa-microphone"></i>';
                toggleMicBtn.classList.remove('muted');
            } else {
                toggleMicBtn.innerHTML = '<i class="fas fa-microphone-slash"></i>';
                toggleMicBtn.classList.add('muted');
            }
            
            // Update participant status
            if (participants['local']) {
                participants['local'].audio = isMicOn;
                updateParticipantsList();
            }
            
            // Send mute/unmute status to other participants (in a real app)
        }

        // Toggle video
        async function toggleVideo() {
            isVideoOn = !isVideoOn;
            
            if (localStream) {
                const videoTracks = localStream.getVideoTracks();
                videoTracks.forEach(track => {
                    track.enabled = isVideoOn;
                });
            }
            
            if (isVideoOn) {
                toggleVideoBtn.innerHTML = '<i class="fas fa-video"></i>';
                toggleVideoBtn.classList.remove('video-off');
            } else {
                toggleVideoBtn.innerHTML = '<i class="fas fa-video-slash"></i>';
                toggleVideoBtn.classList.add('video-off');
            }
            
            // Update participant status
            if (participants['local']) {
                participants['local'].video = isVideoOn;
                updateParticipantsList();
            }
            
            // Send video on/off status to other participants (in a real app)
        }

        // Share screen
        async function shareScreen() {
            try {
                if (isScreenSharing) {
                    // Stop screen sharing and switch back to camera
                    const videoTrack = await getCameraStream();
                    replaceStreamTrack(videoTrack);
                    
                    isScreenSharing = false;
                    shareScreenBtn.classList.remove('bg-blue-500', 'text-white');
                    shareScreenBtn.classList.add('bg-gray-200');
                } else {
                    // Get screen stream
                    const screenStream = await navigator.mediaDevices.getDisplayMedia({ 
                        video: true,
                        audio: false
                    });
                    
                    // Replace video track with screen share
                    const videoTrack = screenStream.getVideoTracks()[0];
                    replaceStreamTrack(videoTrack);
                    
                    isScreenSharing = true;
                    shareScreenBtn.classList.add('bg-blue-500', 'text-white');
                    shareScreenBtn.classList.remove('bg-gray-200');
                    
                    // Handle when user stops screen sharing
                    videoTrack.onended = () => {
                        shareScreen();
                    };
                }
            } catch (err) {
                console.error('Error sharing screen:', err);
            }
        }

        // Get camera stream
        async function getCameraStream() {
            const stream = await navigator.mediaDevices.getUserMedia({ 
                video: {
                    width: { ideal: 1280 },
                    height: { ideal: 720 },
                    frameRate: { ideal: 30 }
                },
                audio: true
            });
            return stream.getVideoTracks()[0];
        }

        // Replace the video track in the local stream
        function replaceStreamTrack(newTrack) {
            const videoTracks = localStream.getVideoTracks();
            const sender = getPeerConnectionSender('video');
            
            if (sender) {
                sender.replaceTrack(newTrack);
            }
            
            // Replace the track in the local stream
            videoTracks.forEach(track => track.stop());
            localStream.removeTrack(videoTracks[0]);
            localStream.addTrack(newTrack);
            
            // Update the local video element
            const videoElement = document.getElementById('local-video');
            if (videoElement) {
                videoElement.srcObject = localStream;
            }
        }

        // Get the RTCRtpSender for a specific track type
        function getPeerConnectionSender(type) {
            for (const pc of Object.values(peerConnections)) {
                const senders = pc.getSenders();
                const sender = senders.find(s => s.track && s.track.kind === type);
                if (sender) return sender;
            }
            return null;
        }

        // Initialize WebRTC peer connections
        async function initializePeerConnection(userId) {
            const peerConnection = new RTCPeerConnection(configuration);
            peerConnections[userId] = peerConnection;
            
            // Add local stream tracks to peer connection
            localStream.getTracks().forEach(track => {
                peerConnection.addTrack(track, localStream);
            });
            
            // Handle ICE candidates
            peerConnection.onicecandidate = event => {
                if (event.candidate) {
                    // Send the ICE candidate to the remote peer (via signaling server)
                    console.log('Sending ICE candidate:', event.candidate);
                }
            };
            
            // Handle remote stream
            peerConnection.ontrack = event => {
                const remoteStream = event.streams[0];
                addVideoStream(userId, remoteStream, `User ${userId}`);
            };
            
            // Handle connection state changes
            peerConnection.onconnectionstatechange = () => {
                console.log(`Connection state with ${userId}:`, peerConnection.connectionState);
                if (peerConnection.connectionState === 'disconnected' || 
                    peerConnection.connectionState === 'failed') {
                    removeVideoStream(userId);
                    delete peerConnections[userId];
                }
            };
            
            return peerConnection;
        }

        // Start a new call
        async function startCall(isNewMeeting = true) {
            userName = userNameInput.value.trim();
            roomId = roomIdInput.value.trim();
            
            if (!userName) {
                alert('Please enter your name');
                return;
            }
            
            if (!roomId && isNewMeeting) {
                roomId = generateRoomId();
                roomIdInput.value = roomId;
            } else if (!roomId) {
                alert('Please enter a meeting ID');
                return;
            }
            
            try {
                // Get user media
                localStream = await navigator.mediaDevices.getUserMedia({ 
                    video: {
                        width: { ideal: 1280 },
                        height: { ideal: 720 },
                        frameRate: { ideal: 30 }
                    },
                    audio: true
                });
                
                // Show call screen
                preCallScreen.classList.add('hidden');
                callScreen.classList.remove('hidden');
                
                // Update room ID display
                currentRoomId.textContent = `Meeting ID: ${roomId}`;
                
                // Add local video
                addVideoStream('local', localStream, userName, true);
                
                // Start call timer
                callStartTime = new Date();
                setInterval(updateCurrentTime, 1000);
                updateCurrentTime();
                
                // In a real app, you would connect to a signaling server here
                // and initialize peer connections with other participants
                console.log('Call started. In a real app, you would connect to a signaling server.');
                
            } catch (err) {
                console.error('Error starting call:', err);
                alert('Could not access camera or microphone. Please check permissions.');
                endCall();
            }
        }

        // End the call
        function endCall() {
            // Stop all media tracks
            if (localStream) {
                localStream.getTracks().forEach(track => track.stop());
            }
            
            // Close all peer connections
            Object.values(peerConnections).forEach(pc => pc.close());
            peerConnections = {};
            
            // Reset state
            localStream = null;
            participants = {};
            callStartTime = null;
            
            // Clear video grid
            videoGrid.innerHTML = '';
            
            // Hide call screen
            callScreen.classList.add('hidden');
            preCallScreen.classList.remove('hidden');
            
            // Close any open modals
            participantsModal.style.display = 'none';
            
            // Reset controls
            isMicOn = true;
            isVideoOn = true;
            isScreenSharing = false;
            
            toggleMicBtn.innerHTML = '<i class="fas fa-microphone"></i>';
            toggleMicBtn.classList.remove('muted');
            
            toggleVideoBtn.innerHTML = '<i class="fas fa-video"></i>';
            toggleVideoBtn.classList.remove('video-off');
            
            shareScreenBtn.classList.remove('bg-blue-500', 'text-white');
            shareScreenBtn.classList.add('bg-gray-200');
        }

        // Event listeners
        newMeetingBtn.addEventListener('click', () => startCall(true));
        joinMeetingBtn.addEventListener('click', () => startCall(false));
        
        toggleMicBtn.addEventListener('click', toggleMic);
        toggleVideoBtn.addEventListener('click', toggleVideo);
        endCallBtn.addEventListener('click', endCall);
        shareScreenBtn.addEventListener('click', shareScreen);
        
        participantsBtn.addEventListener('click', () => {
            participantsModal.style.display = 'flex';
        });
        
        closeParticipantsBtn.addEventListener('click', () => {
            participantsModal.style.display = 'none';
        });

        // Initialize with a random name if field is empty
        if (!userNameInput.value) {
            const names = ['Alex', 'Jamie', 'Taylor', 'Jordan', 'Casey', 'Riley'];
            userNameInput.value = names[Math.floor(Math.random() * names.length)];
        }

        // Check for room ID in URL
        const urlParams = new URLSearchParams(window.location.search);
        const roomParam = urlParams.get('room');
        
        if (roomParam) {
            roomIdInput.value = roomParam;
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Samir621/connecthub" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>