screen-share-relay-v2 / index.html
Absboy's picture
Update index.html
fe51994 verified
Raw History Blame Contribute Delete
4.61 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Real-Time Screen Share (High Speed)</title>
<style>
:root { --primary: #38bdf8; --secondary: #f43f5e; --bg: #0f172a; --card-bg: #1e293b; --text: #f8fafc; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); text-align: center; margin: 0; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.container { width: 90%; max-width: 1000px; padding: 2rem; background: var(--card-bg); border-radius: 1.5rem; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); }
h1 { font-weight: 800; margin-bottom: 1.5rem; }
#screen-view { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 1rem; border: 2px solid var(--primary); margin-top: 1.5rem; display: none; background: #000; }
.btn-group { display: flex; gap: 1rem; justify-content: center; }
.btn { padding: 0.75rem 1.5rem; font-weight: 600; cursor: pointer; border: none; border-radius: 0.75rem; transition: 0.2s; }
.btn-client { background: var(--primary); color: var(--bg); }
.btn-admin { background: var(--secondary); color: white; }
#status { color: #94a3b8; margin-top: 1.5rem; font-size: 0.875rem; background: rgba(0,0,0,0.3); padding: 10px; border-radius: 5px; }
</style>
</head>
<body>
<div class="container">
<h1>🚀 High-Speed Screen Share</h1>
<div id="controls" class="btn-group">
<button class="btn btn-client" onclick="startSharing()">Start Sharing</button>
<button class="btn btn-admin" onclick="startViewing()">View Stream</button>
</div>
<div id="status">Status: Waiting...</div>
<img id="screen-view" src="" alt="Live Stream">
</div>
<script>
let ws;
const status = document.getElementById('status');
const img = document.getElementById('screen-view');
function getWsUrl(path) {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
return `${protocol}//${window.location.host}${path}`;
}
async function startSharing() {
try {
const stream = await navigator.mediaDevices.getDisplayMedia({ video: { frameRate: 5 } });
const video = document.createElement('video');
video.srcObject = stream;
video.play();
ws = new WebSocket(getWsUrl("/ws/client"));
ws.binaryType = "arraybuffer"; // Enable binary mode
ws.onopen = () => {
status.innerText = "Connected! Streaming Binary Frames...";
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
setInterval(() => {
if (video.videoWidth > 0 && ws.readyState === 1) {
canvas.width = 480; // Small resolution for low latency
canvas.height = (video.videoHeight / video.videoWidth) * 480;
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
canvas.toBlob((blob) => {
if (ws.readyState === 1) ws.send(blob);
}, 'image/jpeg', 0.2); // 20% quality for maximum speed
}
}, 200); // 5 FPS
};
ws.onerror = () => status.innerText = "WebSocket Error.";
} catch (err) { status.innerText = "Error: " + err.message; }
}
function startViewing() {
ws = new WebSocket(getWsUrl("/ws/admin"));
ws.binaryType = "arraybuffer";
status.innerText = "Connecting to binary stream...";
img.style.display = 'block';
ws.onmessage = (e) => {
const blob = new Blob([e.data], { type: 'image/jpeg' });
const url = URL.createObjectURL(blob);
const oldUrl = img.src;
img.src = url;
if (oldUrl.startsWith('blob:')) URL.revokeObjectURL(oldUrl); // Memory management
status.innerText = "Live Stream Active";
};
ws.onopen = () => status.innerText = "Admin Connected!";
ws.onerror = () => status.innerText = "Connection Failed.";
}
</script>
</body>
</html>