'use client' import { useEffect, useRef, useState } from 'react' import Link from 'next/link' export default function LivePage() { const videoRef = useRef(null) const [streamKey, setStreamKey] = useState('') const [isPlaying, setIsPlaying] = useState(false) const [error, setError] = useState(null) const [showSetup, setShowSetup] = useState(false) function startWatching() { if (!streamKey.trim()) return setError(null) setIsPlaying(true) } useEffect(() => { if (!isPlaying || !videoRef.current) return const hlsUrl = `/hls/${streamKey}.m3u8` async function initPlayer() { const Hls = (await import('hls.js')).default if (Hls.isSupported()) { const hls = new Hls({ lowLatencyMode: true, liveSyncDurationCount: 3, }) hls.loadSource(hlsUrl) hls.attachMedia(videoRef.current!) hls.on(Hls.Events.MANIFEST_PARSED, () => { videoRef.current?.play().catch(() => {}) }) hls.on(Hls.Events.ERROR, (_event, data) => { if (data.fatal) { setError('Stream not found or ended. Check the stream key and try again.') setIsPlaying(false) } }) return () => hls.destroy() } else if (videoRef.current?.canPlayType('application/vnd.apple.mpegurl')) { // Safari native HLS videoRef.current.src = hlsUrl videoRef.current.play().catch(() => {}) } else { setError('HLS playback is not supported in this browser.') setIsPlaying(false) } } const cleanup = initPlayer() return () => { cleanup?.then((fn) => fn?.()) } }, [isPlaying, streamKey]) return (
{/* Nav */}

Live Stream

{/* Stream viewer */} {!isPlaying ? (

Watch a Stream

Enter the stream key to watch a live broadcast from your community.

setStreamKey(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && startWatching()} className="w-full px-4 py-3 bg-black/30 border border-slate-700 rounded-lg text-white placeholder-slate-500 mb-4 text-sm focus:outline-none focus:border-red-500" /> {error && (

{error}

)}
{/* OBS Setup */}
{showSetup && (

OBS Studio

  1. Open Settings → Stream
  2. Set Service to Custom
  3. Server: rtmp://rtube.online:1936/live
  4. Stream Key: choose any key (e.g. community-meeting)
  5. Click Start Streaming

FFmpeg

ffmpeg -i input.mp4 -c:v libx264 -preset veryfast -c:a aac -f flv rtmp://rtube.online:1936/live/your-key
)}
) : (
LIVE Stream: {streamKey}
)}
) }