config: Add 3 and update 5 files
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 22s

This commit is contained in:
Your Name
2025-09-02 00:11:15 +12:00
parent 79c69ee08b
commit 7d1a1b3f0c
8 changed files with 493 additions and 17 deletions

View File

@@ -170,7 +170,7 @@
<script>
const config = {
courtId: new URLSearchParams(window.location.search).get('court') || 'court',
courtId: new URLSearchParams(window.location.search).get('court') || 'court_h264',
hlsUrl: '/hls/'
};

View File

@@ -0,0 +1,165 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Stream Test</title>
<style>
body {
font-family: monospace;
padding: 20px;
background: #1a1a1a;
color: #0f0;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #0f0;
background: #000;
}
button {
background: #0f0;
color: #000;
border: none;
padding: 10px 20px;
margin: 5px;
cursor: pointer;
font-family: monospace;
font-weight: bold;
}
button:hover {
background: #0a0;
}
.status {
margin: 10px 0;
padding: 10px;
background: #111;
}
.success { color: #0f0; }
.error { color: #f00; }
.info { color: #ff0; }
</style>
</head>
<body>
<h1>SquashKiwi Stream Test Page</h1>
<div class="test-section">
<h2>Available Paths</h2>
<button onclick="checkPaths()">Check MediaMTX Paths</button>
<div id="paths-status" class="status">Click to check available paths...</div>
</div>
<div class="test-section">
<h2>Test Streams</h2>
<button onclick="testStream('court')">Test 'court' (H265)</button>
<button onclick="testStream('court_h264')">Test 'court_h264'</button>
<button onclick="testStream('court_sub')">Test 'court_sub'</button>
<button onclick="testStream('court_main')">Test 'court_main'</button>
<div id="stream-status" class="status">Select a stream to test...</div>
</div>
<div class="test-section">
<h2>HLS Test</h2>
<video id="hls-video" controls style="width: 100%; max-width: 600px;"></video>
<div id="hls-status" class="status">HLS player ready...</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
async function checkPaths() {
const status = document.getElementById('paths-status');
status.innerHTML = '<span class="info">Checking paths...</span>';
try {
// Try direct access to MediaMTX API on port 9997
const response = await fetch('http://' + window.location.hostname + ':9997/v3/paths/list');
const data = await response.json();
let html = '<span class="success">Found ' + data.itemCount + ' path(s):</span><br>';
data.items.forEach(item => {
html += `<br>Path: <b>${item.name}</b>`;
html += `<br> Ready: ${item.ready ? '✓' : '✗'}`;
html += `<br> Tracks: ${item.tracks ? item.tracks.join(', ') : 'none'}`;
html += `<br> Readers: ${item.readers ? item.readers.length : 0}`;
html += '<br>';
});
status.innerHTML = html;
} catch (error) {
status.innerHTML = '<span class="error">Error: ' + error.message + '</span>';
}
}
async function testStream(streamName) {
const status = document.getElementById('stream-status');
const video = document.getElementById('hls-video');
status.innerHTML = `<span class="info">Testing stream: ${streamName}...</span>`;
// Test HLS
const hlsUrl = `/hls/${streamName}/index.m3u8`;
status.innerHTML += `<br>HLS URL: ${hlsUrl}`;
try {
const response = await fetch(hlsUrl, { method: 'HEAD' });
if (response.ok) {
status.innerHTML += '<br><span class="success">HLS playlist exists!</span>';
loadHLS(hlsUrl);
} else {
status.innerHTML += `<br><span class="error">HLS playlist not found (${response.status})</span>`;
}
} catch (error) {
status.innerHTML += '<br><span class="error">HLS test failed: ' + error.message + '</span>';
}
// Test WebRTC
const webrtcUrl = `/webrtc/${streamName}/whep`;
status.innerHTML += `<br><br>WebRTC URL: ${webrtcUrl}`;
try {
const response = await fetch(webrtcUrl, { method: 'OPTIONS' });
if (response.ok) {
status.innerHTML += '<br><span class="success">WebRTC endpoint exists!</span>';
} else {
status.innerHTML += `<br><span class="error">WebRTC endpoint issue (${response.status})</span>`;
}
} catch (error) {
status.innerHTML += '<br><span class="error">WebRTC test failed: ' + error.message + '</span>';
}
}
function loadHLS(url) {
const video = document.getElementById('hls-video');
const status = document.getElementById('hls-status');
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
status.innerHTML = '<span class="success">HLS stream loaded! Press play to start.</span>';
video.play().catch(e => {
status.innerHTML += '<br><span class="info">Auto-play blocked. Click play button.</span>';
});
});
hls.on(Hls.Events.ERROR, function(event, data) {
if (data.fatal) {
status.innerHTML = '<span class="error">HLS Error: ' + data.details + '</span>';
}
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
status.innerHTML = '<span class="info">Using native HLS support</span>';
} else {
status.innerHTML = '<span class="error">HLS not supported in this browser</span>';
}
}
// Check paths on load
window.onload = () => {
checkPaths();
};
</script>
</body>
</html>

View 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>