From ed1fb5e194a577da20d197b3538f4ed3c98f3b2b Mon Sep 17 00:00:00 2001 From: noear Date: Tue, 18 Jun 2024 13:21:45 +0800 Subject: [PATCH] 2.5.6 --- android/android_test/app/build.gradle.kts | 8 ++++---- java/LOG.md | 3 +++ java/socketd-examples/pom.xml | 2 +- java/socketd-parent/pom.xml | 6 +++--- java/socketd-transport-test/pom.xml | 2 +- java/socketd-transport/socketd-transport-aeron/pom.xml | 2 +- java/socketd-transport/socketd-transport-java-kcp/pom.xml | 2 +- java/socketd-transport/socketd-transport-java-tcp/pom.xml | 2 +- .../noear/socketd/transport/java_tcp/TcpBioServer.java | 1 + java/socketd-transport/socketd-transport-java-udp/pom.xml | 2 +- .../socketd-transport-java-websocket/pom.xml | 2 +- java/socketd-transport/socketd-transport-neta/pom.xml | 2 +- java/socketd-transport/socketd-transport-netty/pom.xml | 2 +- .../socketd-transport-smartsocket/pom.xml | 2 +- .../socketd-transport-spring-websocket/pom.xml | 2 +- java/socketd/pom.xml | 2 +- java/socketd/src/main/java/org/noear/socketd/SocketD.java | 2 +- javascript/ LOG.md | 4 ++++ javascript/release/socket.d.esm.js | 4 ++-- javascript/release/socket.d.js | 4 ++-- .../socketd-examples/demo01-js-ws/js/socket.d.esm.js | 4 ++-- javascript/socketd-examples/demo01-js-ws/js/socket.d.js | 4 ++-- javascript/socketd-examples/demo02-node-ws/package.json | 2 +- javascript/socketd-examples/demo03-uniapp-ws/package.json | 2 +- javascript/socketd-examples/demo06-im/index.html | 2 +- javascript/socketd/src/socketd/SocketD.ts | 2 +- javascript/socketd/webpack.config.js | 4 ++-- javascript/socketd/webpack.md | 4 +--- python/LOG.md | 3 +++ python/socketd/setup.py | 2 +- python/socketd/socketd/SocketD.py | 2 +- 31 files changed, 48 insertions(+), 39 deletions(-) diff --git a/android/android_test/app/build.gradle.kts b/android/android_test/app/build.gradle.kts index ba810921..4e9735ad 100644 --- a/android/android_test/app/build.gradle.kts +++ b/android/android_test/app/build.gradle.kts @@ -67,10 +67,10 @@ dependencies { debugImplementation("androidx.compose.ui:ui-tooling") debugImplementation("androidx.compose.ui:ui-test-manifest") -// implementation("org.noear:socketd-transport-smartsocket:2.5.5") - implementation("org.noear:socketd-transport-java-tcp:2.5.5") - implementation("org.noear:socketd-transport-java-udp:2.5.5") - implementation("org.noear:socketd-transport-java-websocket:2.5.5") +// implementation("org.noear:socketd-transport-smartsocket:2.5.6") + implementation("org.noear:socketd-transport-java-tcp:2.5.6") + implementation("org.noear:socketd-transport-java-udp:2.5.6") + implementation("org.noear:socketd-transport-java-websocket:2.5.6") implementation("com.github.tony19:logback-android:3.0.0") } \ No newline at end of file diff --git a/java/LOG.md b/java/LOG.md index e0a6bace..f4174b80 100644 --- a/java/LOG.md +++ b/java/LOG.md @@ -1,3 +1,6 @@ +### 2.5.6 +* smartsocket 升为 1.5.44 + ### 2.5.4 * 添加 新的每秒帧流量控制接口 TrafficLimiter * 添加 Listener:onReply, onSend 方法,方便帧流量统计 diff --git a/java/socketd-examples/pom.xml b/java/socketd-examples/pom.xml index 1fe62a04..69b213d4 100644 --- a/java/socketd-examples/pom.xml +++ b/java/socketd-examples/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../socketd-parent/pom.xml diff --git a/java/socketd-parent/pom.xml b/java/socketd-parent/pom.xml index 70e595c1..8622c6a0 100644 --- a/java/socketd-parent/pom.xml +++ b/java/socketd-parent/pom.xml @@ -6,7 +6,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 pom ${project.artifactId} @@ -18,11 +18,11 @@ UTF-8 1.8 - 2.5.5 + 2.5.6 2.0.12 5.9.1 - 1.5.43 + 1.5.44 1.5.3 4.1.107.Final 1.37.0 diff --git a/java/socketd-transport-test/pom.xml b/java/socketd-transport-test/pom.xml index 3286010d..f049e887 100644 --- a/java/socketd-transport-test/pom.xml +++ b/java/socketd-transport-test/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-aeron/pom.xml b/java/socketd-transport/socketd-transport-aeron/pom.xml index c906dae8..174bba55 100644 --- a/java/socketd-transport/socketd-transport-aeron/pom.xml +++ b/java/socketd-transport/socketd-transport-aeron/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-java-kcp/pom.xml b/java/socketd-transport/socketd-transport-java-kcp/pom.xml index 1728e839..1bbfa288 100644 --- a/java/socketd-transport/socketd-transport-java-kcp/pom.xml +++ b/java/socketd-transport/socketd-transport-java-kcp/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-java-tcp/pom.xml b/java/socketd-transport/socketd-transport-java-tcp/pom.xml index 36565326..0a9cd0bd 100644 --- a/java/socketd-transport/socketd-transport-java-tcp/pom.xml +++ b/java/socketd-transport/socketd-transport-java-tcp/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-java-tcp/src/main/java/org/noear/socketd/transport/java_tcp/TcpBioServer.java b/java/socketd-transport/socketd-transport-java-tcp/src/main/java/org/noear/socketd/transport/java_tcp/TcpBioServer.java index bf3b9589..42000616 100644 --- a/java/socketd-transport/socketd-transport-java-tcp/src/main/java/org/noear/socketd/transport/java_tcp/TcpBioServer.java +++ b/java/socketd-transport/socketd-transport-java-tcp/src/main/java/org/noear/socketd/transport/java_tcp/TcpBioServer.java @@ -70,6 +70,7 @@ public Server start() throws IOException { serverExecutor = Executors.newFixedThreadPool(getConfig().getWorkThreads()); server = createServer(); + server.setReuseAddress(true); serverExecutor.submit(this::accept); diff --git a/java/socketd-transport/socketd-transport-java-udp/pom.xml b/java/socketd-transport/socketd-transport-java-udp/pom.xml index 4d082ef6..83c6ce7f 100644 --- a/java/socketd-transport/socketd-transport-java-udp/pom.xml +++ b/java/socketd-transport/socketd-transport-java-udp/pom.xml @@ -6,7 +6,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-java-websocket/pom.xml b/java/socketd-transport/socketd-transport-java-websocket/pom.xml index 8cf8a2d2..8c5f9c04 100644 --- a/java/socketd-transport/socketd-transport-java-websocket/pom.xml +++ b/java/socketd-transport/socketd-transport-java-websocket/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-neta/pom.xml b/java/socketd-transport/socketd-transport-neta/pom.xml index abafc063..1565c794 100644 --- a/java/socketd-transport/socketd-transport-neta/pom.xml +++ b/java/socketd-transport/socketd-transport-neta/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-netty/pom.xml b/java/socketd-transport/socketd-transport-netty/pom.xml index 2ba9fedc..fd74c9ce 100644 --- a/java/socketd-transport/socketd-transport-netty/pom.xml +++ b/java/socketd-transport/socketd-transport-netty/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-smartsocket/pom.xml b/java/socketd-transport/socketd-transport-smartsocket/pom.xml index fa6c0ee8..05f71416 100644 --- a/java/socketd-transport/socketd-transport-smartsocket/pom.xml +++ b/java/socketd-transport/socketd-transport-smartsocket/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-spring-websocket/pom.xml b/java/socketd-transport/socketd-transport-spring-websocket/pom.xml index 83cb45db..58139ded 100644 --- a/java/socketd-transport/socketd-transport-spring-websocket/pom.xml +++ b/java/socketd-transport/socketd-transport-spring-websocket/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../../socketd-parent/pom.xml diff --git a/java/socketd/pom.xml b/java/socketd/pom.xml index f5a1346a..29150ea4 100644 --- a/java/socketd/pom.xml +++ b/java/socketd/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.5.5 + 2.5.6 ../socketd-parent/pom.xml diff --git a/java/socketd/src/main/java/org/noear/socketd/SocketD.java b/java/socketd/src/main/java/org/noear/socketd/SocketD.java index 1339f5c0..0e1343d3 100644 --- a/java/socketd/src/main/java/org/noear/socketd/SocketD.java +++ b/java/socketd/src/main/java/org/noear/socketd/SocketD.java @@ -24,7 +24,7 @@ public class SocketD { * 框架版本号 */ public static String version() { - return "2.5.5"; + return "2.5.6"; } /** diff --git a/javascript/ LOG.md b/javascript/ LOG.md index 99a7178f..53ca9f4f 100644 --- a/javascript/ LOG.md +++ b/javascript/ LOG.md @@ -1,3 +1,7 @@ +### 2.5.6 +* 强化 EntityDefault::dataSet 方法,支持 Buffer 传入 +* 强化 Session::sendAlarm 支持 Entity 传入 + ### 2.5.5 * 修复 wechat 的环境识别问题 diff --git a/javascript/release/socket.d.esm.js b/javascript/release/socket.d.esm.js index 10e91d6c..039e112f 100644 --- a/javascript/release/socket.d.esm.js +++ b/javascript/release/socket.d.esm.js @@ -1,6 +1,6 @@ /*! - * Socket.D v2.5.5 + * Socket.D v2.5.6 * (c) 2023-2024 noear.org * Released under the Apache-2.0 License. */ -var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.5"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635);class d extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){this._channel.sendAlarm(e,t)}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=d},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):this._data=new n.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new h.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new h.StringEntity(t)),new a.Frame(i.Flags.Alarm,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=s.SocketD,r=s.__esModule;export{n as SocketD}; \ No newline at end of file +var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.6"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635),d=s(4741);class _ extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){"string"!=typeof t?this._channel.sendAlarm(e,t):this._channel.sendAlarm(e,new d.StringEntity(t))}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=_},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof n.BlobBuffer||e instanceof n.ByteBuffer?this._data=e:e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):"undefined"!=typeof Blob&&e instanceof Blob?this._data=new n.BlobBuffer(e):console.warn("This data type is not supported, type="+typeof e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Alarm,s.build())}static pressureFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Pressure,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=s.SocketD,r=s.__esModule;export{n as SocketD}; \ No newline at end of file diff --git a/javascript/release/socket.d.js b/javascript/release/socket.d.js index 872af71f..53130c69 100644 --- a/javascript/release/socket.d.js +++ b/javascript/release/socket.d.js @@ -1,6 +1,6 @@ /*! - * Socket.D v2.5.5 + * Socket.D v2.5.6 * (c) 2023-2024 noear.org * Released under the Apache-2.0 License. */ -var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.5"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635);class d extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){this._channel.sendAlarm(e,t)}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=d},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):this._data=new n.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new h.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new h.StringEntity(t)),new a.Frame(i.Flags.Alarm,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=window;for(var r in s)n[r]=s[r];s.__esModule&&Object.defineProperty(n,"__esModule",{value:!0}); \ No newline at end of file +var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.6"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635),d=s(4741);class _ extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){"string"!=typeof t?this._channel.sendAlarm(e,t):this._channel.sendAlarm(e,new d.StringEntity(t))}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=_},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof n.BlobBuffer||e instanceof n.ByteBuffer?this._data=e:e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):"undefined"!=typeof Blob&&e instanceof Blob?this._data=new n.BlobBuffer(e):console.warn("This data type is not supported, type="+typeof e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Alarm,s.build())}static pressureFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Pressure,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=window;for(var r in s)n[r]=s[r];s.__esModule&&Object.defineProperty(n,"__esModule",{value:!0}); \ No newline at end of file diff --git a/javascript/socketd-examples/demo01-js-ws/js/socket.d.esm.js b/javascript/socketd-examples/demo01-js-ws/js/socket.d.esm.js index 10e91d6c..039e112f 100644 --- a/javascript/socketd-examples/demo01-js-ws/js/socket.d.esm.js +++ b/javascript/socketd-examples/demo01-js-ws/js/socket.d.esm.js @@ -1,6 +1,6 @@ /*! - * Socket.D v2.5.5 + * Socket.D v2.5.6 * (c) 2023-2024 noear.org * Released under the Apache-2.0 License. */ -var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.5"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635);class d extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){this._channel.sendAlarm(e,t)}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=d},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):this._data=new n.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new h.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new h.StringEntity(t)),new a.Frame(i.Flags.Alarm,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=s.SocketD,r=s.__esModule;export{n as SocketD}; \ No newline at end of file +var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.6"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635),d=s(4741);class _ extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){"string"!=typeof t?this._channel.sendAlarm(e,t):this._channel.sendAlarm(e,new d.StringEntity(t))}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=_},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof n.BlobBuffer||e instanceof n.ByteBuffer?this._data=e:e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):"undefined"!=typeof Blob&&e instanceof Blob?this._data=new n.BlobBuffer(e):console.warn("This data type is not supported, type="+typeof e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Alarm,s.build())}static pressureFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Pressure,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=s.SocketD,r=s.__esModule;export{n as SocketD}; \ No newline at end of file diff --git a/javascript/socketd-examples/demo01-js-ws/js/socket.d.js b/javascript/socketd-examples/demo01-js-ws/js/socket.d.js index 872af71f..53130c69 100644 --- a/javascript/socketd-examples/demo01-js-ws/js/socket.d.js +++ b/javascript/socketd-examples/demo01-js-ws/js/socket.d.js @@ -1,6 +1,6 @@ /*! - * Socket.D v2.5.5 + * Socket.D v2.5.6 * (c) 2023-2024 noear.org * Released under the Apache-2.0 License. */ -var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.5"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635);class d extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){this._channel.sendAlarm(e,t)}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=d},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):this._data=new n.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new h.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new h.StringEntity(t)),new a.Frame(i.Flags.Alarm,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=window;for(var r in s)n[r]=s[r];s.__esModule&&Object.defineProperty(n,"__esModule",{value:!0}); \ No newline at end of file +var e={7704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const n=s(2911),r=s(7545),i=s(1243),o=s(8491),a=s(6439),l=s(8259),h=s(5008),c=s(6846),u=s(826),d=s(1196),_=s(7054),g=s(4630),S=s(8991),f=s(5902),p=s(4741);class m{static registerClientProvider(e){for(let t of e.schemas())m.clientProviderMap.set(t,e)}static registerServerProvider(e){for(let t of e.schemas())m.serverProviderMap.set(t,e)}static version(){return"2.5.6"}static protocolName(){return"Socket.D"}static protocolVersion(){return"1.0"}static createServer(e){let t=this.createServerOrNull(e);if(null==t)throw new Error("No socketd server providers were found: "+e);return t}static createServerOrNull(e){n.Asserts.assertNull("schema",e);let t=m.serverProviderMap.get(e);return null==t?null:t.createServer(new l.ServerConfig(e))}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found: "+e);return t}static createClientOrNull(e){n.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),i=this.clientProviderMap.get(s);if(null==i)return null;{const t=new r.ClientConfig(e);return i.createClient(t)}}static createClusterClient(e){return new i.ClusterClient(e)}static newEntity(e){return e?"undefined"!=typeof File&&e instanceof File?new f.FileEntity(e):"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob?(new S.EntityDefault).dataSet(e):new p.StringEntity(String(e)):new S.EntityDefault}static newSimpleListener(){return new g.SimpleListener}static newEventListener(e){return new u.EventListener(e)}static newPathListener(e){return new d.PathListener(e)}static newPipelineListener(){return new _.PipelineListener}static newBrokerListener(){return new h.BrokerListener}static newBrokerFragmentHandler(){return new c.BrokerFragmentHandler}}t.SocketD=m,m.EntityMetas=a.EntityMetas,m.clientProviderMap=new Map,m.serverProviderMap=new Map,(()=>{const e=new o.WsProvider;m.registerClientProvider(e),m.registerServerProvider(e)})()},6846:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerFragmentHandler=void 0;const n=s(7400);class r extends n.FragmentHandlerDefault{aggrEnable(){return!1}}t.BrokerFragmentHandler=r},5008:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListener=void 0;const n=s(9857),r=s(6862),i=s(8422),o=s(6306),a=s(4970),l=s(9079);class h extends n.BrokerListenerBase{onOpen(e){let t=e.name();this.addPlayer(t,e)}onClose(e){let t=e.name();this.removePlayer(t,e)}onMessage(e,t){this.onMessageDo(e,t)}onReply(e,t){}onSend(e,t){}onMessageDo(e,t){let s=t.atName();if(s)if("*"==s){let s=this.getNameAll();if(null!=s&&s.size>0)for(let n of s)this.forwardToName(e,t,n)}else if(s.endsWith("*")){if(s=s.substring(0,s.length()-1),0==this.forwardToName(e,t,s)){if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' player");e.sendAlarm(t,"Broker don't have '@"+s+"' player")}}else{let n=this.getPlayerAny(s,e,t);if(null!=n)this.forwardToSession(e,t,n);else{if(null==e)throw new a.SocketDException("Broker don't have '@"+s+"' session");e.sendAlarm(t,"Broker don't have '@"+s+"' session")}}else{if(null==e)throw new a.SocketDException("Broker message require '@' meta");e.sendAlarm(t,"Broker message require '@' meta")}}broadcast(e,t){this.onMessageDo(null,(new r.MessageBuilder).flag(o.Flags.Message).event(e).entity(t).build())}forwardToName(e,t,s){let n=this.getPlayerAll(s);if(null!=n&&n.size>0){for(let s of n)s!=e&&(s.isValid()?this.forwardToSession(e,t,s):this.onClose(s));return!0}return!1}forwardToSession(e,t,s){t.isRequest()?s.sendAndRequest(t.event(),t,-1).thenReply((s=>{l.SessionUtils.isValid(e)&&e.reply(t,s)})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):t.isSubscribe()?s.sendAndSubscribe(t.event(),t).thenReply((s=>{l.SessionUtils.isValid(e)&&(s.isEnd()?e.replyEnd(t,s):e.reply(t,s))})).thenError((s=>{l.SessionUtils.isValid(e)&&i.RunUtils.runAndTry((()=>e.sendAlarm(t,s.message)))})):s.send(t.event(),t)}onError(e,t){console.warn("Broker error",t)}}t.BrokerListener=h},9857:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BrokerListenerBase=void 0;const n=s(7644),r=s(6439);t.BrokerListenerBase=class{constructor(){this._sessionAll=new Map,this._playerSessions=new Map}getSessionAll(){return this._sessionAll.values()}getSessionAny(){return n.LoadBalancer.getAnyByPoll(new Set(this._sessionAll.values()))}getSessionCount(){return this._sessionAll.size}getNameAll(){return new Set(this._playerSessions.keys())}getPlayerCount(e){let t=this.getPlayerAll(e);return null==t?0:t.size}getPlayerAll(e){if(e){return this._playerSessions.get(e)||null}return null}getPlayerAny(e,t,s){if(!e)return null;if(e.endsWith("!")){e=e.substring(0,e.length-1);let i=null;return null!=s&&(i=s.meta(r.EntityMetas.META_X_HASH)),i?n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),i):null==t?n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e)):n.LoadBalancer.getAnyByHash(this.getPlayerAll(e),t.remoteAddress().address)}return n.LoadBalancer.getAnyByPoll(this.getPlayerAll(e))}addPlayer(e,t){if(e){let s=this._playerSessions.get(e);s||(s=new Set,this._playerSessions.set(e,s)),s.add(t)}this._sessionAll.set(t.sessionId(),t)}removePlayer(e,t){if(e){let s=this.getPlayerAll(e);null!=s&&s.delete(t)}this._sessionAll.delete(t.sessionId())}}},1243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(9270),i=s(7704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}connectHandler(e){return this._connectHandler=e,this}heartbeatHandler(e){return this._heartbeatHandler=e,this}config(e){return this._configHandler=e,this}listen(e){return this._listener=e,this}open(){return n(this,void 0,void 0,(function*(){return this.openDo(!1)}))}openOrThow(){return n(this,void 0,void 0,(function*(){return this.openDo(!0)}))}openDo(e){return n(this,void 0,void 0,(function*(){const t=new Array;for(const s of this._serverUrls)for(let n of s.split(",")){if(n=n.trim(),!n)continue;const s=i.SocketD.createClient(n);this._listener&&s.listen(this._listener),this._configHandler&&s.config(this._configHandler),this._connectHandler&&s.connectHandler(this._connectHandler),this._heartbeatHandler&&s.heartbeatHandler(this._heartbeatHandler),e?t.push(yield s.openOrThow()):t.push(yield s.open())}return new r.ClusterClientSession(t)}))}}},9270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(8404),r=s(4970),i=s(8422),o=s(7644);t.ClusterClientSession=class{constructor(e){this._sessionSet=new Set(e),this._sessionId=n.StrUtils.guid()}getSessionAll(){return this._sessionSet}getSessionAny(e){let t=null;if(t=e?o.LoadBalancer.getAnyByHash(this._sessionSet,e):o.LoadBalancer.getAnyByPoll(this._sessionSet),null==t)throw new r.SocketDException("No session is available!");return t}getSessionOne(){return this.getSessionAny(null)}isValid(){for(const e of this._sessionSet)if(e.isValid())return!0;return!1}isActive(){for(const e of this._sessionSet)if(e.isActive())return!0;return!1}isClosing(){for(const e of this._sessionSet)if(e.isClosing())return!0;return!1}sessionId(){return this._sessionId}reconnect(){for(const e of this._sessionSet)0==e.isValid()&&e.reconnect()}send(e,t){return this.getSessionAny(null).send(e,t)}sendAndRequest(e,t,s){return this.getSessionAny(null).sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionAny(null).sendAndSubscribe(e,t,s)}closeStarting(){this.preclose()}preclose(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.preclose.bind(e))}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close.bind(e))}}},7644:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.LoadBalancer=void 0;const n=s(9079);class r{static roundCounterGet(){let e=r.roundCounter++;return e>999999&&r.roundCounter,e}static hashcode(e){var t,s,n=0;if(0===e.length)return n;for(t=0,s=e.length;tr.roundCounterGet()))}static getAnyByHash(e,t){return r.getAny(e,(()=>r.hashcode(t)))}static getAny(e,t){if(null==e||0==e.size)return null;{let s=new Array;for(let t of e)n.SessionUtils.isActive(t)&&s.push(t);return 0==s.length?null:1==s.length?s[0]:s[Math.abs(t())%s.length]}}static getFirst(e){if(null==e||0==e.length)return null;for(let t of e)if(n.SessionUtils.isActive(t))return t;return null}}t.LoadBalancer=r,r.roundCounter=0},4970:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketDTimeoutException=t.SocketDSizeLimitException=t.SocketDConnectionException=t.SocketDCodecException=t.SocketDChannelException=t.SocketDAlarmException=t.SocketDException=void 0;class s extends Error{constructor(e){super(e)}}t.SocketDException=s,t.SocketDAlarmException=class extends s{constructor(e){super(e.entity().dataAsString()),this._alarm=e,this._alarmCode=e.metaAsInt("code")}getAlarm(){return this._alarm}getAlarmCode(){return this._alarmCode}},t.SocketDChannelException=class extends s{constructor(e){super(e)}},t.SocketDCodecException=class extends s{constructor(e){super(e)}},t.SocketDConnectionException=class extends s{constructor(e){super(e)}},t.SocketDSizeLimitException=class extends s{constructor(e){super(e)}},t.SocketDTimeoutException=class extends s{constructor(e){super(e)}}},6704:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const n=s(7648),r=s(9213),i=s(4797);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new n.ProcessorDefault}getAssistant(){return this._assistant}getConnectHandler(){return this._connectHandler}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}connectHandler(e){return null!=e&&(this._connectHandler=e),this}heartbeatHandler(e){return null!=e&&(this._heartbeatHandler=e),this}config(e){return null!=e&&e(this._config),this}listen(e){return null!=e&&this._processor.setListener(e),this}open(){return this.openDo(!1)}openOrThow(){return this.openDo(!0)}openDo(e){const t=this.createConnector(),s=new r.ClientChannel(this,t);return new Promise(((t,n)=>{s.connect().then((e=>{console.info("Socket.D client successfully connected!"),t(s.getSession())}),(r=>{e?(s.close(i.Constants.CLOSE2008_OPEN_FAIL),n(r)):(console.warn("Socket.D client Connection failed!"),t(s.getSession()))}))}))}}},9213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function o(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(o,a)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(4797),i=s(2911),o=s(4970),a=s(8422),l=s(6039),h=s(2402),c=s(5922),u=s(8872);class d extends u.ChannelBase{constructor(e,t){super(t.getConfig()),this._isConnecting=!1,this._client=e,this._connector=t,this._sessionShell=new l.SessionDefault(this),this._connectHandler=new c.ClientConnectHandlerDefault(e.getConnectHandler()),this._heartbeatHandler=new h.ClientHeartbeatHandlerDefault(e.getHeartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>n(this,void 0,void 0,(function*(){try{yield this.heartbeatHandle()}catch(e){console.debug("Client channel heartbeat failed: {link="+this._connector.getConfig().getLinkUrl()+"}")}}))),this._client.getHeartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(this._real){if(null==this._real.getHandshake())return;if(i.Asserts.isClosedAndEnd(this._real))return console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`),void this.close(this._real.closeCode());if(this._real.isClosing())return}try{yield this.internalCheck(),this._heartbeatHandler.clientHeartbeat(this.getSession())}catch(e){if(e instanceof o.SocketDException)throw e;throw this._connector.autoReconnect()&&this.internalCloseIfError(),e}}))}isValid(){return null!=this._real&&this._real.isValid()}isClosing(){return null!=this._real&&this._real.isClosing()}closeCode(){return null==this._real?0:this._real.closeCode()}getLiveTime(){return this._real?this._real.getLiveTime():0}getRemoteAddress(){return this._real?this._real.getRemoteAddress():null}getLocalAddress(){return this._real?this._real.getLocalAddress():null}send(e,t){i.Asserts.assertClosedAndEnd(this._real),this.internalCheck().then((s=>{if(this._real)try{this._real.send(e,t)}catch(e){t&&t.onError(e)}else{const e=new o.SocketDChannelException("Client channel is not connected");t&&t.onError(e)}}),(e=>{this._connector.autoReconnect()&&this.internalCloseIfError(),t&&t.onError(e)}))}reconnect(){return n(this,void 0,void 0,(function*(){this.initHeartbeat(),yield this.internalCheck()}))}onError(e){this._real.onError(e)}close(e){a.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),a.RunUtils.runAndTry((()=>this._connector.close())),this._real&&a.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._sessionShell}connect(){return n(this,void 0,void 0,(function*(){if(!this._isConnecting){this._isConnecting=!0;try{null!=this._real&&this._real.close(r.Constants.CLOSE2002_RECONNECT),this._real=yield this._connectHandler.clientConnect(this._connector),this._real.setSession(this._sessionShell),this.setHandshake(this._real.getHandshake())}finally{this._isConnecting=!1}}}))}internalCloseIfError(){null!=this._real&&(this._real.close(r.Constants.CLOSE2001_ERROR),this._real=null)}internalCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(yield this.connect(),!0)}))}}t.ClientChannel=d},7545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(2331),r=s(8404);class i extends n.ConfigBase{constructor(e){super(!0),this._metaMap=new Map;const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);this._schema=e.substring(0,t),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let s=r.StrUtils.parseUri(e);this._host=s.host,this._port=parseInt(s.port),this._schemaCleaned=s.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getLinkUrl(){return this._linkUrl}getUrl(){return this._url}getHost(){return this._host}getPort(){return this._port}getMetaMap(){return this._metaMap}metaPut(e,t){return this._metaMap.set(e,t),this}getHeartbeatInterval(){return this._heartbeatInterval}heartbeatInterval(e){return this._heartbeatInterval=e,this}getConnectTimeout(){return this._connectTimeout}connectTimeout(e){return this._connectTimeout=e,this}isAutoReconnect(){return this._autoReconnect}autoReconnect(e){return this._autoReconnect=e,this}idleTimeout(e){return 0==this._autoReconnect?(this._idleTimeout=e,this):(this._idleTimeout=0,this)}toString(){return"ClientConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", url='"+this._url+"', ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", heartbeatInterval="+this._heartbeatInterval+", connectTimeout="+this._connectTimeout+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", autoReconnect="+this._autoReconnect+", maxUdpSize="+this._maxUdpSize+"}"}}t.ClientConfig=i},5922:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectHandlerDefault=void 0,t.ClientConnectHandlerDefault=class{constructor(e){this._connectHandler=e}clientConnect(e){return this._connectHandler?this._connectHandler(e):e.connect()}}},8511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}getConfig(){return this._client.getConfig()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},9777:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHandshakeResult=void 0,t.ClientHandshakeResult=class{constructor(e,t){this._channel=e,this._throwable=t}getChannel(){return this._channel}getThrowable(){return this._throwable}}},2402:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientHeartbeatHandlerDefault=void 0,t.ClientHeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}clientHeartbeat(e){this._heartbeatHandler?this._heartbeatHandler(e):e.sendPing()}}},2911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(4797),r=s(4970);class i{static assertClosed(e){if(null!=e&&e.closeCode()>0)throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static isClosedAndEnd(e){return e.closeCode()==n.Constants.CLOSE2009_USER||e.closeCode()==n.Constants.CLOSE2008_OPEN_FAIL}static assertClosedAndEnd(e){if(null!=e&&i.isClosedAndEnd(e))throw new r.SocketDChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertNull(e,t){if(null==t)throw new Error("The argument cannot be null: "+e)}static assertEmpty(e,t){if(!t)throw new Error("The argument cannot be empty: "+e)}static assertSize(e,t,s){if(t>s){const n=`This message ${e} size is out of limit ${s} (${t})`;throw new r.SocketDSizeLimitException(n)}}}t.Asserts=i},6560:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BlobBuffer=t.ByteBuffer=void 0,t.ByteBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this.size()-this.position()}position(){return this._bufIdx}size(){return this._buf.byteLength}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n);return this._bufIdx=n,new Promise((e=>{e(1)})).then((()=>{t(r)})),!0}getBlob(){return null}getArray(){return this._buf}},t.BlobBuffer=class{constructor(e){this._bufIdx=0,this._buf=e}remaining(){return this._buf.size-this._bufIdx}position(){return this._bufIdx}size(){return this._buf.size}reset(){this._bufIdx=0}getBytes(e,t){let s=this.remaining();if(s>e&&(s=e),s<=0)return!1;let n=this._bufIdx+s,r=this._buf.slice(this._bufIdx,n),i=new FileReader;return i.onload=e=>{e.target&&t(e.target.result)},i.readAsArrayBuffer(r),this._bufIdx=n,!0}getBlob(){return this._buf}getArray(){return null}}},2608:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ArrayBufferCodecWriter=t.ArrayBufferCodecReader=void 0,t.ArrayBufferCodecReader=class{constructor(e){this._buf=e,this._bufView=new DataView(e),this._bufViewIdx=0}getByte(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt8(this._bufViewIdx);return this._bufViewIdx+=1,e}getBytes(e,t,s){const n=new DataView(e),r=t+s;for(let e=t;e=this._buf.byteLength);e++)n.setInt8(e,this._bufView.getInt8(this._bufViewIdx)),this._bufViewIdx++}getInt(){if(this._bufViewIdx>=this._buf.byteLength)return-1;const e=this._bufView.getInt32(this._bufViewIdx);return this._bufViewIdx+=4,e}peekByte(){return this.remaining()>0?this._bufView.getInt8(this._bufViewIdx):-1}skipBytes(e){this._bufViewIdx=this.position()+e}remaining(){return this._buf.byteLength-this._bufViewIdx}position(){return this._bufViewIdx}size(){return this._buf.byteLength}reset(){this._bufViewIdx=0}},t.ArrayBufferCodecWriter=class{constructor(e){this._buf=new ArrayBuffer(e),this._bufView=new DataView(this._buf),this._bufViewIdx=0}putBytes(e){const t=new DataView(e),s=t.byteLength;for(let e=0;e{Object.defineProperty(t,"__esModule",{value:!0}),t.Constants=void 0;const n=s(6560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1000_PROTOCOL_CLOSE_STARTING:1e3,CLOSE1001_PROTOCOL_CLOSE:1001,CLOSE1002_PROTOCOL_ILLEGAL:1002,CLOSE2001_ERROR:2001,CLOSE2002_RECONNECT:2002,CLOSE2003_DISCONNECTION:2003,CLOSE2008_OPEN_FAIL:2008,CLOSE2009_USER:2009,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MAX_SIZE_FRAME:17825792,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2}},6439:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=void 0,t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",META_X_IP:"X-IP",META_X_HASH:"X-Hash",META_X_UNLIMITED:"X-Unlimited",META_DATA_LENGTH:"Data-Length",META_DATA_TYPE:"Data-Type",META_DATA_FRAGMENT_IDX:"Data-Fragment-Idx",META_DATA_FRAGMENT_TOTAL:"Data-Fragment-Total",META_DATA_DISPOSITION_FILENAME:"Data-Disposition-Filename",META_RANGE_START:"Data-Range-Start",META_RANGE_SIZE:"Data-Range-Size"}},6306:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flags=void 0,t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,Pressure:32,Message:40,Request:41,Subscribe:42,Reply:48,ReplyEnd:49,of:function(e){switch(e){case 10:return this.Connect;case 11:return this.Connack;case 20:return this.Ping;case 21:return this.Pong;case 30:return this.Close;case 31:return this.Alarm;case 32:return this.Pressure;case 40:return this.Message;case 41:return this.Request;case 42:return this.Subscribe;case 48:return this.Reply;case 49:return this.ReplyEnd;default:return this.Unknown}},name:function(e){switch(e){case this.Connect:return"Connect";case this.Connack:return"Connack";case this.Ping:return"Ping";case this.Pong:return"Pong";case this.Close:return"Close";case this.Alarm:return"Alarm";case this.Pressure:return"Pressure";case this.Message:return"Message";case this.Request:return"Request";case this.Subscribe:return"Subscribe";case this.Reply:return"Reply";case this.ReplyEnd:return"ReplyEnd";default:return"Unknown"}}}},3954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frame=void 0;const n=s(6306);t.Frame=class{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+n.Flags.name(this._flag)+", message="+this._message+"}"}}},7953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(6439),r=s(8404);t.HandshakeDefault=class{constructor(e){let t=e.dataAsString();null!=t&&""!=t||(t=e.event()),this._source=e,this._url=t,this._version=e.meta(n.EntityMetas.META_SOCKETD_VERSION),this._outMetaMap=new Map,this._paramMap=new Map;let s=r.StrUtils.parseUri(t);s.path?this._path=s.path:this._path="/";const i=s.query;if(i)for(const e of i.split("&")){const t=e.indexOf("=");t>0&&this._paramMap.set(e.substring(0,t),e.substring(t+1))}e.metaMap().forEach(((e,t,s)=>{this._paramMap.set(t,e)}))}getSource(){return this._source}getOutMetaMap(){return this._outMetaMap}uri(){return this._url}path(){return this._path}version(){return this._version}param(e){return this._paramMap.get(e)||null}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}outMeta(e,t){this._outMetaMap.set(e,t)}}},6862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(4797),r=s(6439),i=s(6306);t.MessageBuilder=class{constructor(){this._flag=i.Flags.Unknown,this._sid=n.Constants.DEF_SID,this._event=n.Constants.DEF_EVENT,this._entity=null}flag(e){return this._flag=e,this}sid(e){return this._sid=e,this}event(e){return this._event=e,this}entity(e){return this._entity=e,this}build(){return new o(this._flag,this._sid,this._event,this._entity)}};class o{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}atName(){return this.meta("@")}rangeStart(){return this.metaAsInt(r.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(r.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==i.Flags.Request}isSubscribe(){return this._flag==i.Flags.Subscribe}isEnd(){return this._flag==i.Flags.ReplyEnd}sid(){return this._sid}event(){return this._event}entity(){return this._entity}toString(){return"Message{sid='"+this._sid+"', event='"+this._event+"', entity="+this._entity+"}"}metaString(){return this._entity.metaString()}metaMap(){return this._entity.metaMap()}meta(e){return this._entity.meta(e)}metaOrDefault(e,t){return this._entity.metaOrDefault(e,t)}metaAsInt(e){return this._entity.metaAsInt(e)}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return this._entity.metaAsFloat(e)}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}delMeta(e){this._entity.delMeta(e)}data(){return this._entity.data()}dataAsReader(){return this._entity.dataAsReader()}dataAsString(){return this._entity.dataAsString()}dataSize(){return this._entity.dataSize()}release(){this._entity&&this._entity.release()}}t.MessageDefault=o},6789:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RouteSelectorDefault=void 0,t.RouteSelectorDefault=class{constructor(){this._inner=new Map}select(e){return this._inner.get(e)}put(e,t){this._inner.set(e,t)}remove(e){this._inner.delete(e)}size(){return this._inner.size}}},1305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._attrMap=null,this._sessionId=this.generateId()}sessionId(){return this._sessionId}liveTime(){return this._channel.getLiveTime()}name(){return this.param("@")||null}attrMap(){return null==this._attrMap&&(this._attrMap=new Map),this._attrMap}attrHas(e){return null!=this._attrMap&&this._attrMap.has(e)}attr(e){return null==this._attrMap?null:this._attrMap.get(e)}attrOrDefault(e,t){return this.attr(e)||t}attrPut(e,t){this.attrMap().set(e,t)}isActive(){return this.isValid()&&0==this.isClosing()}generateId(){return this._channel.getConfig().genId()}}},6039:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(1305),r=s(6862),i=s(3954),o=s(4797),a=s(6306),l=s(8991),h=s(537),c=s(5141),u=s(5635),d=s(4741);class _ extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}isClosing(){return this._channel.isClosing()}remoteAddress(){return this._channel.getRemoteAddress()}localAddress(){return this._channel.getLocalAddress()}handshake(){return this._channel.getHandshake()}param(e){return this.handshake().param(e)}paramOrDefault(e,t){return this.handshake().paramOrDefault(e,t)}path(){return null==this._pathNew?this.handshake().path():this._pathNew}pathNew(e){this._pathNew=e}reconnect(){this._channel.reconnect()}sendPing(){this._channel.sendPing()}sendAlarm(e,t){"string"!=typeof t?this._channel.sendAlarm(e,t):this._channel.sendAlarm(e,new d.StringEntity(t))}send(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new h.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<0&&(s=this._channel.getConfig().getStreamTimeout()),0==s&&(s=this._channel.getConfig().getRequestTimeout());const o=new c.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),o),o}sendAndSubscribe(e,t,s){null==t&&(t=new l.EntityDefault);const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<=0&&(s=this._channel.getConfig().getStreamTimeout());const o=new u.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),o),o}reply(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.Reply,s),null)}replyEnd(e,t){null==t&&(t=new l.EntityDefault);const s=(new r.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build();this._channel.send(new i.Frame(a.Flags.ReplyEnd,s),null)}closeStarting(){this.preclose()}preclose(){console.debug(`${this._channel.getConfig().getRoleName()} session close starting, sessionId=${this.sessionId()}`),this._channel.isValid()&&this._channel.sendClose(o.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose(o.Constants.CLOSE1001_PROTOCOL_CLOSE)}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(o.Constants.CLOSE2009_USER)}}t.SessionDefault=_},9871:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SocketAddress=void 0,t.SocketAddress=class{constructor(e,t,s){this.address=e,this.family=t,this.port=s}}},7147:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CodecDefault=void 0;const n=s(3954),r=s(8404),i=s(2911),o=s(4797),a=s(6306),l=s(6862),h=s(8991);t.CodecDefault=class{constructor(e){this._config=e}write(e,t){if(e.message()){const s=r.StrUtils.strToBuf(e.message().sid(),this._config.getCharset()),n=r.StrUtils.strToBuf(e.message().event(),this._config.getCharset()),a=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+a.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,o.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,o.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",a.byteLength,o.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),o.Constants.MAX_SIZE_DATA);const h=t(l);return h.putInt(l),h.putInt(e.flag()),h.putBytes(s),h.putChar("\n".charCodeAt(0)),h.putBytes(n),h.putChar("\n".charCodeAt(0)),h.putBytes(a),h.putChar("\n".charCodeAt(0)),h.putBytes(e.message().data().getArray()),h.flush(),h}{const s=8,n=t(s);return n.putInt(s),n.putInt(e.flag()),n.flush(),n}}read(e){const t=e.getInt();if(t>e.remaining()+4)return null;const s=e.getInt();if(8==t)return new n.Frame(a.Flags.of(s),null);{const r=Math.min(o.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),c=this.decodeString(e,i,o.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,o.Constants.MAX_SIZE_EVENT),d=this.decodeString(e,i,o.Constants.MAX_SIZE_META_STRING),_=t-e.position();let g;if(_>o.Constants.MAX_SIZE_DATA){g=new ArrayBuffer(o.Constants.MAX_SIZE_DATA),e.getBytes(g,0,o.Constants.MAX_SIZE_DATA);for(let t=_-o.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else g=new ArrayBuffer(_),_>0&&e.getBytes(g,0,_);const S=(new l.MessageBuilder).flag(a.Flags.of(s)).sid(c).event(u).entity((new h.EntityDefault).dataSet(g).metaStringSet(d)).build();return new n.Frame(S.flag(),S)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(0==t&&10==e.peekByte()){e.skipBytes(1);break}s>0&&s<=i||(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},8991:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityDefault=void 0;const n=s(6560),r=s(2608),i=s(4797),o=s(6439),a=s(4970),l=s(8404);t.EntityDefault=class{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(e){return this.metaPut("@",e),this}range(e,t){return this.metaPut(o.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(o.EntityMetas.META_RANGE_SIZE,t.toString()),this}metaStringSet(e){if(this._metaMap=new Map,e)for(const t of e.split("&")){const e=t.indexOf("=");e>0&&this._metaMap.set(t.substring(0,e),t.substring(e+1))}return this}metaMapPut(e){if(e)if(e instanceof Map)e.forEach(((e,t,s)=>{this.metaMap().set(t,e)}));else for(const t of e.prototype)this.metaMap().set(t,e[t]);return this}metaPut(e,t){return null==t?this.metaMap().delete(e):this.metaMap().set(e,t),this}metaDel(e){this.metaMap().delete(e)}metaString(){let e="";return this.metaMap().forEach(((t,s,n)=>{e+=`${s}=${t}&`})),e.length>0?e.substring(0,e.length-1):e}metaMap(){return null==this._metaMap&&(this._metaMap=new Map),this._metaMap}meta(e){return this.metaMap().get(e)||null}metaOrDefault(e,t){return this.meta(e)||t}metaAsInt(e){return parseInt(this.metaOrDefault(e,"0"))}metaAsLong(e){return this.metaAsInt(e)}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}metaAsDouble(e){return this.metaAsFloat(e)}putMeta(e,t){this.metaPut(e,t)}delMeta(e){this.metaDel(e)}dataSet(e){return e instanceof n.BlobBuffer||e instanceof n.ByteBuffer?this._data=e:e instanceof ArrayBuffer?this._data=new n.ByteBuffer(e):"undefined"!=typeof Blob&&e instanceof Blob?this._data=new n.BlobBuffer(e):console.warn("This data type is not supported, type="+typeof e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsReader");return this._dataAsReader||(this._dataAsReader=new r.ArrayBufferCodecReader(this._data.getArray())),this._dataAsReader}dataAsString(){if(null==this._data.getArray())throw new a.SocketDException("Blob does not support dataAsString");return l.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}},5902:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=void 0;const n=s(6439),r=s(8991);class i extends r.EntityDefault{constructor(e){super(),this.dataSet(e),this.metaPut(n.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}t.FileEntity=i},4741:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StringEntity=void 0;const n=s(8991),r=s(8404);class i extends n.EntityDefault{constructor(e){super();const t=r.StrUtils.strToBuf(e);this.dataSet(t)}}t.StringEntity=i},6422:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(6862),r=s(8725),i=s(6439),o=s(4970),a=s(3954),l=s(8991);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(i.EntityMetas.META_DATA_LENGTH);if(!t)throw new o.SocketDCodecException("Missing '"+i.EntityMetas.META_DATA_LENGTH+"' meta, event="+e.event());this._dataLength=parseInt(t)}getSid(){return this._main.sid()}getDataStreamSize(){return this._dataStreamSize}getDataLength(){return this._dataLength}add(e,t){this._fragmentHolders.push(new r.FragmentHolder(e,t)),this._dataStreamSize=this._dataStreamSize+t.dataSize()}get(){this._fragmentHolders.sort(((e,t)=>e.getIndex()==t.getIndex()?0:e.getIndex()>t.getIndex()?1:-1));const e=new ArrayBuffer(this._dataLength),t=new DataView(e);let s=0;for(const e of this._fragmentHolders){const n=new DataView(e.getMessage().data().getArray());for(let r=0;r{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHandlerDefault=void 0;const n=s(6439),r=s(6422),i=s(8991);t.FragmentHandlerDefault=class{spliFragment(e,t,s,n){if(s.dataSize()>e.getConfig().getFragmentSize()){let r=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(r,i,e,t,s,n)}else null==s.data().getBlob()?(n(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{n((new i.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,r,o,a){e++,o.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new i.EntityDefault).dataSet(l);1==e&&h.metaMapPut(o.metaMap()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(n.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),a(h),null!=r&&r.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,r,o,a)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new r.FragmentAggregatorDefault(s),e.putAttachment(n.getSid(),n)),n.add(t,s),n.getDataLength()>n.getDataStreamSize()?null:(e.putAttachment(s.sid(),null),n.get())}aggrEnable(){return!0}}},8725:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentHolder=void 0,t.FragmentHolder=class{constructor(e,t){this._index=e,this._message=t}getIndex(){return this._index}getMessage(){return this._message}}},6269:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(8404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},8872:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(4797),r=s(9755);t.ChannelBase=class{constructor(e){this._config=e,this._attachments=new Map}getAttachment(e){return this._attachments.get(e)}putAttachment(e,t){null==t?this._attachments.delete(e):this._attachments.set(e,t)}close(e){e>n.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e,t){this.send(r.Frames.connectFrame(this.getConfig().genId(),e,t),null)}sendConnack(){this.send(r.Frames.connackFrame(this.getHandshake()),null)}sendPing(){this.send(r.Frames.pingFrame(),null)}sendPong(){this.send(r.Frames.pongFrame(),null)}sendClose(e){this.send(r.Frames.closeFrame(e),null)}sendAlarm(e,t){this.send(r.Frames.alarmFrame(e,t),null)}}},9747:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(3954),r=s(6862),i=s(4797),o=s(6439),a=s(6039),l=s(8872),h=s(9755);class c extends l.ChannelBase{constructor(e,t){super(t.getConfig()),this._liveTime=0,this._alarmCode=0,this._closeCode=0,this._isCloseNotified=!1,this._source=e,this._processor=t.getProcessor(),this._assistant=t.getAssistant(),this._streamManger=t.getConfig().getStreamManger()}onOpenFuture(e){this._onOpenFuture=e}doOpenFuture(e,t){this._onOpenFuture&&this._onOpenFuture(e,t)}isValid(){return 0==this.closeCode()&&this._assistant.isValid(this._source)}isClosing(){return this._closeCode==i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING}closeCode(){return this._closeCode>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING?this._closeCode:0}config(){return this._config}sendPing(){this.send(h.Frames.pingFrame(),null)}sendPong(){this.send(h.Frames.pongFrame(),null)}getRemoteAddress(){return this._assistant.getRemoteAddress(this._source)}getLocalAddress(){return this._assistant.getLocalAddress(this._source)}send(e,t){if(this.getConfig().clientMode()||console.debug("S-SEN:"+e),e.message()){const s=e.message();if(null!=t&&this._streamManger.addStream(s.sid(),t),null!=s.entity())return s.dataSize()>this.getConfig().getFragmentSize()&&s.putMeta(o.EntityMetas.META_DATA_LENGTH,s.dataSize().toString()),void this.getConfig().getFragmentHandler().spliFragment(this,t,s,(t=>{const i=new n.Frame(e.flag(),(new r.MessageBuilder).flag(e.flag()).sid(s.sid()).event(s.event()).entity(t).build());this._processor.sendFrame(this,i,this._assistant,this._source)}))}this._processor.sendFrame(this,e,this._assistant,this._source),null!=t&&t.onProgress(!0,1,1)}reconnect(){}onError(e){this._processor.onError(this,e)}getLiveTime(){return this._liveTime}setLiveTimeAsNow(){this._liveTime=(new Date).getTime()}setAlarmCode(e){this._alarmCode=e}getSession(){return null==this._session&&(this._session=new a.SessionDefault(this)),this._session}getStream(e){return this._streamManger.getStream(e)}setSession(e){this._session=e}close(e){try{this._closeCode=e,super.close(e),e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this._assistant.isValid(this._source)&&(setTimeout((()=>{this._assistant.close(this._source)}),100),console.debug(`${this.getConfig().getRoleName()} channel closed, sessionId=${this.getSession().sessionId()}`))}catch(e){console.warn(`${this.getConfig().getRoleName()} channel close error, sessionId=${this.getSession().sessionId()}`,e)}e>i.Constants.CLOSE1000_PROTOCOL_CLOSE_STARTING&&this.onCloseDo()}onCloseDo(){0==this._isCloseNotified&&(this._isCloseNotified=!0,this._processor.doCloseNotice(this))}}t.ChannelDefault=c},2331:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(7147),r=s(4797),i=s(2911),o=s(7400),a=s(6269),l=s(8431);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new l.StreamMangerDefault(this),this._codec=new n.CodecDefault(this),this._charset="utf-8",this._idGenerator=new a.GuidGenerator,this._fragmentHandler=new o.FragmentHandlerDefault,this._fragmentSize=r.Constants.MAX_SIZE_DATA,this._ioThreads=1,this._codecThreads=2,this._exchangeThreads=4*this._codecThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=6e4,this._requestTimeout=1e4,this._streamTimeout=72e5,this._maxUdpSize=2048}clientMode(){return this._clientMode}getStreamManger(){return this._streamManger}getRoleName(){return this.clientMode()?"Client":"Server"}getCharset(){return this._charset}charset(e){return this._charset=e,this}getCodec(){return this._codec}genId(){return this._idGenerator.generate()}idGenerator(e){return i.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return i.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>r.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=void 0;const n=s(6439),r=s(7704),i=s(6306),o=s(6862),a=s(3954),l=s(8991),h=s(4741);t.Frames=class{static connectFrame(e,t,s){const l=new h.StringEntity(t);return l.metaMapPut(s),l.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),new a.Frame(i.Flags.Connect,(new o.MessageBuilder).sid(e).event(t).entity(l).build())}static connackFrame(e){const t=new l.EntityDefault;return t.metaMapPut(e.getOutMetaMap()),t.metaPut(n.EntityMetas.META_SOCKETD_VERSION,r.SocketD.protocolVersion()),t.dataSet(e.getSource().data().getArray()),new a.Frame(i.Flags.Connack,(new o.MessageBuilder).sid(e.getSource().sid()).event(e.getSource().event()).entity(t).build())}static pingFrame(){return new a.Frame(i.Flags.Ping,null)}static pongFrame(){return new a.Frame(i.Flags.Pong,null)}static closeFrame(e){const t=new o.MessageBuilder;return t.entity(new h.StringEntity("").metaPut("code",e.toString())),new a.Frame(i.Flags.Close,t.build())}static alarmFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Alarm,s.build())}static pressureFrame(e,t){const s=new o.MessageBuilder;if(null!=e){let n=new l.EntityDefault;n.metaStringSet(e.metaString()),n.dataSet(t.data()),n.metaMapPut(t.metaMap()),s.sid(e.sid()),s.event(e.event()),s.entity(n)}else s.entity(t);return new a.Frame(i.Flags.Pressure,s.build())}}},7648:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(6306),r=s(7953),i=s(4797),o=s(4970),a=s(6439),l=s(4630);t.ProcessorDefault=class{constructor(){this._listener=new l.SimpleListener}setListener(e){null!=e&&(this._listener=e)}sendFrame(e,t,s,n){this.sendFrameHandle(e,t,s,n,((e,t)=>{}))}sendFrameHandle(e,t,s,r,i){try{s.write(r,t),t.flag()>=n.Flags.Message&&this._listener.onSend(e.getSession(),t.message()),i(!0,null)}catch(e){i(!1,e)}}reveFrame(e,t){this.reveFrameHandle(e,t)}reveFrameHandle(e,t){if(e.getConfig().clientMode()||console.debug("S-REV:"+t),t.flag()==n.Flags.Connect)e.setHandshake(new r.HandshakeDefault(t.message())),e.onOpenFuture(((t,s)=>{if(t){if(e.isValid())try{e.sendConnack()}catch(s){this.onError(e,s)}}else e.isValid()&&this.onCloseInternal(e,i.Constants.CLOSE2001_ERROR)})),this.onOpen(e);else if(t.flag()==n.Flags.Connack)e.setHandshake(new r.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(i.Constants.CLOSE1001_PROTOCOL_CLOSE),t.flag()==n.Flags.Close)throw new o.SocketDConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}e.setLiveTimeAsNow();try{switch(t.flag()){case n.Flags.Ping:e.sendPong();break;case n.Flags.Pong:break;case n.Flags.Close:{let s=0;null!=t.message()&&(s=t.message().metaAsInt("code")),0==s&&(s=i.Constants.CLOSE1001_PROTOCOL_CLOSE),this.onCloseInternal(e,s);break}case n.Flags.Alarm:{const s=new o.SocketDAlarmException(t.message());e.setAlarmCode(s.getAlarmCode());const n=e.getConfig().getStreamManger().getStream(t.message().sid());null==n?this.onError(e,s):(e.getConfig().getStreamManger().removeStream(t.message().sid()),n.onError(s));break}case n.Flags.Pressure:const s=t.message().metaAsInt("code");e.setAlarmCode(s);break;case n.Flags.Message:case n.Flags.Request:case n.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case n.Flags.Reply:case n.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:this.onCloseInternal(e,i.Constants.CLOSE1002_PROTOCOL_ILLEGAL)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,r=1,i=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(a.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){r=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,r,t.message());if(n&&(i=parseInt(t.message().metaOrDefault(a.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,r,i));t=o}}s?(n&&n.onProgress(!1,r,i),this.onReply(e,t,n)):this.onMessage(e,t)}onOpen(e){try{this._listener.onOpen(e.getSession()),e.doOpenFuture(!0,null)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onOpen error`,t),e.doOpenFuture(!1,t)}}onMessage(e,t){try{this._listener.onMessage(e.getSession(),t.message())}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onReply(e,t,s){s?((s.demands(){Object.defineProperty(t,"__esModule",{value:!0}),t.EventListener=void 0;const n=s(6789);t.EventListener=class{constructor(e){this._eventRouteSelector=e||new n.RouteSelectorDefault}doOn(e,t){return this._eventRouteSelector.put(e,t),this}doOnOpen(e){return this._doOnOpen=e,this}doOnMessage(e){return this._doOnMessage=e,this}doOnClose(e){return this._doOnClose=e,this}doOnError(e){return this._doOnError=e,this}onOpen(e){this._doOnOpen&&this._doOnOpen(e)}onMessage(e,t){this._doOnMessage&&this._doOnMessage(e,t);const s=this._eventRouteSelector.select(t.event());s&&s(e,t)}onReply(e,t){this._doOnReply&&this._doOnReply(e,t)}onSend(e,t){this._doOnSend&&this._doOnSend(e,t)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}}},1196:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PathListener=void 0;const n=s(6789),r=s(826);t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}doOf(e,t){return this._pathRouteSelector.put(e,t),this}of(e){const t=new r.EventListener;return this._pathRouteSelector.put(e,t),t}size(){return this._pathRouteSelector.size()}onOpen(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onOpen(e)}onMessage(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onMessage(e,t)}onReply(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onReply(e,t)}onSend(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onSend(e,t)}onClose(e){const t=this._pathRouteSelector.select(e.path());null!=t&&t.onClose(e)}onError(e,t){const s=this._pathRouteSelector.select(e.path());null!=s&&s.onError(e,t)}}},7054:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=void 0,t.PipelineListener=class{constructor(){this._deque=new Array}prev(e){return this._deque.unshift(e),this}next(e){return this._deque.push(e),this}size(){return this._deque.length}onOpen(e){for(const t of this._deque)t.onOpen(e)}onMessage(e,t){for(const s of this._deque)s.onMessage(e,t)}onReply(e,t){for(const s of this._deque)s.onReply(e,t)}onSend(e,t){for(const s of this._deque)s.onSend(e,t)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},4630:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SimpleListener=void 0,t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onReply(e,t){}onSend(e,t){}onClose(e){}onError(e,t){}}},9106:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerBase=void 0;const n=s(7648),r=s(4630),i=s(8422);t.ServerBase=class{constructor(e,t){this._processor=new n.ProcessorDefault,this._sessions=new Set,this._listener=new r.SimpleListener,this._config=e,this._assistant=t,this._processor.setListener(this)}getAssistant(){return this._assistant}getConfig(){return this._config}config(e){return e&&e(this._config),this}getProcessor(){return this._processor}listen(e){return e&&(this._listener=e),this}prestop(){this.prestopDo()}stop(){this.stopDo()}onOpen(e){this._sessions.add(e),this._listener.onOpen(e)}onMessage(e,t){this._listener.onMessage(e,t)}onReply(e,t){this._listener.onReply(e,t)}onSend(e,t){this._listener.onSend(e,t)}onClose(e){this._sessions.delete(e),this._listener.onClose(e)}onError(e,t){this._listener.onError(e,t)}prestopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.preclose()))}stopDo(){for(let e of this._sessions)e.isValid()&&i.RunUtils.runAndTry((()=>e.close()));this._sessions.clear()}}},8259:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServerConfig=void 0;const n=s(2331);class r extends n.ConfigBase{constructor(e){super(!1),this._schema=e,e.startsWith("sd:")&&(e=e.substring(3)),this._schemaCleaned=e,this._host="",this._port=8602}getSchema(){return this._schema}getHost(){return this._host}getHttpServer(){return this._httpServer}httpServer(e){return this._httpServer=e,this}host(e){return this._host=e,this}getPort(){return this._port}port(e){return this._port=e,this}getLocalUrl(){return this._host?"sd:"+this._schemaCleaned+"://"+this._host+":"+this._port:"sd:"+this._schemaCleaned+"://127.0.0.1:"+this._port}toString(){return"ServerConfig{schema='"+this._schemaCleaned+"', charset="+this._charset+", host='"+this._host+"', port="+this._port+", ioThreads="+this._ioThreads+", codecThreads="+this._codecThreads+", exchangeThreads="+this._exchangeThreads+", idleTimeout="+this._idleTimeout+", requestTimeout="+this._requestTimeout+", streamTimeout="+this._streamTimeout+", readBufferSize="+this._readBufferSize+", writeBufferSize="+this._writeBufferSize+", maxUdpSize="+this._maxUdpSize+"}"}}t.ServerConfig=r},5141:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RequestStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_SIGNLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=!0;try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}await(){return new Promise(((e,t)=>{this.thenReply((t=>{e(t)})).thenError((e=>{t(e)}))}))}thenReply(e){return this._doOnReply=e,this}}t.RequestStreamImpl=i},537:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SendStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e){super(e,n.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}}t.SendStreamImpl=i},2909:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamBase=void 0;const n=s(4970);t.StreamBase=class{constructor(e,t,s){this._sid=e,this._demands=t,this._timeout=s}sid(){return this._sid}demands(){return this._demands}timeout(){return this._timeout}insuranceStart(e,t){this._insuranceFuture||(this._insuranceFuture=setTimeout((()=>{e.removeStream(this.sid()),this.onError(new n.SocketDTimeoutException("The stream response timeout, sid="+this.sid()))}),t))}insuranceCancel(){this._insuranceFuture&&clearTimeout(this._insuranceFuture)}onError(e){this._doOnError&&this._doOnError(e)}onProgress(e,t,s){this._doOnProgress&&this._doOnProgress(e,t,s)}thenError(e){return this._doOnError=e,this}thenProgress(e){return this._doOnProgress=e,this}}},8431:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=void 0;const n=s(2911),r=s(4797);t.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(n.Asserts.assertNull("stream",t),t.demands()==r.Constants.DEMANDS_ZERO)return;this._streamMap.set(e,t);const s=t.timeout()>0?t.timeout():this._config.getStreamTimeout();s>0&&t.insuranceStart(this,s)}removeStream(e){const t=this.getStream(e);t&&(this._streamMap.delete(e),t.insuranceCancel(),console.debug(`${this._config.getRoleName()} stream removed, sid=${e}`))}}},5635:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SubscribeStreamImpl=void 0;const n=s(4797),r=s(2909);class i extends r.StreamBase{constructor(e,t){super(e,n.Constants.DEMANDS_MULTIPLE,t),this._isDone=!1}isDone(){return this._isDone}onReply(e){this._isDone=e.isEnd();try{this._doOnReply&&this._doOnReply(e)}catch(e){this.onError(e)}}thenReply(e){return this._doOnReply=e,this}}t.SubscribeStreamImpl=i},1174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(2608);t.WsChannelAssistant=class{constructor(e){this._config=e}read(e){return this._config.getCodec().read(new n.ArrayBufferCodecReader(e))}write(e,t){let s=this._config.getCodec().write(t,(e=>new n.ArrayBufferCodecWriter(e)));e.send(s.getBuffer())}isValid(e){return e.isOpen()}close(e){e.close()}getRemoteAddress(e){return e.remoteAddress()}getLocalAddress(e){return e.localAddress()}}},1976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(1174),r=s(7882),i=s(6704);class o extends i.ClientBase{constructor(e){super(e,new n.WsChannelAssistant(e))}createConnector(){return new r.WsClientConnector(this)}}t.WsClient=o},7882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(8511),r=s(9777),i=s(2171),o=s(9747),a=s(6306),l=s(4970);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{try{this._real=new c(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}catch(e){s(e)}}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class c{constructor(e,t,s){try{this._real=i.EnvBridge.createSdWebSocketClient(e,this)}catch(e){s(new r.ClientHandshakeResult(null,e))}this._client=t,this._channel=new o.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl(),this._client.getConfig().getMetaMap())}catch(e){console.warn("Client channel sendConnect error",e)}}onMessage(e){if(e.data()instanceof String)console.warn("Client channel unsupported onMessage(String test)");else try{let t=this._client.getAssistant().read(e.data());null!=t&&(t.flag()==a.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{this.handshakeFutureDo(t)})),this._client.getProcessor().reveFrame(this._channel,t))}catch(e){e instanceof l.SocketDConnectionException&&this.handshakeFutureDo(e),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this.handshakeFutureDo(e.error()),this._client.getProcessor().onError(this._channel,e.error())}onPing(e){}onPong(e){}handshakeFutureDo(e){this._handshakeFuture?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)):this._handshakeFuture=null}close(){this._real.close()}}t.WebSocketClientImpl=c},8491:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsProvider=void 0;const n=s(1976),r=s(7041);t.WsProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}createServer(e){return new r.WsServer(e)}}},7041:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketServerListener=t.WsServer=void 0;const r=s(1174),i=s(7704),o=n(s(2241)),a=s(8642),l=s(4797),h=s(9106);class c extends h.ServerBase{constructor(e){super(e,new r.WsChannelAssistant(e))}getTitle(){return"ws/js-websocket/v"+i.SocketD.version()}start(){if(this._isStarted)throw new Error("Socket.D server started");this._isStarted=!0,this.getConfig().getHttpServer()?this._server=new o.default.Server({server:this.getConfig().getHttpServer(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this.getConfig().getHost()?this._server=new o.default.Server({port:this.getConfig().getPort(),host:this.getConfig().getHost(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME}):this._server=new o.default.Server({port:this.getConfig().getPort(),handleProtocols:(e,t)=>i.SocketD.protocolName(),maxPayload:l.Constants.MAX_SIZE_FRAME});const e=new u(this);return this._server.on("connection",((t,s)=>{new a.SdWebSocketNodeJs(this.getConfig(),t,s,e)})),console.info("Socket.D server started: {server="+this.getConfig().getLocalUrl()+"}"),this}stop(){if(this._isStarted){this._isStarted=!1,super.stop();try{null!=this._server&&this._server.close()}catch(e){console.debug("Server stop error",e)}}}}t.WsServer=c;class u{constructor(e){this._server=e}getServer(){return this._server}onOpen(e){}onMessage(e){let t=e.socket().attachment(),s=this._server.getAssistant().read(e.data());null!=s&&this._server.getProcessor().reveFrame(t,s)}onClose(e){let t=e.socket().attachment();this._server.getProcessor().onClose(t)}onError(e){let t=e.socket().attachment();t&&this._server.getProcessor().onError(t,e.error())}onPing(e){this.assertHandshake(e.socket())}onPong(e){this.assertHandshake(e.socket())}assertHandshake(e){let t=e.attachment();return null!=t&&null!=t.getHandshake()||(e.close(),console.warn("Server channel no handshake onPingPong"),!1)}}t.SdWebSocketServerListener=u},2171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(9941),r=s(4967),i=s(7703),o=s(3734);var a;!function(e){e[e.Unknown=0]="Unknown",e[e.Browser=1]="Browser",e[e.NodeJs=2]="NodeJs",e[e.Uniapp=3]="Uniapp",e[e.Weixin=4]="Weixin"}(a||(t.Runtime=a={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Browser:"undefined"!=typeof process&&process.versions&&process.versions.node?a.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?a.Uniapp:"undefined"!=typeof wx&&wx.connectSocket&&wx.request?a.Weixin:a.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==a.Weixin?(console.info("Client channel use wechat api!"),new o.SdWebSocketWeixinClient(e,t)):s==a.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappClient(e,t)):s==a.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsClient(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserClient(e,t))}}},2874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketPongEventImpl=t.SdWebSocketPingEventImpl=t.SdWebSocketErrorEventImpl=t.SdWebSocketCloseEventImpl=t.SdWebSocketMessageEventImpl=t.SdWebSocketEventImpl=t.SdWebSocketState=void 0,function(e){e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED"}(s||(t.SdWebSocketState=s={})),t.SdWebSocketEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketMessageEventImpl=class{constructor(e,t){this._socket=e,this._data=t}socket(){return this._socket}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketErrorEventImpl=class{constructor(e,t){this._socket=e,this._error=t}socket(){return this._socket}error(){return this._error}},t.SdWebSocketPingEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}},t.SdWebSocketPongEventImpl=class{constructor(e){this._socket=e}socket(){return this._socket}}},9941:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketBrowserClient=class{constructor(e,t){this._real=new WebSocket(e,r.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.onopen=this.onOpen.bind(this),this._real.onmessage=this.onMessage.bind(this),this._real.onclose=this.onClose.bind(this),this._real.onerror=this.onError.bind(this)}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._real.readyState==WebSocket.CONNECTING}isClosed(){return this._real.readyState==WebSocket.CLOSED}isClosing(){return this._real.readyState==WebSocket.CLOSING}isOpen(){return this._real.readyState==WebSocket.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},8642:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJs=void 0;const r=s(2874),i=n(s(2241)),o=s(9871),a=s(9747),l=s(8422);t.SdWebSocketNodeJs=class{constructor(e,t,s,n){this._lastPongTime=0,this._config=e,this._real=t,this._listener=n,this._real.binaryType="arraybuffer",s.socket.remoteAddress?this._remoteAddress=new o.SocketAddress(s.socket.remoteAddress,s.socket.remoteFamily,s.socket.remotePort):this._remoteAddress=null,s.socket.localAddress?this._localAddress=new o.SocketAddress(s.socket.localAddress,s.socket.localFamily,s.socket.localPort):this._localAddress=null;const r=new a.ChannelDefault(this,n.getServer());this.attachmentPut(r),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this)),this._real.on("ping",this.onPing.bind(this)),this._real.on("pong",this.onPong.bind(this)),this.onOpen(),this._lastPongTime=(new Date).getTime(),this._heartbeatScheduledFuture=setInterval((()=>{this.doPing()}),2e4)}doPing(){(new Date).getTime()-this._lastPongTime>this._config.getIdleTimeout()?this._real.close():this._real.ping()}remoteAddress(){return this._remoteAddress}localAddress(){return this._localAddress}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){l.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture)));let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}onPing(){let e=new r.SdWebSocketPingEventImpl(this);this._listener.onPing(e)}onPong(){this._lastPongTime=(new Date).getTime();let e=new r.SdWebSocketPongEventImpl(this);this._listener.onPong(e)}close(){this._real.close()}send(e){this._real.send(e)}}},4967:function(e,t,s){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketNodeJsClient=void 0;const r=s(2874),i=n(s(2241)),o=s(7704);t.SdWebSocketNodeJsClient=class{constructor(e,t){this._real=new i.default(e,o.SocketD.protocolName()),this._listener=t,this._real.binaryType="arraybuffer",this._real.on("open",this.onOpen.bind(this)),this._real.on("message",this.onMessage.bind(this)),this._real.on("close",this.onClose.bind(this)),this._real.on("error",this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isClosed(){return this._real.readyState==i.default.CLOSED}isClosing(){return this._real.readyState==i.default.CLOSING}isConnecting(){return this._real.readyState==i.default.CONNECTING}isOpen(){return this._real.readyState==i.default.OPEN}onOpen(){let e=new r.SdWebSocketEventImpl(this);this._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(this,e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl(this);this._listener.onClose(e)}onError(e){let t=new r.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._real.close()}send(e){this._real.send(e)}}},7703:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketUniappClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,protocols:[r.SocketD.protocolName()],success:e=>{}}),this._listener=t,this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},3734:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinClient=void 0;const n=s(2874),r=s(7704);t.SdWebSocketWeixinClient=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e,protocols:[r.SocketD.protocolName()]}),this._listener=t,this._real.binaryType="arraybuffer",this._real.onOpen(this.onOpen.bind(this)),this._real.onMessage(this.onMessage.bind(this)),this._real.onClose(this.onClose.bind(this)),this._real.onError(this.onError.bind(this))}remoteAddress(){return null}localAddress(){return null}attachment(){return this._attachment}attachmentPut(e){this._attachment=e}isConnecting(){return this._state==n.SdWebSocketState.CONNECTING}isClosed(){return this._state==n.SdWebSocketState.CLOSED}isClosing(){return this._state==n.SdWebSocketState.CLOSING}isOpen(){return this._state==n.SdWebSocketState.OPEN}onOpen(e){let t=new n.SdWebSocketEventImpl(this);this._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(this,e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl(this);this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){let t=new n.SdWebSocketErrorEventImpl(this,e);this._listener.onError(t)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},8422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},9079:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionUtils=void 0,t.SessionUtils=class{static isActive(e){return null!=e&&e.isActive()}static isValid(e){return null!=e&&e.isValid()}}},8404:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StrUtils=void 0;class s{static guid(){let e="";for(let t=1;t<=32;t++)e+=Math.floor(16*Math.random()).toString(16);return e}static parseUri(e){if(!e)return"";let t=e.indexOf("?");if(t>0){let n=e.substring(0,t),r=e.substring(t,e.length),i=s.parseUriDo(n);return i.source=e,i.query=r.substring(1,r.length),i.relative=r,i}return s.parseUriDo(e)}static parseUriDo(e){if(!e)return"";let t=s.parseUriOptions,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;for(;i--;)r[t.key[i]]=n[i]||"";return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,(function(e,s,n){s&&(r[t.q.name][s]=n)})),r}static strToBuf(e,t){if(t||(t="utf-8"),"undefined"==typeof TextEncoder){let t=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(t).buffer}return(new TextEncoder).encode(e).buffer}static bufToStr(e,t,n,r){if(e.byteLength!=n){const s=new DataView(e),r=new ArrayBuffer(n),i=new DataView(r);for(let e=0;e{e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}},t={},s=function s(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,s),i.exports}(7704),n=window;for(var r in s)n[r]=s[r];s.__esModule&&Object.defineProperty(n,"__esModule",{value:!0}); \ No newline at end of file diff --git a/javascript/socketd-examples/demo02-node-ws/package.json b/javascript/socketd-examples/demo02-node-ws/package.json index 8abceebd..8c120725 100644 --- a/javascript/socketd-examples/demo02-node-ws/package.json +++ b/javascript/socketd-examples/demo02-node-ws/package.json @@ -3,7 +3,7 @@ "description": "SocketD Node Test Project", "author": "aoshiguchen", "dependencies": { - "@noear/socket.d": "2.5.5", + "@noear/socket.d": "2.5.6", "ws": "^8.16.0" } } diff --git a/javascript/socketd-examples/demo03-uniapp-ws/package.json b/javascript/socketd-examples/demo03-uniapp-ws/package.json index 95e12738..95a61b08 100644 --- a/javascript/socketd-examples/demo03-uniapp-ws/package.json +++ b/javascript/socketd-examples/demo03-uniapp-ws/package.json @@ -3,6 +3,6 @@ "description": "SocketD Uniapp Test Project", "author": "ZhangQi", "dependencies": { - "@noear/socket.d": "2.5.5" + "@noear/socket.d": "2.5.6" } } diff --git a/javascript/socketd-examples/demo06-im/index.html b/javascript/socketd-examples/demo06-im/index.html index d1b569b1..21e36751 100644 --- a/javascript/socketd-examples/demo06-im/index.html +++ b/javascript/socketd-examples/demo06-im/index.html @@ -4,7 +4,7 @@ Socket.D-im demo - +