Spaces:
Running
Running
fix: browser streaming not updating and clicks not working
Browse filesStreaming Improvements:
- Added image preloading to prevent flickering
- Added frame counter for better cache-busting
- Reduced update frequency to 1 second for better performance
- Added onload/onerror handlers for debugging
- Console logging for stream start and frame updates
Click Handling:
- Removed overlay div that was blocking clicks
- Attached click handler directly to image element
- Added visual feedback (pulse animation) on click
- Better coordinate calculation with scale factors
- Added console logging for click debugging
- Error handling for failed click requests
Debugging:
- Console logs for stream operations
- Console logs for click coordinates
- Error messages for failed operations
- static/qaz.html +56 -9
static/qaz.html
CHANGED
|
@@ -797,8 +797,7 @@
|
|
| 797 |
|
| 798 |
<!-- Video Stream -->
|
| 799 |
<div class="browser-stream-container">
|
| 800 |
-
<img id="browser-stream" class="browser-stream" src="" alt="Browser Stream">
|
| 801 |
-
<div class="browser-overlay" id="browser-overlay" onclick="handleStreamClick(event)"></div>
|
| 802 |
|
| 803 |
<div class="browser-loading" id="browser-loading" style="display:none;">
|
| 804 |
<div class="spinner"></div>
|
|
@@ -1090,18 +1089,32 @@
|
|
| 1090 |
|
| 1091 |
const img = document.getElementById('browser-stream');
|
| 1092 |
const quality = streamQuality === 'low' ? 0.5 : streamQuality === 'medium' ? 0.75 : 1;
|
|
|
|
| 1093 |
|
| 1094 |
-
//
|
| 1095 |
const updateFrame = () => {
|
| 1096 |
if (!currentProvider) return;
|
| 1097 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1098 |
};
|
| 1099 |
|
| 1100 |
-
// Update every
|
| 1101 |
-
streamInterval = setInterval(updateFrame,
|
| 1102 |
updateFrame();
|
| 1103 |
|
| 1104 |
document.getElementById('browser-status-dot').classList.add('streaming');
|
|
|
|
| 1105 |
}
|
| 1106 |
|
| 1107 |
function setStreamQuality(quality) {
|
|
@@ -1146,14 +1159,40 @@
|
|
| 1146 |
}
|
| 1147 |
|
| 1148 |
function handleStreamClick(event) {
|
| 1149 |
-
if (!currentProvider)
|
|
|
|
|
|
|
|
|
|
| 1150 |
|
| 1151 |
const rect = event.target.getBoundingClientRect();
|
| 1152 |
-
const
|
| 1153 |
-
const
|
|
|
|
|
|
|
| 1154 |
|
|
|
|
| 1155 |
document.getElementById('browser-coords').textContent = `Click: ${x}, ${y}`;
|
| 1156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1157 |
fetch('/qaz/portal/action', {
|
| 1158 |
method: 'POST',
|
| 1159 |
headers: { 'Content-Type': 'application/json' },
|
|
@@ -1163,6 +1202,14 @@
|
|
| 1163 |
x: x,
|
| 1164 |
y: y
|
| 1165 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1166 |
});
|
| 1167 |
}
|
| 1168 |
|
|
|
|
| 797 |
|
| 798 |
<!-- Video Stream -->
|
| 799 |
<div class="browser-stream-container">
|
| 800 |
+
<img id="browser-stream" class="browser-stream" src="" alt="Browser Stream" onclick="handleStreamClick(event)" style="cursor: crosshair;">
|
|
|
|
| 801 |
|
| 802 |
<div class="browser-loading" id="browser-loading" style="display:none;">
|
| 803 |
<div class="spinner"></div>
|
|
|
|
| 1089 |
|
| 1090 |
const img = document.getElementById('browser-stream');
|
| 1091 |
const quality = streamQuality === 'low' ? 0.5 : streamQuality === 'medium' ? 0.75 : 1;
|
| 1092 |
+
let frameCount = 0;
|
| 1093 |
|
| 1094 |
+
// Preload image to prevent flickering
|
| 1095 |
const updateFrame = () => {
|
| 1096 |
if (!currentProvider) return;
|
| 1097 |
+
|
| 1098 |
+
const newSrc = `/qaz/portal/${currentProvider}/screenshot?t=${Date.now()}&quality=${quality}&frame=${frameCount++}`;
|
| 1099 |
+
|
| 1100 |
+
// Create a new image to preload
|
| 1101 |
+
const preloadImg = new Image();
|
| 1102 |
+
preloadImg.onload = () => {
|
| 1103 |
+
// Only update src after image is loaded
|
| 1104 |
+
img.src = newSrc;
|
| 1105 |
+
};
|
| 1106 |
+
preloadImg.onerror = () => {
|
| 1107 |
+
console.error('Failed to load screenshot');
|
| 1108 |
+
};
|
| 1109 |
+
preloadImg.src = newSrc;
|
| 1110 |
};
|
| 1111 |
|
| 1112 |
+
// Update every 1000ms (1 second) for better performance
|
| 1113 |
+
streamInterval = setInterval(updateFrame, 1000);
|
| 1114 |
updateFrame();
|
| 1115 |
|
| 1116 |
document.getElementById('browser-status-dot').classList.add('streaming');
|
| 1117 |
+
console.log('Stream started for provider:', currentProvider);
|
| 1118 |
}
|
| 1119 |
|
| 1120 |
function setStreamQuality(quality) {
|
|
|
|
| 1159 |
}
|
| 1160 |
|
| 1161 |
function handleStreamClick(event) {
|
| 1162 |
+
if (!currentProvider) {
|
| 1163 |
+
console.log('No provider selected');
|
| 1164 |
+
return;
|
| 1165 |
+
}
|
| 1166 |
|
| 1167 |
const rect = event.target.getBoundingClientRect();
|
| 1168 |
+
const scaleX = 1280 / rect.width;
|
| 1169 |
+
const scaleY = 800 / rect.height;
|
| 1170 |
+
const x = Math.round((event.clientX - rect.left) * scaleX);
|
| 1171 |
+
const y = Math.round((event.clientY - rect.top) * scaleY);
|
| 1172 |
|
| 1173 |
+
console.log(`Click at ${x}, ${y} on ${currentProvider}`);
|
| 1174 |
document.getElementById('browser-coords').textContent = `Click: ${x}, ${y}`;
|
| 1175 |
|
| 1176 |
+
// Visual feedback
|
| 1177 |
+
const img = event.target;
|
| 1178 |
+
const feedback = document.createElement('div');
|
| 1179 |
+
feedback.style.cssText = `
|
| 1180 |
+
position: absolute;
|
| 1181 |
+
left: ${event.clientX - rect.left}px;
|
| 1182 |
+
top: ${event.clientY - rect.top}px;
|
| 1183 |
+
width: 20px;
|
| 1184 |
+
height: 20px;
|
| 1185 |
+
border: 3px solid var(--accent);
|
| 1186 |
+
border-radius: 50%;
|
| 1187 |
+
transform: translate(-50%, -50%);
|
| 1188 |
+
pointer-events: none;
|
| 1189 |
+
z-index: 100;
|
| 1190 |
+
animation: pulse 0.5s ease-out;
|
| 1191 |
+
`;
|
| 1192 |
+
img.parentElement.appendChild(feedback);
|
| 1193 |
+
setTimeout(() => feedback.remove(), 500);
|
| 1194 |
+
|
| 1195 |
+
// Send click to backend
|
| 1196 |
fetch('/qaz/portal/action', {
|
| 1197 |
method: 'POST',
|
| 1198 |
headers: { 'Content-Type': 'application/json' },
|
|
|
|
| 1202 |
x: x,
|
| 1203 |
y: y
|
| 1204 |
})
|
| 1205 |
+
}).then(res => {
|
| 1206 |
+
if (!res.ok) {
|
| 1207 |
+
console.error('Click failed:', res.status);
|
| 1208 |
+
} else {
|
| 1209 |
+
console.log('Click sent successfully');
|
| 1210 |
+
}
|
| 1211 |
+
}).catch(err => {
|
| 1212 |
+
console.error('Click error:', err);
|
| 1213 |
});
|
| 1214 |
}
|
| 1215 |
|