When running live campus broadcasts for events like convocation or debates, stream availability matters. If an upstream encoder suffers packet loss or disconnects, the video player needs to recover immediately without leaving viewers on a frozen screen.
1. Three-Tier Failover Architecture
Standard HTTP Live Streaming (HLS) delivers media in short 2- to 6-second segments listed in an .m3u8 playlist. When an encoder goes offline, default players simply stall. In Campus TV, we handle this with a three-tier fallback pipeline:
2. Real-Time Viewer Tracking with Socket.IO
Instead of polling the database to keep track of active viewers, we read live room occupancy directly from Socket.IO:
io.on('connection', (socket) => {
socket.on('live:join', () => {
socket.join('live_broadcast');
const count = io.sockets.adapter.rooms.get('live_broadcast')?.size || 0;
io.to('live_broadcast').emit('live:viewers', { active: count });
});
socket.on('disconnect', () => {
const count = io.sockets.adapter.rooms.get('live_broadcast')?.size || 0;
io.emit('live:viewers', { active: count });
});
});
3. Buffer Delay & Latency
End-to-end broadcast latency in HTTP chunked delivery depends directly on segment duration and the client buffer depth:
4. Summary
Handling failovers on the client and keeping lightweight fallback streams ready ensures viewers get uninterrupted live coverage, even during unexpected network hiccups.