"use strict";(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["8013"],{44331:function(e,t,n){n.r(t),n.d(t,{LiveKitLiveStreams:()=>V});var i=n(7409),a=n(99282),r=n(16584);n(94963);var l=n(30396),c=n(80569),o=n.n(c),d=n(68833),s=n(98914),h=n(6942),v=n(87949),u=n(53962),p=n(60807),g=n(7882),m=n(94874),Z=n(15771),y=n(19081),w=n(89263),_=n(21685),f=n(98248),b=n(58175),x=n(70379);let B=e=>{let{credentials:t,eventId:n,participantType:c,goLive:d,disconnect:v}=e,[g,m]=(0,l.eJ)(""),[_,f]=(0,l.eJ)([]),[B,X]=(0,l.eJ)([]),S=(0,p.aF)(),J=(0,x.pm)(),T=async e=>{if(e)try{let t=(await o().post("/api/v1/live_stream/".concat(n,"/invite_guest/").concat(e)).send()).body;X(e=>[...e,t])}catch(e){console.error("Error inviting user:",e)}},j=async e=>{try{let t=await o().put("/api/v1/live_stream/".concat(n,"/invite/").concat(e,"/remove")).send();window.alert("User ".concat(e," removed: ").concat(JSON.stringify(t.body)))}catch(e){window.alert("Error removing user: ".concat(e.message))}},N=async()=>{let e=await o().put("/api/v1/live_stream/".concat(n,"/leave_as_guest")).send();window.alert("User ".concat(null==S?void 0:S.id," left as guest: ").concat(JSON.stringify(e.body)))},q=async e=>{try{await o().put("/api/v1/live_stream/".concat(n,"/invite/").concat(e,"/cancel")).send(),X(t=>t.filter(t=>t.id!==e))}catch(e){console.error("Error canceling invite:",e)}};return(0,r.BX)(y.tu,{children:[(0,r.tZ)(y.gq,{style:{flexGrow:1},children:(0,r.BX)(h.IC,{video:!0,audio:!0,token:t.token,serverUrl:t.serverUrl,"data-lk-theme":"default",style:{height:"100vh"},onConnected:d,onDisconnected:v,children:[(0,r.tZ)(C,{setParticipants:f}),(0,r.tZ)(k,{streamId:n}),(0,r.tZ)(h.Z5,{}),(0,r.tZ)(h.VS,{})]})}),(0,r.BX)(y.gq,{gap:48,style:{width:"100%"},padding:12,children:["host"===c&&(0,r.BX)(r.HY,{children:[(0,r.BX)(y.tu,{maxWidth:320,gap:12,children:[(0,r.tZ)(w.n,{label:"Invite user by ID",placeholder:"User id to invite",value:g,onChange:e=>m(e)}),(0,r.tZ)(Z.zx,{onClick:()=>T(g),children:"Invite User"})]}),(0,r.tZ)(I,{onSubmit:T})]}),(0,r.BX)(y.tu,{gap:8,style:{width:"100%"},children:[(0,r.tZ)(b.xv.H2,{children:"Participants"}),(0,r.tZ)(y.tu,{gap:8,children:_.map(e=>(0,r.BX)(y.gq,{gap:12,alignItems:"center",children:[(0,r.tZ)(b.xv.B4,{children:e.sid}),(0,r.tZ)(b.xv.B4,{children:e.name}),(0,r.tZ)(b.xv.B4,{children:e.metadata}),"host"===c?(0,r.tZ)(Z.zx,{onClick:()=>j(JSON.parse(e.metadata).user_id),children:"Kick"}):JSON.parse(e.metadata).user_id===(null==S?void 0:S.id)&&(0,r.tZ)(Z.zx,{onClick:()=>N(),children:"Leave"})]},e.sid))})]}),"host"===c&&(0,r.BX)(y.tu,{gap:8,style:{width:"100%"},children:[(0,r.tZ)(b.xv.H2,{children:"Active Invites"}),(0,r.tZ)(y.tu,{gap:8,children:B.map(e=>(0,r.BX)(y.gq,{gap:12,alignItems:"center",children:[(0,r.BX)(b.xv.B4,{children:["Invite: ",e.id]}),(0,r.BX)(b.xv.B4,{children:["User: ",e.invited_user_id]}),(0,r.tZ)(Z.hU,{onClick:()=>{(0,s.vQ)("".concat(window.location.origin,"/live_event/").concat(n,"/guest?inviteId=").concat(e.id)),J.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"Copied link to clipboard"})))},children:(0,r.tZ)(u.Z,{size:20})}),(0,r.tZ)(Z.zx,{onClick:()=>q(e.id),children:"Cancel Invite"})]},e.id))})]})]})]})},C=e=>{let{setParticipants:t}=e,n=(0,h.BL)();return(0,l.d4)(()=>{t(n)},[n]),null},k=e=>{let{streamId:t}=e,n=(0,h.Ih)([{source:v.fQ.Source.Camera,withPlaceholder:!0},{source:v.fQ.Source.ScreenShare,withPlaceholder:!1}],{onlySubscribed:!0}),i=async()=>{console.log({body:(await o().get("/api/v1/live_stream/".concat(t,"/count")).send()).body})};return(0,l.d4)(()=>{let e=setInterval(()=>{i()},5e3);return()=>clearInterval(e)},[]),(0,r.tZ)(h.Me,{tracks:n,style:{height:"calc(100vh - var(--lk-control-bar-height))"},children:(0,r.tZ)(h.y7,{})})},I=e=>{let{onSubmit:t}=e,[n,i]=(0,l.eJ)(""),a=(0,l.sO)(null),[c,o]=(0,l.eJ)(!1),[d,s]=(0,l.eJ)(),{isLoading:h,result:v}=(0,g.ib)({pathname:"/api/v1/live_stream/guest_suggestions/search",method:"GET",query:{query:n},deps:[n],auto:!0});return(0,r.tZ)(y.gq,{children:(0,r.tZ)(_.J,{content:e=>{let{closePopover:t}=e;return h?(0,r.tZ)(f.$j,{}):(0,r.tZ)(y.tu,{gap:4,children:null==v?void 0:v.map(e=>(0,r.BX)(y.gq,{onClick:()=>{s(e),i(e.name),t()},alignItems:"center",gap:12,children:[(0,r.tZ)(m.qE,{size:40,photoUrl:e.photo_url}),(0,r.BX)(y.tu,{children:[(0,r.tZ)(b.xv.B4,{children:e.name}),e.handle&&(0,r.BX)(b.xv.B4,{color:"secondary",children:["@",e.handle]})]})]}))})},onClose:()=>{a.current!==document.activeElement&&o(!1)},onOpen:()=>{o(!0)},preferPlacement:"top-center",open:c,children:(0,r.BX)(y.tu,{gap:12,maxWidth:320,children:[(0,r.tZ)(w.n,{label:"Invited user",placeholder:"name or handle",value:n,onChange:e=>i(e),onFocus:()=>{c||o(!0)},inputRef:a}),(0,r.tZ)(Z.zx,{onClick:async()=>{(null==d?void 0:d.id)&&(await t(d.id),i(""),o(!1))},disabled:!(null==d?void 0:d.id),children:"Invite User"})]})})})};var X=n(32503),S=n(33804),J=n(20888),T=n(95441),j=n(49526),N=n(48980),q=n(80449),U=n(71068),P=n(96745),z=n(68709),E=n(17688),F=n(96302),A=n(51776),L=n(98012);let D=e=>{let{livestreamId:t,inviteId:n,onReject:i,onAcceptInvite:a}=e,l=(0,p.aF)(),{iString:c}=(0,T.M1)();if(!t||!l||!n)return null;let d=async()=>{try{(await o().put("/api/v1/live_stream/".concat(t,"/invite/").concat(n,"/decline")).send()).ok&&i()}catch(e){console.error("Error rejecting invite:",e)}};return(0,r.BX)(y.sg,{alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{translated:!0,children:"You have an active invite"}),(0,r.tZ)(Z.zx,{onClick:d,priority:"secondary",children:c("Reject Invite")}),(0,r.tZ)(Z.zx,{onClick:async()=>{try{let e=await o().put("/api/v1/live_stream/".concat(t,"/invite/").concat(n,"/accept")).send();e.ok&&a(e.body)}catch(e){console.error("Error accepting invite:",e)}},priority:"primary",children:c("Accept Invite")})]})},O=e=>{var t;let{joinCall:n,participantType:c,activeLiveStream:d}=e,{iString:s}=(0,T.M1)(),[v,u]=(0,l.eJ)(!1),[p,g]=(0,l.eJ)((null==d?void 0:d.liveStream.status)==="scheduled"),[m,w]=(0,l.eJ)((0,L.Z)().add(1,"hour").toDate()),[_,f]=(0,l.eJ)((null==d?void 0:d.liveStream.status)==="scheduled"),[B,C]=(0,l.eJ)(""),[k,I]=(0,l.eJ)("everyone"),[U,O]=(0,l.eJ)(""),[R,V]=(0,l.eJ)(!1);(0,l.d4)(()=>{(null==d?void 0:d.liveStream.status)==="scheduled"&&(g(!0),f(!0))},[d]);let W="host"===c,Y="guest"===c,K=(null==d?void 0:d.liveStream.status)==="active",Q=null==d?void 0:d.liveStreamInformation.desktopThumbnailGifUrl,$=null==d?void 0:d.liveStreamInformation.desktopThumbnailPhotoUrl,[ee]=(0,j.t)({key:"inviteId",initialValue:"",type:"number",isArray:!1}),[et,en]=(0,l.eJ)(null),ei=(0,x.pm)();(0,l.d4)(()=>{(async()=>{if(Y&&ee)try{let e=await o().get("/api/v1/live_stream/invite/".concat(ee)).send();if(e.ok){let t=e.body;en(t.activeLiveStream)}}catch(e){console.error("Error fetching invite info:",e)}})()},[Y,ee]);let ea="guest"===c?et?(0,r.tZ)(D,{livestreamId:null==d?void 0:d.liveStream.id,inviteId:ee,onReject:()=>{en(null)},onAcceptInvite:e=>{n(v,B,k,e)}}):(0,r.tZ)(b.xv.B4,{translated:!0,children:"No active invite"}):null,er=async()=>{try{V(!0),await (0,N.rd)("/api/v1/live_stream/".concat(null==d?void 0:d.liveStream.id,"/schedule_guest"),{method:"POST",json:parseInt(U)?{user_id:U}:{email:U}}),O(""),ei.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:s("Invite sent")})))}catch(e){alert((0,N.i)(e))}finally{V(!1)}};return(0,r.tZ)(S.w,{children:(0,r.BX)(y.sg,{padding:20,bg:"primary",gap:16,children:[(0,r.tZ)(y.sg,{children:(0,r.tZ)(b.xv.H3,{color:"primary",children:K?s("Join live video"):s("New live video")})}),(0,r.BX)(y.X2,{border:"detail",radius:"md",overflow:"hidden",shadow:"xs",children:[(0,r.BX)(y.sg,{className:"liveKitContainer-tDrfBy",padding:20,gap:20,alignItems:"center",flex:"grow",children:[(0,r.tZ)(b.xv.B3,{color:"secondary",textAlign:"center",children:s("For best viewing results on mobile, make sure your face is in the center of the video")}),(0,r.BX)(y.sg,{className:"overlayContainer-U0SSS1",children:[(0,r.tZ)(H,{}),(0,r.tZ)(h.tt,{"data-lk-theme":"default",onSubmit:()=>{n(v,B,k)},onValidate:()=>!W||!!K||B.length>0})]})]}),(0,r.BX)(G,{children:[ea,K&&(0,r.tZ)(q.b,{title:s("Live video in progress"),description:s("This live video is already started. Tap the button below to join now."),theme:"warn",priority:"secondary",Icon:X.Z,flex:"auto"}),W&&!K?(0,r.BX)(A.fv,{children:[(0,r.tZ)(z.__,{children:s("Event title")}),(0,r.tZ)(A.oi,{placeholder:s("Add a title..."),value:B,onChange:e=>C(e.currentTarget.value),maxLength:100})]}):null,W&&!K&&(0,r.BX)(A.fv,{children:[(0,r.tZ)(z.__,{children:s("Audience")}),(0,r.BX)(E.i,{name:"audience",value:k,onChange:e=>{I(e.target.value)},children:[(0,r.tZ)(E.d,{children:s("Select audience")}),(0,r.tZ)("option",{value:"everyone",children:s("Everyone")}),(0,r.tZ)("option",{value:"only_free",children:s("Free subscribers")}),(0,r.tZ)("option",{value:"only_paid",children:s("Paid subscribers")}),(0,r.tZ)("option",{value:"only_founding",children:s("Founding members")})]})]}),W&&!K?(0,r.tZ)(A.fv,{children:(0,r.BX)(y.gq,{paddingTop:12,gap:8,alignItems:"center",justifyContent:"space-between",children:[(0,r.tZ)(z.__,{children:s("Send as email")}),(0,r.tZ)(F.ZP,{checked:v,onChange:()=>{u(!v)}})]})}):null,W&&!K?(0,r.tZ)(A.fv,{children:(0,r.BX)(y.gq,{paddingTop:12,gap:8,alignItems:"center",justifyContent:"space-between",children:[(0,r.tZ)(z.__,{children:s("Schedule for later")}),(0,r.tZ)(F.ZP,{checked:p,onChange:()=>{g(!p)}})]})}):null,W&&!K&&p?(0,r.BX)(r.HY,{children:[(0,r.tZ)(A.fv,{children:(0,r.BX)(y.gq,{gap:8,alignItems:"center",justifyContent:"space-between",children:[(0,r.tZ)(z.__,{children:s("Schedule time")}),(0,r.tZ)(P.Tz,{value:m,onChange:e=>w(new Date(e.currentTarget.value))})]})}),(0,r.tZ)(Z.zx,{priority:"primary",onClick:async()=>{try{await (0,N.rd)("/api/v1/live_stream/".concat(null==d?void 0:d.liveStream.id,"/schedule"),{method:"PUT",json:{scheduledAt:m,audience:k,sendEmails:v,eventName:B}}),f(!0)}catch(e){alert((0,N.i)(e))}},children:_?s("Reschedule"):s("Schedule")})]}):null,W&&!K&&p&&_?(0,r.BX)(A.fv,{children:[(0,r.tZ)(z.__,{children:s("Invite by email or user id")}),(0,r.BX)(y.gq,{gap:8,alignItems:"center",justifyContent:"space-between",children:[(0,r.tZ)(A.oi,{placeholder:s("Add an email or user id..."),value:U,onKeyDown:e=>{"Enter"===e.key&&U&&er()},onChange:e=>{O(e.currentTarget.value)},maxLength:100,flex:"grow"}),(0,r.tZ)(Z.zx,{disabled:!U||R,loading:R,onClick:er,children:s("Invite")})]})]}):null,K&&(Q||$)&&(0,r.BX)(A.fv,{children:[(0,r.tZ)(z.__,{children:s("Preview")}),(0,r.tZ)(M,{children:(0,r.tZ)(J.e,{src:null!==(t=null!=Q?Q:$)&&void 0!==t?t:"",maxWidth:400,useRetinaSizing:!0,imageIsFixedWidth:!0})})]})]})]}),(0,r.BX)(y.X2,{justifyContent:"end",gap:8,children:[(0,r.tZ)(Z.zx,{priority:"secondary",onClick:()=>{window.history.back()},children:s("Cancel")}),(0,r.tZ)(Z.zx,{priority:"primary",onClick:()=>{let e=document.querySelector(".lk-join-button");e&&e.click()},disabled:W&&!K&&0===B.length,children:K?s("Join now"):s("Go Live")})]})]})})},G=(0,U.zo)({display:"flex",direction:"column",gap:12,minWidth:400,padding:20,sizing:"border-box"}),M=(0,U.zo)({display:"flex",direction:"column",radius:"sm",outline:"detail",overflow:"hidden"}),H=()=>(0,r.tZ)("svg",{className:"faceGuide-VFnUOm",viewBox:"0 0 200 240",preserveAspectRatio:"xMidYMid meet",children:(0,r.tZ)("path",{d:"M100 20c44.183 0 80 44.772 80 100s-35.817 100-80 100S20 175.228 20 120 55.817 20 100 20z"})}),R=[16,17],V=e=>{let{user:t,participantType:n,eventId:c}=e,h=(0,x.pm)(),[v,u]=(0,l.eJ)(null),[p,g]=(0,l.eJ)(null),[m,w]=(0,l.eJ)(!1),[_,f]=(0,l.eJ)(!1),[C,k]=(0,l.eJ)(!1),[I,X]=(0,l.eJ)("everyone"),[S,J]=(0,l.eJ)(""),[T,j]=(0,l.eJ)(!0),[N,q]=(0,l.eJ)(!0),[U,P]=(0,l.eJ)(!0),[z,L]=(0,l.eJ)(!0),[D,G]=(0,l.eJ)(!0),[M,H]=(0,l.eJ)(!0),[V,W]=(0,l.eJ)(!1),[Y,K]=(0,l.eJ)(R[R.length-1]),[Q,$]=(0,l.eJ)("");(0,l.d4)(()=>{(async()=>{let e=(await o().get("/api/v1/live_stream/".concat(c)).send()).body.activeLiveStream;u(e),e.liveStream.ended_streaming_at&&(f(!0),h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"This event has ended"}))))})()},[]);let ee=async()=>{try{let e=(await o().get("/api/v1/live_stream/".concat(c,"/credentials/").concat(n)).send()).body;g(e)}catch(e){401===e.status?(h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"You don't have access to this event"}))),setTimeout(()=>(0,s.uX)(window.location.origin),1500)):(h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"Unable to access event. Please try again."}))),console.error("Failed to load participant credentials",e))}},et=async(e,t,n,i)=>{i?g(i):await ee(),k(e),J(t),X(n),w(!0)},en=async()=>{"host"===n&&v&&"pending"===v.liveStream.status&&await o().put("/api/v1/live_stream/".concat(c,"/live")).send({emailSubscribers:!!C,eventName:S,audience:I})},ei=async()=>{"host"===n&&m&&await o().post("/api/v1/live_stream/".concat(c,"/end")).send()},ea=async()=>{if(null==v?void 0:v.liveStream.ended_streaming_at){let{body:e}=await o().post("/api/v1/live_stream/".concat(c,"/workflow")).send({useAiTrimming:z,useBrandedIntro:D,useIntroClip:M,useAudioEnhancer:N,useVideoEnhancer:U,useClipValidation:T,skipClipGeneration:V,version:Y});h.popToast(t=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},t),{text:"Workflow started with id ".concat(e.workflow_id)})))}else h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"This event has not ended"})))},er=async()=>{if(!isNaN(Number(Q))&&Number(Q)>0&&(null==v?void 0:v.liveStream.ended_streaming_at)){let e={use_ai_trimming:z,use_branded_intro:D,use_intro_clip:M,use_audio_enhancer:N,version:Y},{body:t}=await o().put("/api/v1/live_stream/".concat(c,"/reprocess_draft/").concat(Q)).send(e);(0,d.j)(d.FP.LIVE_STREAM_PODCAST_SETTINGS_CHANGE_REQUESTED,(0,a._)((0,i._)({live_stream_id:c,post_id:Q},e),{is_admin:!0})),h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"Workflow started with id ".concat(t.workflow_id)})))}else h.popToast(e=>(0,r.tZ)(x.FN,(0,a._)((0,i._)({},e),{text:"This event has not ended or Invalid post ID"})))};return _?(0,r.tZ)(y.tu,{padding:16,justifyContent:"center",alignItems:"center",children:(0,r.BX)(y.tu,{gap:16,width:400,children:[(0,r.tZ)(b.xv.H3,{children:"Event ended"}),(0,r.BX)(y.tu,{flex:"grow",gap:8,children:[(0,r.tZ)(b.xv.Meta,{children:"General"}),(0,r.tZ)(y.tu,{gap:8,padding:16,border:"detail",radius:"md",children:(0,r.tZ)(y.gq,{gap:8,justifyContent:"end",children:(0,r.tZ)(Z.zx,{priority:"secondary",onClick:()=>(0,s.uX)(window.location.origin),children:"Home"})})})]}),((0,s.WC)()||t.is_global_admin)&&(0,r.BX)(y.tu,{flex:"grow",gap:16,children:[(0,r.tZ)(b.xv.Meta,{children:"Draft Options"}),(0,r.BX)(y.tu,{gap:8,padding:16,border:"detail",radius:"md",children:[(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use Clip Validation"}),(0,r.tZ)(F.ZP,{checked:T,onChange:e=>j(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use Audio Enhancer"}),(0,r.tZ)(F.ZP,{checked:N,onChange:e=>q(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use Video Enhancer"}),(0,r.tZ)(F.ZP,{checked:U,onChange:e=>P(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use AI Trimming"}),(0,r.tZ)(F.ZP,{checked:z,onChange:e=>L(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use Branded Intro"}),(0,r.tZ)(F.ZP,{checked:D,onChange:e=>G(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Use Intro Clip"}),(0,r.tZ)(F.ZP,{checked:M,onChange:e=>H(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Skip Clip Generation"}),(0,r.tZ)(F.ZP,{checked:V,onChange:e=>W(e)})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Version"}),(0,r.tZ)(E.i,{value:Y,onChange:e=>K(parseInt(e.currentTarget.value)),children:R.map(e=>(0,r.tZ)("option",{value:e,children:e},e))})]}),(0,r.BX)(y.gq,{flex:"grow",justifyContent:"space-between",alignItems:"center",children:[(0,r.tZ)(b.xv.B3,{color:"primary",weight:"semibold",children:"Post ID"}),(0,r.tZ)(A.oi,{value:Q,onChange:e=>$(e.currentTarget.value)})]}),(0,r.BX)(y.gq,{flex:"grow",gap:8,justifyContent:"end",children:[(0,r.tZ)(Z.zx,{priority:"secondary-outline",onClick:er,children:"Update Draft"}),(0,r.tZ)(Z.zx,{onClick:ea,children:"Create Draft"})]})]})]})]})}):m?(null==p?void 0:p.token)?(0,r.tZ)(B,{participantType:n,credentials:p,eventId:c,goLive:en,disconnect:ei}):(0,r.tZ)("div",{className:"main-loader",children:"Loading..."}):(0,r.tZ)(O,{joinCall:et,participantType:n,activeLiveStream:v})}}}]);