| ... | ... | @@ -100,13 +100,16 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 100 | 100 | const send = (message: object) => { if (input?.readyState === "open") input.send(JSON.stringify(message)); }; |
| 101 | 101 | const compose = () => { |
| 102 | 102 | const frame = windowFrame; |
| 103 | | const composed = !!frame?.windows.length; |
| 104 | | video.classList.toggle("vm-video-composed", composed); |
| 105 | | canvas.hidden = !composed; |
| 106 | | if (!frame || !composed || !width || !height || video.readyState < 2) return; |
| 103 | canvas.hidden = !video.requestVideoFrameCallback || !video.srcObject || video.readyState < 2; |
| 104 | if (canvas.hidden || !props.active || !width || !height) return; |
| 107 | 105 | if (canvas.width !== width || canvas.height !== height) { canvas.width = width; canvas.height = height; } |
| 108 | 106 | const context = canvas.getContext("2d", { alpha: false }); |
| 109 | 107 | if (!context) return; |
| 108 | canvas.dataset.windows = String(frame?.windows.length ?? 0); |
| 109 | if (!frame?.windows.length) { |
| 110 | context.drawImage(video, 0, 0, width, height); |
| 111 | return; |
| 112 | } |
| 110 | 113 | context.fillStyle = "#101014"; |
| 111 | 114 | context.fillRect(0, 0, width, height); |
| 112 | 115 | for (const window of [...frame.windows].reverse()) { |
| ... | ... | @@ -118,7 +121,6 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 118 | 121 | } |
| 119 | 122 | context.drawImage(video, window.atlas_x, window.atlas_y, window.width, window.height, x, y, window.width, window.height); |
| 120 | 123 | } |
| 121 | | canvas.dataset.windows = String(frame.windows.length); |
| 122 | 124 | }; |
| 123 | 125 | const release = () => { buttons = 0; drag = undefined; compose(); send({ type: "release", sequence: ++pointerSequence }); }; |
| 124 | 126 | const connect = async () => { |
| ... | ... | @@ -227,9 +229,9 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 227 | 229 | windowFrame = undefined; pendingFrames = []; frameTimestamp = undefined; drag = undefined; |
| 228 | 230 | movement = undefined; pointerSequence = 0; |
| 229 | 231 | setFrameSync(false); setWindowsAvailable(false); setWindowCapture(false); setStats(undefined); setCapture(undefined); |
| 230 | | compose(); |
| 231 | 232 | video.onplaying = null; |
| 232 | 233 | video.srcObject = null; |
| 234 | compose(); |
| 233 | 235 | clearTimeout(cursorTimer); |
| 234 | 236 | cursorFrames = []; |
| 235 | 237 | cursorFrame = 0; |
| ... | ... | @@ -385,6 +387,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 385 | 387 | const current = attempt; |
| 386 | 388 | playbackFrame = requestAnimationFrame(() => { |
| 387 | 389 | if (disposed || current !== attempt || !props.active || !enabled() || document.hidden || !video.srcObject) return; |
| 390 | compose(); |
| 388 | 391 | void video.play().catch(() => { |
| 389 | 392 | if (!disposed && current === attempt && props.active && enabled() && !document.hidden && video.srcObject) { |
| 390 | 393 | setProblem("The browser couldn't play the screen. Reconnect to try again."); |
| ... | ... | @@ -488,7 +491,6 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 488 | 491 | <button class="button small" onClick={() => setBootScreen(true)}>View boot screen</button> |
| 489 | 492 | </div> |
| 490 | 493 | </Show> |
| 491 | | <canvas ref={canvas} class="vm-window-canvas" hidden aria-hidden="true" /> |
| 492 | 494 | <video ref={video} autoplay muted playsinline tabindex={preparing() ? -1 : 0} aria-hidden={preparing()} aria-label="VM screen" aria-describedby={`keyboard-release-${props.name}`} |
| 493 | 495 | onContextMenu={(event) => event.preventDefault()} |
| 494 | 496 | onPointerMove={pointer} |
| ... | ... | @@ -513,6 +515,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 513 | 515 | const mask = event.deltaY ? (event.deltaY < 0 ? 8 : 16) : event.deltaX < 0 ? 32 : 64; |
| 514 | 516 | pointer(event, buttons | mask); pointer(event); |
| 515 | 517 | }} /> |
| 518 | <canvas ref={canvas} class="vm-screen-canvas" hidden aria-hidden="true" /> |
| 516 | 519 | <img ref={cursorImage} class="vm-cursor" alt="" aria-hidden="true" /> |
| 517 | 520 | <img ref={cursorInvert} class="vm-cursor vm-cursor-invert" alt="" aria-hidden="true" /> |
| 518 | 521 | </div> |