Mission control for VR lessons: teachers see which headsets are online, launch lessons and watch a student's VR view live in the browser. Laravel + Reverb + WebRTC + Next.js.

Teachers running a class of students wearing VR headsets — who need to know what's going on behind thirty pairs of goggles.
Solo build across four repositories — Laravel API, Next.js teacher dashboard, landing page and a WebRTC signalling server. The VR headset app is developed separately and talks to my API.
Put a teacher back in control of a classroom where every student is inside a headset: who's connected, who's in which lesson, and what are they actually looking at — in real time.
A Laravel 13 API with Sanctum auth and Reverb WebSockets drives live state; presence channels show which headsets are online. Video goes peer-to-peer over WebRTC through a tiny Node signalling server, so Laravel never touches the media stream.
A teacher sees every headset's status and current lesson live, without refreshing.
Live view of a student's VR perspective streams straight into the dashboard.
A lazily created Laravel Echo singleton on top of Reverb. Channel authorisation is proxied through a Next.js route, so the Sanctum cookie stays HttpOnly.
'use client';
import Echo from 'laravel-echo';
import Pusher, { type ChannelAuthorizationCallback } from 'pusher-js';
let echoInstance: InstanceType<typeof Echo> | null = null;
export function getEcho() {
if (echoInstance) return echoInstance;
window.Pusher = Pusher;
echoInstance = new Echo({
broadcaster: 'reverb',
key: process.env.NEXT_PUBLIC_REVERB_APP_KEY,
wsHost: process.env.NEXT_PUBLIC_REVERB_HOST,
wsPort: Number(process.env.NEXT_PUBLIC_REVERB_PORT ?? 8080),
wssPort: Number(process.env.NEXT_PUBLIC_REVERB_PORT ?? 8080),
forceTLS: process.env.NEXT_PUBLIC_REVERB_SCHEME === 'https',
enabledTransports: ['ws', 'wss'],
// Channel auth goes through a Next.js route, so the Sanctum session
// cookie never has to be exposed to client-side JavaScript.
authorizer: (channel: { name: string }) => ({
authorize: (socketId: string, callback: ChannelAuthorizationCallback) => {
fetch('/api/broadcasting/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ socket_id: socketId, channel_name: channel.name }),
})
.then((res) => res.json())
.then((data) => callback(null, data))
.catch((err) => callback(err instanceof Error ? err : new Error(String(err)), null));
},
}),
});
return echoInstance;
}No REST endpoint, no cron: devices join a presence channel, and here/joining/leaving events keep a Set of online IDs up to date for every component that asks.
function useDevicePresence(schoolId: string | null | undefined): Set<string> {
const [onlineDeviceIds, setOnlineDeviceIds] = useState<Set<string>>(EMPTY_SET);
useEffect(() => {
if (!schoolId) return;
// Every headset joins this presence channel when it opens its socket,
// so Reverb tells us who is online — no polling, no webhooks.
const channel = getEcho().join(`school.${schoolId}.devices`);
channel
.here((members: PresenceMember[]) => {
setOnlineDeviceIds(
new Set(members.map(deviceIdFromMember).filter((id): id is string => id !== null)),
);
})
.joining((member: PresenceMember) => {
const id = deviceIdFromMember(member);
if (!id) return;
setOnlineDeviceIds((prev) => new Set(prev).add(id));
})
.leaving((member: PresenceMember) => {
const id = deviceIdFromMember(member);
if (!id) return;
setOnlineDeviceIds((prev) => {
const next = new Set(prev);
next.delete(id);
return next;
});
});
return () => {
getEcho().leave(`school.${schoolId}.devices`);
setOnlineDeviceIds(EMPTY_SET);
};
}, [schoolId]);
return schoolId ? onlineDeviceIds : EMPTY_SET;
}The teacher's browser opens one RTCPeerConnection per headset. A minimal WebSocket signalling server swaps offers and ICE candidates; when a headset leaves, its connection is torn down cleanly.
export class StreamViewer {
private ws: WebSocket | null = null;
private readonly peerConnections = new Map<string, RTCPeerConnection>();
private readonly pendingCandidates = new Map<string, RTCIceCandidateInit[]>();
private readonly peerId: string;
private closed = false;
constructor(
private readonly sessionId: string,
participantId: string,
private readonly callbacks: StreamViewerCallbacks
) {
this.peerId = `teacher-${participantId}`;
}
connect() {
if (this.closed) return;
const base = process.env.NEXT_PUBLIC_SIGNALING_URL ?? 'ws://localhost:3000';
const ws = new WebSocket(`${base}?sessionId=${this.sessionId}&peerId=${this.peerId}`);
this.ws = ws;
ws.onmessage = (event) => {
const msg: SignalingMessage = JSON.parse(event.data);
switch (msg.type) {
case 'offer':
void this.handleOffer(msg);
break;
case 'ice-candidate':
void this.handleIceCandidate(msg);
break;
case 'peer-left':
if (msg.clientId) {
this.peerConnections.get(msg.clientId)?.close();
this.peerConnections.delete(msg.clientId);
this.pendingCandidates.delete(msg.clientId);
}
break;
}
};
// …
}
}Headsets join a Reverb presence channel when they connect, so “who's online” is pushed instantly instead of being asked for every few seconds.
A dedicated signalling server only brokers the WebRTC handshake; the stream flows headset → browser and never loads the API.
HttpOnly session cookies plus a Next.js route for channel auth means no token ever sits in client-side JavaScript.
Real-time is mostly about the unhappy path: sockets drop, headsets sleep, ICE candidates arrive before the offer. Buffering and cleaning up per peer mattered more than the happy-path code.