/*!
 DMXzone Sockets
 Version: 1.0.2
 (c) 2022 Wappler.io
 @build 2022-03-29 15:16:24
 */
dmx.__sockets={},dmx.Socket=function(t,e,n,o){t=t||"/",e=dmx.extend(!0,{transports:["websocket"]},e);var s=dmx.__sockets[t];if(!s){var c="",i=document.querySelector('[src$="socket.io/socket.io.js"]');if(i)c=i.getAttribute("src").replace(/\/?socket\.io\/socket\.io\.js$/,"");s=io(c+t,e),"websocket"==e.transports[0]&&s.on("reconnect_attempt",(function(){s.io.opts.transports=["polling","websocket"]})),dmx.__sockets[t]=s}return n&&Object.keys(n).forEach((function(t){s.on(t,(function(e,s){dmx.Flow.run(n[t],new dmx.DataScope({$param:e},o)).then((function(t){"function"==typeof s&&s(t)}))}))})),s},dmx.Actions({"sockets.emit":function(t){t=this.parse(t),dmx.Socket(t.namespace||"/").emit(t.eventName,t.params)},"sockets.request":function(t){return t=this.parse(t),new Promise((function(e){dmx.Socket(t.namespace||"/").emit(t.eventName,t.params,e)}))}}),dmx.Component("socket",{initialData:{id:null,connected:!1,disconnected:!0},attributes:{namespace:{type:String,default:"/"},options:{type:Object,default:{}}},methods:{emit:function(t,e){this.socket.emit(t,e)},connect:function(){this.socket.connect()},request:function(t,e){var n=this.socket;return new Promise((function(o){n.emit(t,e,o)}))}},events:{connect:Event,disconnect:Event,connect_error:Event,message:Event},message:function(t,e){this.dispatchEvent("message",{},e,t)},trigger:function(t){this.set("id",this.socket.id),this.set("connected",this.socket.connected),this.set("disconnected",this.socket.disconnected),this.dispatchEvent(t)},render:function(t){if(t.textContent)try{this.cfg=(window.Hjson?Hjson:JSON).parse(t.textContent)}catch(e){console.error(e),dmx.debug&&console.debug(t.textContent)}this.onConnect=this.trigger.bind(this,"connect"),this.onDisconnect=this.trigger.bind(this,"disconnect"),this.onConnectError=this.trigger.bind(this,"connect_error"),this.onMessage=this.message.bind(this),this.socket=dmx.Socket(this.props.namespace,this.props.options,this.cfg,this),this.socket.on("connect",this.onConnect),this.socket.on("disconnect",this.onDisconnect),this.socket.on("connect_error",this.onConnectError),this.socket.onAny(this.onMessage)},destroyed:function(){this.socket.off("connect",this.onConnect),this.socket.off("disconnect",this.onDisconnect),this.socket.off("connect_error",this.onConnectError),this.socket.offAny(this.onMessage)}});
//# sourceMappingURL=../maps/dmxSockets.js.map
