1
0
mirror of https://github.com/ZeroCatDev/Classworks.git synced 2026-03-21 09:13:10 +00:00
Classworks/assets/socketClient-BSmNJE3a.js

2 lines
1.1 KiB
JavaScript

import{l as f}from"./vendor-socket-CyTcV1HU.js";import{n as l}from"./index-C2sjQt3C.js";import{i as a,g as u}from"./serverRotation-DZGX69ae.js";let e=null,c=null;const r=new Set;function m(){var o,s;if(a())return u();const n=l("server.domain"),t=(s=(o=import.meta)==null?void 0:o.env)==null?void 0:s.VITE_SERVER_URL;return n||t||window.location.origin}function i(){const n=m();if(!e||c!==n){if(e){try{e.disconnect()}catch{}e=null}c=n,e=f(n,{transports:["polling","websocket"]}),r.forEach(({event:t,handler:o})=>{e.on(t,o)})}return e}function k(n,t){return i().on(n,t),r.add({event:n,handler:t}),()=>v(n,t)}function v(n,t){if(e){e.off(n,t);for(const o of Array.from(r))o.event===n&&o.handler===t&&r.delete(o)}}function E(n){const t=i();n&&t.emit("join-token",{token:n})}function S(n){e&&e.emit("leave-token",{token:n})}function U(){e&&e.emit("leave-all")}function w(n){const t=i();return t.on("connect",n),()=>t.off("connect",n)}function R(n,t=null){i().emit("send-event",{type:n,content:t})}function b(){if(e){try{e.disconnect()}catch{}e=null,c=null,r.clear()}}export{k as a,S as b,m as c,b as d,i as g,E as j,U as l,w as o,R as s};