(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1245],{24886:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/stream",function(){return r(19891)}])},19891:function(e,t,r){"use strict";r.r(t);var n=r(85893),a=r(67294),o=r(53920);r(74581);var s=r(28469),i=r(83454);let c=(0,o.ZP)(i.env.NEXT_PUBLIC_SOCKET_URL),l={streamTitle:{fontSize:"36px",marginBottom:"20px",display:"none"},streamerVideo:{width:"100%",minHeight:"70vh",border:"1px solid #ccc",marginBottom:"20px"},streamingBtnGroup:{textAlign:"center"},startStreamingBtn:{padding:"10px 20px",fontSize:"18px",cursor:"pointer",backgroundColor:"#007bff",color:"#fff",border:"none"},endStreamingBtn:{padding:"10px 20px",fontSize:"18px",cursor:"pointer",backgroundColor:"#dc3545",color:"#fff",border:"none"}};t.default=()=>{let[e,t]=(0,a.useState)(null),[r,o]=(0,a.useState)([]),[i,d]=(0,a.useState)(null);(0,a.useRef)(),(0,a.useRef)(),(0,a.useRef)();let[u,m]=(0,a.useState)(null),[f,h]=(0,a.useState)(null),[g,p]=(0,a.useState)(""),S=(0,a.useRef)();(0,a.useRef)();let v=(0,a.useRef)(),[x,y]=(0,a.useState)(""),start=async()=>{try{let e=new MediaRecorder(i,{mimeType:"video/webm",videoBitsPerSecond:3145728});e.ondataavailable=async e=>{if(e.data.size>0){let t=new FormData;t.append("video",e.data);try{await fetch("".concat((0,s.JW)(),"/stream/upload-video\n                        "),{method:"POST",body:t})}catch(e){console.error("Error uploading video chunk:",e)}}},e.start(1e3)}catch(e){console.error("Error starting broadcast:",e)}},end=async()=>{window.mediaRecorder&&window.mediaRecorder.stop();try{await fetch("".concat((0,s.JW)(),"/stream/stop-broadcast"),{method:"POST"})}catch(e){console.error("Error stopping broadcast:",e)}},clientCome=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;console.log("localStream",t),t?(c.emit("stream-client-request",{clientPeerId:e,message:"Accept"}),S.current.call(null!=e?e:g,t)):c.emit("stream-client-request",{clientPeerId:e,message:"Reject"})};return(0,a.useEffect)(()=>{let getMediaStream=async()=>{try{let e=await navigator.mediaDevices.getUserMedia({video:!0,audio:!0});d(e)}catch(e){console.error("Error accessing media devices:",e)}};return getMediaStream(),()=>{i&&i.getTracks().forEach(e=>e.stop())}},[]),(0,a.useEffect)(()=>{let handleStreamEvent=t=>{clientCome(t,e)};return c.on("stream",handleStreamEvent),()=>{c.off("stream",handleStreamEvent)}},[e]),(0,a.useEffect)(()=>{window.location.href.includes("http://localhost:4000/auth/google/callback")&&console.log("Authenticated successfully!")},[]),(0,n.jsxs)("div",{style:{textAlign:"center"},children:[(0,n.jsx)("h1",{style:l.streamTitle,children:(0,n.jsx)("input",{type:"text",value:f,disabled:!0})}),(0,n.jsx)("div",{style:l.streamerVideo,children:(0,n.jsx)("video",{width:"560",height:"315",autoPlay:!0,controls:!0,ref:e=>{e&&i&&(e.srcObject=i)}})}),(0,n.jsxs)("div",{style:l.streamingBtnGroup,children:[(0,n.jsx)("button",{style:l.startStreamingBtn,onClick:start,children:"Start Streaming"}),(0,n.jsx)("button",{style:l.endStreamingBtn,onClick:end,children:"End Streaming"})]}),(0,n.jsx)("div",{children:(0,n.jsx)("video",{ref:v,autoPlay:!0,muted:!0})})]})}}},function(e){e.O(0,[3920,9774,2888,179],function(){return e(e.s=24886)}),_N_E=e.O()}]);