config: Add 3 and update 5 files
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 22s
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 22s
This commit is contained in:
254
squashkiwi-streaming/config/web/webrtc.html
Normal file
254
squashkiwi-streaming/config/web/webrtc.html
Normal file
@@ -0,0 +1,254 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>SquashKiwi Court Stream - WebRTC</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
color: white;
|
||||
}
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
header {
|
||||
text-align: center;
|
||||
padding: 30px 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
||||
}
|
||||
.video-section {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
backdrop-filter: blur(10px);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.video-container {
|
||||
position: relative;
|
||||
padding-bottom: 56.25%;
|
||||
height: 0;
|
||||
background: black;
|
||||
}
|
||||
video {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.video-controls {
|
||||
padding: 15px;
|
||||
background: rgba(0, 0, 0, 0.3);
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
.status-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 20px;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.status-badge.live {
|
||||
background: rgba(76, 175, 80, 0.3);
|
||||
}
|
||||
.status-badge.offline {
|
||||
background: rgba(244, 67, 54, 0.3);
|
||||
}
|
||||
.btn {
|
||||
padding: 8px 16px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border: none;
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.btn:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
.info-section {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
backdrop-filter: blur(10px);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.switch-link {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
}
|
||||
.switch-link a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
display: inline-block;
|
||||
}
|
||||
.switch-link a:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<h1>🎾 SquashKiwi Court Stream (WebRTC)</h1>
|
||||
</header>
|
||||
|
||||
<div class="video-section">
|
||||
<div class="video-container">
|
||||
<video id="video" controls autoplay muted></video>
|
||||
</div>
|
||||
<div class="video-controls">
|
||||
<div class="status-badge offline" id="status">
|
||||
<span>Connecting...</span>
|
||||
</div>
|
||||
<div>
|
||||
<button class="btn" onclick="toggleFullscreen()">📺 Fullscreen</button>
|
||||
<button class="btn" onclick="refreshStream()">🔄 Refresh</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="switch-link">
|
||||
<a href="/">Switch to HLS Player</a>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<h2>WebRTC Stream</h2>
|
||||
<p>This player uses WebRTC for lower latency streaming. It should work with H265/HEVC streams.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const config = {
|
||||
courtId: new URLSearchParams(window.location.search).get('court') || 'court_h264',
|
||||
webrtcUrl: '/webrtc/'
|
||||
};
|
||||
|
||||
let pc = null;
|
||||
|
||||
async function initPlayer() {
|
||||
const video = document.getElementById('video');
|
||||
|
||||
pc = new RTCPeerConnection({
|
||||
iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
|
||||
});
|
||||
|
||||
// Add transceiver for receiving video
|
||||
pc.addTransceiver('video', {direction: 'recvonly'});
|
||||
pc.addTransceiver('audio', {direction: 'recvonly'});
|
||||
|
||||
pc.ontrack = (event) => {
|
||||
console.log('Got track:', event.track.kind);
|
||||
video.srcObject = event.streams[0];
|
||||
updateStatus(true);
|
||||
};
|
||||
|
||||
pc.oniceconnectionstatechange = () => {
|
||||
console.log('ICE connection state:', pc.iceConnectionState);
|
||||
if (pc.iceConnectionState === 'disconnected' || pc.iceConnectionState === 'failed') {
|
||||
updateStatus(false);
|
||||
setTimeout(refreshStream, 5000);
|
||||
}
|
||||
};
|
||||
|
||||
// Create offer with ICE candidates
|
||||
const offer = await pc.createOffer();
|
||||
await pc.setLocalDescription(offer);
|
||||
|
||||
// Wait for ICE gathering to complete
|
||||
await new Promise((resolve) => {
|
||||
if (pc.iceGatheringState === 'complete') {
|
||||
resolve();
|
||||
} else {
|
||||
pc.onicegatheringstatechange = () => {
|
||||
if (pc.iceGatheringState === 'complete') {
|
||||
resolve();
|
||||
}
|
||||
};
|
||||
// Timeout after 2 seconds
|
||||
setTimeout(resolve, 2000);
|
||||
}
|
||||
});
|
||||
|
||||
// Send complete offer with ICE candidates to MediaMTX
|
||||
try {
|
||||
const response = await fetch(`${config.webrtcUrl}${config.courtId}/whep`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/sdp'
|
||||
},
|
||||
body: pc.localDescription.sdp
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const answer = await response.text();
|
||||
await pc.setRemoteDescription({
|
||||
type: 'answer',
|
||||
sdp: answer
|
||||
});
|
||||
|
||||
console.log('WebRTC connection established');
|
||||
} catch (error) {
|
||||
console.error('WebRTC error:', error);
|
||||
updateStatus(false);
|
||||
setTimeout(refreshStream, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatus(live) {
|
||||
const statusEl = document.getElementById('status');
|
||||
if (live) {
|
||||
statusEl.className = 'status-badge live';
|
||||
statusEl.innerHTML = '<span>🔴 LIVE</span>';
|
||||
} else {
|
||||
statusEl.className = 'status-badge offline';
|
||||
statusEl.innerHTML = '<span>⚫ OFFLINE</span>';
|
||||
}
|
||||
}
|
||||
|
||||
function toggleFullscreen() {
|
||||
const video = document.getElementById('video');
|
||||
if (!document.fullscreenElement) {
|
||||
video.requestFullscreen().catch(err => {
|
||||
console.error('Fullscreen error:', err);
|
||||
});
|
||||
} else {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
function refreshStream() {
|
||||
if (pc) {
|
||||
pc.close();
|
||||
}
|
||||
initPlayer();
|
||||
}
|
||||
|
||||
// Initialize player on load
|
||||
initPlayer();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user