| 1 |
- System.register([],(function(n,o){"use strict";return{execute:function(){n("u",(function(){var n={host:o,ws:void 0,reconnection:!0,reconnectiontime:10,subscription:[],open:function(o){return(null==o?void 0:o.host)&&(n.host=o.host),(null==o?void 0:o.reconnection)&&(n.reconnection=o.reconnection),(null==o?void 0:o.reconnectiontime)&&(n.reconnectiontime=o.reconnectiontime),(null==o?void 0:o.subscription)&&(n.subscription=o.subscription),new Promise((function(o,e){!n.ws&&(n.ws=new WebSocket(n.host)),n.ws&&(n.ws.onopen=function(){var e,s,i;(null===(e=n.ws)||void 0===e?void 0:e.readyState)==WebSocket.OPEN&&(n.ws.onmessage=function(o){n.onmessage&&n.onmessage(o)}),(null===(s=n.ws)||void 0===s?void 0:s.readyState)==WebSocket.OPEN&&(n.ws.onclose=function(o){console.log("ws连接关闭",o),n.ws=void 0,n.reconnection&&setTimeout(n.open,1e3*n.reconnectiontime)}),(null===(i=n.subscription)||void 0===i?void 0:i.length)&&n.send({messageType:"SUBSCRIBE",topics:n.subscription}),o(n)}),n.ws&&(n.ws.onerror=function(){n.ws=void 0,n.reconnection&&setTimeout(n.open,1e3*n.reconnectiontime),e(n)})}))},send:function(o){var e;!o.messageId&&(o.messageId=(new Date).getTime()+"");var s=JSON.stringify(o);null===(e=n.ws)||void 0===e||e.send(s)},close:function(){n.ws&&(n.reconnection=!1,n.ws.close())},onmessage:void 0};return n}));var o="ws://"+window.location.host+"/wss";console.log(o)}}}));
|