char/live.umm.gay
git clone https://git.t4t.associates/char/live.umm.gay
be8b658
main
1import Head from "next/head" ; 2import { useRouter } from "next/router" 3import React from "react" 4 5const WHEP_API_LOCATION = "/api/wish-server/whep" 6 7const Video = ({ user} :{ user :string }) => { 8const videoRef = React . createRef < HTMLVideoElement >(); 9React . useEffect (() => { 10const peerConnection = new RTCPeerConnection () 11 12peerConnection . ontrack = function ( event ) { 13videoRef . current ! . srcObject = event . streams [ 0 ] 14} 15 16peerConnection . addTransceiver ( 'audio' ) 17peerConnection . addTransceiver ( 'video' ) 18 19 20peerConnection . createOffer (). then ( async offer => { 21peerConnection . setLocalDescription ( offer ) 22 23const response = await fetch ( WHEP_API_LOCATION , { 24method :'POST' , 25body :offer . sdp , 26headers :{ 27Authorization :`Bearer ${ user } ` , 28'Content-Type' :'application/sdp' 29} 30}) 31 32if ( response . status >= 200 && response . status < 300 ) { 33const sdp = await response . text (); 34peerConnection . setRemoteDescription ({ 35 sdp, 36type :'answer' 37}) 38} 39}) 40 41return function cleanup () { 42peerConnection . close () 43} 44}, [ videoRef , user ]) 45 46return < video ref = { videoRef } autoPlay muted controls playsInline /> 47} 48 49export default () => { 50const router = useRouter () 51const { user} = router . query ; 52const Player = ({ user} :{ user :any }) => { 53if ( typeof user !== "string" ) { 54return <> 55< strong > The requested user was not found. </ strong > 56</> 57} 58 59return <> 60< Video user = { user }></ Video > 61</> 62} 63 64return <> 65< Head > 66< title >{ ` ${ user } | live.umm.gay` }</ title > 67</ Head > 68 69< main > 70< h1 > watching: { user }</ h1 > 71< Player user = { user }/> 72{ /* TODO: Chat? */ } 73</ main > 74</> 75}