Sample Code for HTML and React
1. HTML with JavaScript Example
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StreamPixel Full-Screen Stream with Loading Screen</title>
<style>
/* Reset and full-height settings for consistent coverage */
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
/* Loading screen styling */
#loadingScreen {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.9); /* Semi-transparent black background */
display: flex;
justify-content: center;
align-items: center;
z-index: 100; /* Highest layer */
}
#loadingScreen img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover; /* Stretch and crop the image to cover the viewport */
}
/* Buttons container */
#controls {
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.7); /* Semi-transparent background */
color: white;
padding: 10px;
z-index: 10; /* Above iframe but below loading screen */
position: fixed;
width: 100%;
top: 0;
}
#controls button {
margin: 0 10px;
padding: 10px 20px;
font-size: 14px;
cursor: pointer;
border: none;
background-color: #007bff;
color: white;
border-radius: 5px;
transition: background-color 0.3s;
}
#controls button:hover {
background-color: #0056b3;
}
/* Fullscreen iframe */
iframe {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
z-index: 1; /* Below everything else */
}
</style>
</head>
<body>
<!-- Loading Screen -->
<div id="loadingScreen">
<img src="your-image.jpg" alt="Loading...">
</div>
<!-- Button Controls -->
<div id="controls">
<button onclick="sendCommand()">Send Test Message</button>
<button onclick="muteAudio()">Mute Audio</button>
<button onclick="unMuteAudio()">Unmute Audio</button>
<button onclick="terminateSession()">Terminate Session</button>
</div>
<!-- Fullscreen Iframe -->
<iframe
id="streamPixelIframe"
src="your stream link"
allow="microphone; camera"
title="StreamPixel Stream"
></iframe>
<script>
const iframe = document.getElementById('streamPixelIframe');
const loadingScreen = document.getElementById('loadingScreen');
// Function to send a test message to the iframe
function sendCommand() {
const message = { message: 'test' };
iframe.contentWindow.postMessage(message, '*');
}
// Function to mute audio
function muteAudio() {
const message = { message: 'muteAudio' };
iframe.contentWindow.postMessage(message, '*');
}
// Function to unmute audio
function unMuteAudio() {
const message = { message: 'unMuteAudio' };
iframe.contentWindow.postMessage(message, '*');
}
// Function to terminate the session
function terminateSession() {
const message = { message: 'terminateSession' };
iframe.contentWindow.postMessage(message, '*');
}
// Listen for messages from the iframe
window.addEventListener('message', (event) => {
console.log('Message received:', event.data);
if (event.data === 'loadingComplete') {
// Remove the loading screen when loading is complete
loadingScreen.style.display = 'none';
console.log('Stream loading complete');
}
});
// Fallback: Remove the loading screen if iframe takes too long to respond
setTimeout(() => {
if (loadingScreen.style.display !== 'none') {
loadingScreen.style.display = 'none';
console.warn('Fallback: Loading screen removed due to timeout.');
}
}, 15000); // 15 seconds timeout
</script>
</body>
</html>
2. React Example
Code:
Last updated