blog/source/files/magicbroad/assets/index.b2b53b3b.js

3 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-06-09 01:09:09 +00:00
import{q as d,g as F,H as G,v as B,i as t,d as l,S as J,I as y,t as S,r as M,z as T}from"./index.13b310ab.js";import{B as P}from"./Button.f5ab4cd7.js";import{T as D}from"./TextField.2ea54ac2.js";import{u as j}from"./solid.5ae8e60d.js";import{P as z,S as H,R as O}from"./index.79b5287a.js";import{v as V}from"./getDeviceId.e8f3946a.js";import"./ButtonBase.9bf595f5.js";import"./isHostComponent.9ebad583.js";const A=S('<p>Peer "<!>" [changed x<!>], clk <!>, connectionState <!>, singalingState </p>'),K=S("<p>Loading participants...</p>"),Q=S("<div><p>User: </p><br><br><p>User-Device Id: </p><div><p>Participants:</p><ul></ul></div><div><p>Peers:</p><ul></ul></div></div>"),W=S("<li>User Id: </li>"),X=S("<li>No peers.</li>"),Y=S("<li></li>"),Z=i=>{const[h,s]=d(z.unknown),[b,R]=d("stable"),[f,o]=d(0),C=n=>{s(n),o(g=>g+1)},u=()=>{R(i.peer.connection.signalingState),o(n=>n+1)};return M(()=>{s(i.peer.connectionState)}),T(()=>{i.peer.bus.on("connectionstatechange",C),i.peer.connection.addEventListener("signalingstatechange",u)}),B(()=>{i.peer.bus.detach("connectionstatechange",C),i.peer.connection.removeEventListener("signalingstatechange",u)}),(()=>{const n=A.cloneNode(!0),g=n.firstChild,_=g.nextSibling,$=_.nextSibling,v=$.nextSibling,w=v.nextSibling,x=w.nextSibling,e=x.nextSibling,c=e.nextSibling;return c.nextSibling,t(n,()=>i.peer.userDeviceId,_),t(n,f,v),t(n,()=>i.peer.clk.toString(),x),t(n,h,c),t(n,b,null),n})()},se=()=>{const[i,h]=d(""),[s,b]=d(""),[R,f]=d([],{equals:!1}),o=j(),C=F(),[u,n]=d(),[g,_]=G(()=>V(s())?o.getParticipants(s()):[]),$=async e=>{await o.isJoinedRoomById(e)||await o.joinRoomById(e),_.refetch();const c=H.ofRoom(o.supabase,e,o.getUserDeviceId()),r=new O(o.getUserDeviceId(),c,e);r.bus.on("addpeer",()=>{f(r.peers)}),r.bus.on("removepeer",m=>{m.disconnect(),f(r.peers)}),await r.broadcastPeerList(),n(r)},v=async()=>{const e=await o.createRoom(i());b(e.id),h(e.name),await $(e.id)},w=async()=>{const e=await o.findRoomById(s());e?(b(e.id),h(e.name),await $(e.id)):alert(`Could not found room ${s()}`)};B(async()=>{const e=u();e&&(await e.stop(),n())});const x=()=>{const e=u();if(e)return e.userDeviceId};return(()=>{const e=Q.cloneNode(!0),c=e.firstChild;c.firstChild;const r=c.nextSibling,m=r.nextSibling,N=m.nextSibling;N.firstChild;const I=N.nextSibling,k=I.firstChild,L=k.nextSibling,U=I.nextSibling,E=U.firstChild,q=E.nextSibling;return t(c,()=>JSON.stringify(C.user(),void 0,2),null),t(e,l(D,{variant:"standard",get value(){return i()},label:"Room Name",onChange:a=>h(a.target.value)}),r),t(e,l(P,{onClick:v,children:"Create New Room"}),r),t(e,l(D,{variant:"standard",get value(){return s()},label:"Room ID",onChange:a=>b(a.target.value)}),m),t(e,l(P,{onClick:w,children:"Enter Room"}),m),t(e,l(P,{onClick:()=>{const a=u();a&&a.broadcastPeerList()},children:"Sync Peer List"}),m),t(N,()=>x()||"unknown",null),t(I,l(J,{get when(){return g.loading},get children(){return K.cloneNode(!0)}}),k),t(L,l(y,{get each(){return g()},children:a=>(()=>{const p=W.cloneNode(!0);return p.firstChild,t(p,()=>a.user_id,null),p})()})),t(q,l(y,{get each(){return R()},get fallback(){return X.cloneNode(!0)},children:a=>(()=>{const p=Y.cloneNode(!0);return t(p,l(Z,{peer:a})),p})()})),e})()};export{se as default};
//# sourceMappingURL=index.b2b53b3b.js.map