UNPKG

18x

Version:

util js for build web site

1 lines 557 B
const R=e=>{let n,s;let o=new BroadcastChannel(""),send=(e,...n)=>o.postMessage([e,n]),conn=()=>{let o=s;if(!o){null!=n&&n.close();return}Object.assign(n=new WebSocket(`wss:${e}ws/`+o.slice(0,2).map(e=>e.toString(36)).join("/")),{binaryType:"arraybuffer",onmessage:({data:e})=>{let n=e.indexOf("["),t=parseInt(e.slice(0,n),36);0===t&&send(t,s=[o[0],...JSON.parse(e.slice(n)+"]")])},onclose:()=>{s&&setTimeout(conn,1e3)}})};onconnect=({ports:e})=>{e[0].onmessage=({data:e})=>{[e=>{if(s&&e){if(s[0]===e[0]){s=e;return}n.close()}s=e,conn()}][e[0]](...e[1])}}};