Spaces:
Running
Running
Download index.html from Samir621/connecthub: direct link, hf CLI and curl.
- Browser
- Download file 25.4 kB
-
https://huggingface.co/spaces/Samir621/connecthub/resolve/main/index.html
- Command line
-
hf download hf://spaces/Samir621/connecthub/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Samir621/connecthub/resolve/main/index.html
25.4 kB
| <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> |