Show your camera on a screen
Updated
A script draws a clock on a canvas and writes it into a stream that one screen plays; clicking the button publishes your camera to the mirror screen.
Watch the clock screen tick. Click the amber button and allow the camera to see yourself on the mirror. Drag elsewhere to orbit the camera.
Show your camera on a screen
#pragma lifecycle(startup, update)
let canvas;let writer;
// Draw at most 4 frames a second: the clock changes once a second.const drawClock = throttle(() => { const ctx = canvas.getContext('2d'); ctx.fillStyle = '#0f172a'; ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = '#f8fafc'; ctx.font = '64px sans-serif'; ctx.fillText(new Date().toLocaleTimeString(), 24, 110); writer.writeVideoFrame(canvas);}, 250);
function startup() { canvas = Canvas.create(320, 180); writer = Streams.create('clock', { video: { width: 320, height: 180 } });
on('mirror/button', async (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again if (Streams.has('me/camera')) return; if (await Input.camera.start({ facing: 'user' })) { Streams.publish('me/camera', Input.camera.stream()); } });
on('mirror', (event) => { if (event.eventType === EventType.MediaStream.Connected) log('Mirror showing', event.data.stream); if (event.eventType === EventType.MediaStream.Disconnected) log('Mirror lost', event.data.stream); });}
function update() { drawClock();}How it works
Section titled “How it works”The script is explained step by step in Show your camera on a screen.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
LiveScreens.xrproj