diff --git a/.gitignore b/.gitignore index 87b77baa..94f088a8 100755 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ target/ *.ipr *.log *.flattened-pom.xml +*/package-lock.json ### NetBeans ### nbproject/private/ @@ -27,6 +28,7 @@ nbdist/ obj/ bin/ node_modules/ +.hbuilderx/ ### Mac files ### *.DS_Store diff --git a/android/android_test/app/build.gradle.kts b/android/android_test/app/build.gradle.kts index 4ae17924..39a1dbc5 100644 --- a/android/android_test/app/build.gradle.kts +++ b/android/android_test/app/build.gradle.kts @@ -41,9 +41,9 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.8.0") - implementation("org.noear:socketd-transport-java-tcp:2.3.2") - implementation("org.noear:socketd-transport-java-udp:2.3.2") - implementation("org.noear:socketd-transport-java-websocket:2.3.2") + implementation("org.noear:socketd-transport-java-tcp:2.3.3") + implementation("org.noear:socketd-transport-java-udp:2.3.3") + implementation("org.noear:socketd-transport-java-websocket:2.3.3") implementation("com.github.tony19:logback-android:3.0.0") diff --git a/java/socketd-examples/pom.xml b/java/socketd-examples/pom.xml index 8697ef23..249c6f41 100644 --- a/java/socketd-examples/pom.xml +++ b/java/socketd-examples/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.3.2 + 2.3.3 ../socketd-parent/pom.xml diff --git a/java/socketd-parent/pom.xml b/java/socketd-parent/pom.xml index bbef0b5d..ce71c050 100644 --- a/java/socketd-parent/pom.xml +++ b/java/socketd-parent/pom.xml @@ -6,7 +6,7 @@ org.noear socketd-parent - 2.3.2 + 2.3.3 pom ${project.artifactId} @@ -18,7 +18,7 @@ UTF-8 1.8 - 2.3.2 + 2.3.3 2.0.9 5.9.1 diff --git a/java/socketd-transport-test/pom.xml b/java/socketd-transport-test/pom.xml index 7f4d61a4..00bfa45b 100644 --- a/java/socketd-transport-test/pom.xml +++ b/java/socketd-transport-test/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.3.2 + 2.3.3 ../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 37085e33..3cadbd32 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.3.2 + 2.3.3 ../../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 50d5d0d1..b907c776 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.3.2 + 2.3.3 ../../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 63903de2..db282730 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.3.2 + 2.3.3 ../../socketd-parent/pom.xml diff --git a/java/socketd-transport/socketd-transport-java-udp/pom.xml b/java/socketd-transport/socketd-transport-java-udp/pom.xml index e9caca7e..f0535e61 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.3.2 + 2.3.3 ../../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 44fe52ea..f0484209 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.3.2 + 2.3.3 ../../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 de6ff590..84c543ff 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.3.2 + 2.3.3 ../../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 f17a2782..23041cbe 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.3.2 + 2.3.3 ../../socketd-parent/pom.xml diff --git a/java/socketd/pom.xml b/java/socketd/pom.xml index e1cffddd..fdc75f3a 100644 --- a/java/socketd/pom.xml +++ b/java/socketd/pom.xml @@ -7,7 +7,7 @@ org.noear socketd-parent - 2.3.2 + 2.3.3 ../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 e0f70d7c..d3f77870 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.3.2"; + return "2.3.3"; } /** diff --git a/javascript/ LOG.md b/javascript/ LOG.md index 98fdf062..68bd82f3 100644 --- a/javascript/ LOG.md +++ b/javascript/ LOG.md @@ -1,3 +1,7 @@ +### 2.3.3 + +* 完成 uniapp(h5,android,ios), node.js 兼容测试 + ### 2.3.1 * 添加 range 元信息快捷方式 diff --git a/javascript/HEAD.md b/javascript/HEAD.md deleted file mode 100644 index fbdbff6a..00000000 --- a/javascript/HEAD.md +++ /dev/null @@ -1,10 +0,0 @@ - -```javascript - -/*! - * Socket.D v2.3.2 - * (c) 2023-2024 noear.org and other contributors - * Released under the Apache-2.0 License. - */ - -``` \ No newline at end of file diff --git a/javascript/release/socket.d.js b/javascript/release/socket.d.js index c6fc28a4..5c87ab76 100644 --- a/javascript/release/socket.d.js +++ b/javascript/release/socket.d.js @@ -1,6 +1,6 @@ /*! - * Socket.D v2.3.2 + * Socket.D v2.3.3 * (c) 2023-2024 noear.org and other contributors * Released under the Apache-2.0 License. */ -var e={704:(e,t,s)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const r=s(911),i=s(545),a=s(243),o=s(481),l=s(165),h=s(852),u=s(797);class c{static version(){return"2.3.2"}static protocolVersion(){return"1.0"}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found.");return t}static createClientOrNull(e){r.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),n=this.clientProviderMap.get(s);if(null==n)return null;{const t=new i.ClientConfig(e);return n.createClient(t)}}static createClusterClient(e){return new a.ClusterClient(e)}static newEntity(e){return e?"[object String]"===toString.call(e)?new l.StringEntity(e.toString()):e instanceof File?new l.FileEntity(e):e instanceof ArrayBuffer||e instanceof Blob?(new l.EntityDefault).dataSet(e):new l.StringEntity(e.toString()):new l.EntityDefault}static newSimpleListener(){return new h.SimpleListener}static newEventListener(e){return new h.EventListener(e)}static newPathListener(e){return new h.PathListener(e)}static newPipelineListener(){return new h.PipelineListener}}t.SocketD=c,n=c,c.EntityMetas=u.EntityMetas,c.clientProviderMap=new Map,(()=>{const e=new o.WsClientProvider;for(const t of e.schemas())n.clientProviderMap.set(t,e);"undefined"!=typeof window&&(window.SocketD=n)})()},243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(270),i=s(704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}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*(){const e=new Array;for(const t of this._serverUrls)for(let s of t.split(",")){if(s=s.trim(),!s)continue;const t=i.SocketD.createClient(s);null!=this._listener&&t.listen(this._listener),null!=this._configHandler&&t.config(this._configHandler),null!=this._heartbeatHandler&&t.heartbeatHandler(this._heartbeatHandler);const n=yield t.open();e.push(n)}return new r.ClusterClientSession(e)}))}}},270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(404),r=s(921),i=s(422);t.ClusterClientSession=class{constructor(e){this._sessionSet=e,this._sessionId=n.StrUtils.guid(),this._sessionRoundCounter=0}getSessionAll(){return this._sessionSet}getSessionOne(){if(0==this._sessionSet.length)throw new r.SocketdException("No session!");if(1==this._sessionSet.length)return this._sessionSet[0];{const e=new Array;for(const t of this._sessionSet)t.isValid()&&e.push(t);if(0==e.length)throw new r.SocketdException("No session is available!");if(1==e.length)return e[0];const t=this._sessionRoundCounter++,s=t%e.length;return t>999999999&&(this._sessionRoundCounter=0),e[s]}}isValid(){for(const e of this._sessionSet)if(e.isValid())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.getSessionOne().send(e,t)}sendAndRequest(e,t,s){return this.getSessionOne().sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionOne().sendAndSubscribe(e,t,s)}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close)}}},921:(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._from=e}getFrom(){return this._from}},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)}}},421:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const r=s(405),i=s(213),a=s(39);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new r.ProcessorDefault}getAssistant(){return this._assistant}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}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 n(this,void 0,void 0,(function*(){const e=this.createConnector(),t=yield e.connect(),s=new i.ClientChannel(t,e);s.setHandshake(t.getHandshake());const n=new a.SessionDefault(s);return t.setSession(n),console.info("Socket.D client successfully connected!"),n}))}}},213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(998),i=s(569),a=s(797),o=s(911),l=s(921),h=s(422);class u extends r.ChannelBase{constructor(e,t){super(e.getConfig()),this._connector=t,this._real=e,null==t.heartbeatHandler()?this._heartbeatHandler=new i.HeartbeatHandlerDefault(null):this._heartbeatHandler=new i.HeartbeatHandlerDefault(t.heartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>{try{this.heartbeatHandle()}catch(e){console.warn("Client channel heartbeat error",e)}}),this._connector.heartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(null!=this._real){if(null==this._real.getHandshake())return;if(this._real.isClosed()==a.Constants.CLOSE4_USER)return void console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`)}try{yield this.prepareCheck(),this._heartbeatHandler.heartbeat(this.getSession())}catch(e){if(e instanceof l.SocketdException)throw e;throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),new l.SocketdChannelException(e)}}))}prepareCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(this._real=yield this._connector.connect(),!0)}))}isValid(){return null!=this._real&&this._real.isValid()}isClosed(){return null==this._real?0:this._real.isClosed()}send(e,t){return n(this,void 0,void 0,(function*(){o.Asserts.assertClosedByUser(this._real);try{yield this.prepareCheck(),this._real.send(e,t)}catch(e){throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),e}}))}retrieve(e,t){this._real.retrieve(e,t)}reconnect(){this.initHeartbeat(),this.prepareCheck()}onError(e){this._real.onError(e)}close(e){h.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),h.RunUtils.runAndTry((()=>this._connector.close())),this._real&&h.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._real.getSession()}}t.ClientChannel=u},545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(628),r=s(404);class i extends n.ConfigBase{constructor(e){super(!0),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let t=r.StrUtils.parseUri(e);this._port=parseInt(t.port),this._schema=t.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getUrl(){return this._url}getLinkUrl(){return this._linkUrl}getHost(){return this._host}getPort(){return this._port}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._schema+"', charset="+this._charset+", url='"+this._url+"', 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},511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}heartbeatHandler(){return this._client.getHeartbeatHandler()}heartbeatInterval(){return this._client.getHeartbeatInterval()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},777:(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}}},911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(797),r=s(921);t.Asserts=class{static assertClosed(e){if(null!=e&&e.isClosed()>0)throw new r.SocketdChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertClosedByUser(e){if(null!=e&&e.isClosed()==n.Constants.CLOSE4_USER)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)}}}},560:(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,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}}},998:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(954);t.ChannelBase=class{constructor(e){this._isClosed=0,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)}isClosed(){return this._isClosed}close(e){this._isClosed=e,this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e){this.send(n.Frames.connectFrame(this.getConfig().getIdGenerator().generate(),e),null)}sendConnack(e){this.send(n.Frames.connackFrame(e),null)}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}sendClose(){this.send(n.Frames.closeFrame(),null)}sendAlarm(e,t){this.send(n.Frames.alarmFrame(e,t),null)}}},930:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(954),r=s(862),i=s(797),a=s(998),o=s(39);class l extends a.ChannelBase{constructor(e,t){super(t.getConfig()),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.isClosed()&&this._assistant.isValid(this._source)}config(){return this._config}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}send(e,t){if(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(i.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._assistant.write(this._source,i)}))}this._assistant.write(this._source,e),null!=t&&t.onProgress(!0,1,1)}retrieve(e,t){t?((t.demands(){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}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.CodecByteBuffer=void 0;const n=s(954),r=s(404),i=s(911),a=s(797),o=s(862),l=s(165);t.CodecByteBuffer=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()),o=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+o.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,a.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,a.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",o.byteLength,a.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),a.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(o),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(a.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),h=this.decodeString(e,i,a.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,a.Constants.MAX_SIZE_EVENT),c=this.decodeString(e,i,a.Constants.MAX_SIZE_META_STRING),d=t-e.position();let _;if(d>a.Constants.MAX_SIZE_DATA){_=new ArrayBuffer(a.Constants.MAX_SIZE_DATA),e.getBytes(_,0,a.Constants.MAX_SIZE_DATA);for(let t=d-a.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else _=new ArrayBuffer(d),d>0&&e.getBytes(_,0,d);const g=(new o.MessageBuilder).flag(a.Flags.of(s)).sid(h).event(u).entity((new l.EntityDefault).dataSet(_).metaStringSet(c)).build();return new n.Frame(g.flag(),g)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(10==t)break;s>0&&s<=i||0!=t&&(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},628:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(895),r=s(67),i=s(351),a=s(797),o=s(911),l=s(905);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new n.StreamMangerDefault(this),this._codec=new l.CodecByteBuffer(this),this._charset="utf-8",this._idGenerator=new r.GuidGenerator,this._fragmentHandler=new i.FragmentHandlerDefault,this._fragmentSize=a.Constants.MAX_SIZE_DATA,this._coreThreads=2,this._maxThreads=4*this._coreThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=0,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}getIdGenerator(){return this._idGenerator}idGenerator(e){return o.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return o.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>a.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=t.Flags=t.Constants=void 0;const n=s(560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1_PROTOCOL:1,CLOSE2_PROTOCOL_ILLEGAL:2,CLOSE3_ERROR:3,CLOSE4_USER:4,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2},t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,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 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.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"}}},t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",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"}},165:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=t.StringEntity=t.EntityDefault=void 0;const n=s(404),r=s(608),i=s(797),a=s(560),o=s(921);class l{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(){return this.meta("@")}range(e,t){return this.metaPut(i.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(i.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 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 this.metaMap().set(e,t),this}metaString(){return this.metaMap().toString()}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"))}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}putMeta(e,t){this.metaPut(e,t)}dataSet(e){return e instanceof ArrayBuffer?this._data=new a.ByteBuffer(e):this._data=new a.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new o.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 o.SocketdException("Blob does not support dataAsString");return n.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}t.EntityDefault=l,t.StringEntity=class extends l{constructor(e){super();const t=n.StrUtils.strToBuf(e);this.dataSet(t)}},t.FileEntity=class extends l{constructor(e){super(),this.dataSet(e),this.metaPut(i.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}},187:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(862),r=s(165),i=s(954),a=s(72),o=s(797),l=s(921);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(o.EntityMetas.META_DATA_LENGTH);if(!t)throw new l.SocketdCodecException("Missing '"+o.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 a.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(165),r=s(797),i=s(187);t.FragmentHandlerDefault=class{spliFragment(e,t,s,r){if(s.dataSize()>e.getConfig().getFragmentSize()){let n=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(n,i,e,t,s,r)}else null==s.data().getBlob()?(r(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{r((new n.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,i,a,o){e++,a.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new n.EntityDefault).dataSet(l);1==e&&h.metaMapPut(a.metaMap()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),o(h),null!=i&&i.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,i,a,o)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new i.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}}},72:(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}}},954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=t.Frame=void 0;const n=s(165),r=s(797),i=s(862),a=s(704);class o{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+r.Flags.name(this._flag)+", message="+this._message+"}"}}t.Frame=o,t.Frames=class{static connectFrame(e,t){const s=new n.StringEntity(t);return s.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),new o(r.Flags.Connect,(new i.MessageBuilder).sid(e).event(t).entity(s).build())}static connackFrame(e){const t=new n.EntityDefault;return t.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),t.dataSet(e.data().getArray()),new o(r.Flags.Connack,(new i.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build())}static pingFrame(){return new o(r.Flags.Ping,null)}static pongFrame(){return new o(r.Flags.Pong,null)}static closeFrame(){return new o(r.Flags.Close,null)}static alarmFrame(e,t){const s=new i.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new n.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new n.StringEntity(t)),new o(r.Flags.Alarm,s.build())}}},953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(797),r=s(404);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._paramMap=new Map;let s=r.StrUtils.parseUri(t);this._path=s.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))}}getSource(){return this._source}param(e){return this._paramMap.get(e)}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}uri(){return this._url}path(){return this._path}version(){return this._version}}},569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HeartbeatHandlerDefault=void 0,t.HeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}heartbeat(e){null==this._heartbeatHandler?e.sendPing():this._heartbeatHandler(e)}}},67:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},852:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=t.PathListener=t.EventListener=t.SimpleListener=void 0;const n=s(789);t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onClose(e){}onError(e,t){}},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)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}},t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}of(e,t){return this._pathRouteSelector.put(e,t),this}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)}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)}},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)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(797);t.MessageBuilder=class{constructor(){this._flag=n.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 r(this._flag,this._sid,this._event,this._entity)}};class r{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}at(){return this._entity.at()}rangeStart(){return this.metaAsInt(n.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(n.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==n.Flags.Request}isSubscribe(){return this._flag==n.Flags.Subscribe}isEnd(){return this._flag==n.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)}metaAsFloat(e){return this._entity.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}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=r},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(852),r=s(797),i=s(921),a=s(953);t.ProcessorDefault=class{constructor(){this._listener=new n.SimpleListener}setListener(e){null!=e&&(this._listener=e)}onReceive(e,t){if(t.flag()==r.Flags.Connect)e.setHandshake(new a.HandshakeDefault(t.message())),e.onOpenFuture(((s,n)=>{if(s&&e.isValid())try{e.sendConnack(t.message())}catch(n){this.onError(e,n)}})),this.onOpen(e);else if(t.flag()==r.Flags.Connack)e.setHandshake(new a.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(r.Constants.CLOSE1_PROTOCOL),t.flag()==r.Flags.Close)throw new i.SocketdConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}try{switch(t.flag()){case r.Flags.Ping:e.sendPong();break;case r.Flags.Pong:break;case r.Flags.Close:e.close(r.Constants.CLOSE1_PROTOCOL),this.onCloseInternal(e);break;case r.Flags.Alarm:{const s=new i.SocketdAlarmException(t.message()),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 r.Flags.Message:case r.Flags.Request:case r.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case r.Flags.Reply:case r.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:e.close(r.Constants.CLOSE2_PROTOCOL_ILLEGAL),this.onCloseInternal(e)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,i=1,a=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(r.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){i=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,i,t.message());if(n&&(a=parseInt(t.message().metaOrDefault(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,i,a));t=o}}s?(n&&n.onProgress(!1,i,a),e.retrieve(t,n)):this.onMessage(e,t.message())}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)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onClose(e){0==e.isClosed()&&this.onCloseInternal(e)}onCloseInternal(e){this._listener.onClose(e.getSession())}onError(e,t){this._listener.onError(e.getSession(),t)}}},789:(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}}},305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._sessionId=this.generateId()}sessionId(){return this._sessionId}name(){return this.param("@")}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)}generateId(){return this._channel.getConfig().getIdGenerator().generate()}}},39:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(305),r=s(862),i=s(954),a=s(797),o=s(895);class l extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}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){const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new o.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getRequestTimeout());const l=new o.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),l),l}sendAndSubscribe(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getStreamTimeout());const l=new o.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),l),l}reply(e,t){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){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)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose()}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(a.Constants.CLOSE4_USER)}}t.SessionDefault=l},895:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=t.SubscribeStreamImpl=t.RequestStreamImpl=t.SendStreamImpl=t.StreamBase=void 0;const n=s(921),r=s(911),i=s(797);class a{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}}t.StreamBase=a,t.SendStreamImpl=class extends a{constructor(e){super(e,i.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}},t.RequestStreamImpl=class extends a{constructor(e,t){super(e,i.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.SubscribeStreamImpl=class extends a{constructor(e,t){super(e,i.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.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(r.Asserts.assertNull("stream",t),t.demands()==i.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}`))}}},174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(608);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){throw new Error("Method not implemented.")}getLocalAddress(e){throw new Error("Method not implemented.")}}},976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(421),r=s(174),i=s(882);class a extends n.ClientBase{constructor(e){super(e,new r.WsChannelAssistant(e))}createConnector(){return new i.WsClientConnector(this)}}t.WsClient=a},882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(511),r=s(777),i=s(171),a=s(930),o=s(797),l=s(921);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{this._real=new u(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class u{constructor(e,t,s){this._real=i.EnvBridge.createSdWebSocketClient(e,this),this._client=t,this._channel=new a.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl())}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()==o.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{null==t?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,null)):this._handshakeFuture(new r.ClientHandshakeResult(this._channel,t))})),this._client.getProcessor().onReceive(this._channel,t))}catch(e){e instanceof l.SocketdConnectionException&&this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this._client.getProcessor().onError(this._channel,e)}close(){this._real.close()}}t.WebSocketClientImpl=u},481:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClientProvider=void 0;const n=s(976);t.WsClientProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}}},171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(14),r=s(769),i=s(73),a=s(865);var o;!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"}(o||(t.Runtime=o={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:window.navigator.userAgent.toLowerCase().indexOf("MicroMessenger")<0?o.Browser:o.Weixin:"undefined"!=typeof process&&process.versions&&process.versions.node?o.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:o.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==o.Weixin?(console.info("Client channel use xeixin api!"),new a.SdWebSocketWeixinImpl(e,t)):s==o.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappImpl(e,t)):s==o.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsImpl(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserImpl(e,t))}}},874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),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{},t.SdWebSocketMessageEventImpl=class{constructor(e){this._data=e}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{}},14:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserImpl=void 0;const n=s(874);t.SdWebSocketBrowserImpl=class{constructor(e,t){this._real=new WebSocket(e),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)}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._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},769: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.SdWebSocketNodeJsImpl=void 0;const r=s(874),i=n(s(241));t.SdWebSocketNodeJsImpl=class{constructor(e,t){this._real=new i.default(e),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))}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._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl;this._listener.onClose(e)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},73:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappImpl=void 0;const n=s(874);t.SdWebSocketUniappImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},865:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinImpl=void 0;const n=s(874);t.SdWebSocketWeixinImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e}),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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},404:(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=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){t||(t="utf-8");var s=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(s).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}(704),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={704:(e,t,s)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const r=s(911),i=s(545),a=s(243),o=s(481),l=s(165),h=s(852),u=s(797);class c{static version(){return"2.3.3"}static protocolVersion(){return"1.0"}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found.");return t}static createClientOrNull(e){r.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),n=this.clientProviderMap.get(s);if(null==n)return null;{const t=new i.ClientConfig(e);return n.createClient(t)}}static createClusterClient(e){return new a.ClusterClient(e)}static newEntity(e){return e?"[object String]"===toString.call(e)?new l.StringEntity(e.toString()):e instanceof File?new l.FileEntity(e):e instanceof ArrayBuffer||e instanceof Blob?(new l.EntityDefault).dataSet(e):new l.StringEntity(e.toString()):new l.EntityDefault}static newSimpleListener(){return new h.SimpleListener}static newEventListener(e){return new h.EventListener(e)}static newPathListener(e){return new h.PathListener(e)}static newPipelineListener(){return new h.PipelineListener}}t.SocketD=c,n=c,c.EntityMetas=u.EntityMetas,c.clientProviderMap=new Map,(()=>{const e=new o.WsClientProvider;for(const t of e.schemas())n.clientProviderMap.set(t,e);"undefined"!=typeof window&&(window.SocketD=n)})()},243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(270),i=s(704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}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*(){const e=new Array;for(const t of this._serverUrls)for(let s of t.split(",")){if(s=s.trim(),!s)continue;const t=i.SocketD.createClient(s);null!=this._listener&&t.listen(this._listener),null!=this._configHandler&&t.config(this._configHandler),null!=this._heartbeatHandler&&t.heartbeatHandler(this._heartbeatHandler);const n=yield t.open();e.push(n)}return new r.ClusterClientSession(e)}))}}},270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(404),r=s(921),i=s(422);t.ClusterClientSession=class{constructor(e){this._sessionSet=e,this._sessionId=n.StrUtils.guid(),this._sessionRoundCounter=0}getSessionAll(){return this._sessionSet}getSessionOne(){if(0==this._sessionSet.length)throw new r.SocketdException("No session!");if(1==this._sessionSet.length)return this._sessionSet[0];{const e=new Array;for(const t of this._sessionSet)t.isValid()&&e.push(t);if(0==e.length)throw new r.SocketdException("No session is available!");if(1==e.length)return e[0];const t=this._sessionRoundCounter++,s=t%e.length;return t>999999999&&(this._sessionRoundCounter=0),e[s]}}isValid(){for(const e of this._sessionSet)if(e.isValid())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.getSessionOne().send(e,t)}sendAndRequest(e,t,s){return this.getSessionOne().sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionOne().sendAndSubscribe(e,t,s)}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close)}}},921:(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._from=e}getFrom(){return this._from}},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)}}},421:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const r=s(405),i=s(213),a=s(39);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new r.ProcessorDefault}getAssistant(){return this._assistant}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}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 n(this,void 0,void 0,(function*(){const e=this.createConnector(),t=yield e.connect(),s=new i.ClientChannel(t,e);s.setHandshake(t.getHandshake());const n=new a.SessionDefault(s);return t.setSession(n),console.info("Socket.D client successfully connected!"),n}))}}},213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(998),i=s(569),a=s(797),o=s(911),l=s(921),h=s(422);class u extends r.ChannelBase{constructor(e,t){super(e.getConfig()),this._connector=t,this._real=e,null==t.heartbeatHandler()?this._heartbeatHandler=new i.HeartbeatHandlerDefault(null):this._heartbeatHandler=new i.HeartbeatHandlerDefault(t.heartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>{try{this.heartbeatHandle()}catch(e){console.warn("Client channel heartbeat error",e)}}),this._connector.heartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(null!=this._real){if(null==this._real.getHandshake())return;if(this._real.isClosed()==a.Constants.CLOSE4_USER)return void console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`)}try{yield this.prepareCheck(),this._heartbeatHandler.heartbeat(this.getSession())}catch(e){if(e instanceof l.SocketdException)throw e;throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),new l.SocketdChannelException(e)}}))}prepareCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(this._real=yield this._connector.connect(),!0)}))}isValid(){return null!=this._real&&this._real.isValid()}isClosed(){return null==this._real?0:this._real.isClosed()}send(e,t){return n(this,void 0,void 0,(function*(){o.Asserts.assertClosedByUser(this._real);try{yield this.prepareCheck(),this._real.send(e,t)}catch(e){throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),e}}))}retrieve(e,t){this._real.retrieve(e,t)}reconnect(){this.initHeartbeat(),this.prepareCheck()}onError(e){this._real.onError(e)}close(e){h.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),h.RunUtils.runAndTry((()=>this._connector.close())),this._real&&h.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._real.getSession()}}t.ClientChannel=u},545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(628),r=s(404);class i extends n.ConfigBase{constructor(e){super(!0),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let t=r.StrUtils.parseUri(e);this._port=parseInt(t.port),this._schema=t.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getUrl(){return this._url}getLinkUrl(){return this._linkUrl}getHost(){return this._host}getPort(){return this._port}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._schema+"', charset="+this._charset+", url='"+this._url+"', 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},511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}heartbeatHandler(){return this._client.getHeartbeatHandler()}heartbeatInterval(){return this._client.getHeartbeatInterval()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},777:(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}}},911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(797),r=s(921);t.Asserts=class{static assertClosed(e){if(null!=e&&e.isClosed()>0)throw new r.SocketdChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertClosedByUser(e){if(null!=e&&e.isClosed()==n.Constants.CLOSE4_USER)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)}}}},560:(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,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}}},998:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(954);t.ChannelBase=class{constructor(e){this._isClosed=0,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)}isClosed(){return this._isClosed}close(e){this._isClosed=e,this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e){this.send(n.Frames.connectFrame(this.getConfig().getIdGenerator().generate(),e),null)}sendConnack(e){this.send(n.Frames.connackFrame(e),null)}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}sendClose(){this.send(n.Frames.closeFrame(),null)}sendAlarm(e,t){this.send(n.Frames.alarmFrame(e,t),null)}}},930:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(954),r=s(862),i=s(797),a=s(998),o=s(39);class l extends a.ChannelBase{constructor(e,t){super(t.getConfig()),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.isClosed()&&this._assistant.isValid(this._source)}config(){return this._config}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}send(e,t){if(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(i.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._assistant.write(this._source,i)}))}this._assistant.write(this._source,e),null!=t&&t.onProgress(!0,1,1)}retrieve(e,t){t?((t.demands(){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}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.CodecByteBuffer=void 0;const n=s(954),r=s(404),i=s(911),a=s(797),o=s(862),l=s(165);t.CodecByteBuffer=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()),o=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+o.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,a.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,a.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",o.byteLength,a.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),a.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(o),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(a.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),h=this.decodeString(e,i,a.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,a.Constants.MAX_SIZE_EVENT),c=this.decodeString(e,i,a.Constants.MAX_SIZE_META_STRING),d=t-e.position();let _;if(d>a.Constants.MAX_SIZE_DATA){_=new ArrayBuffer(a.Constants.MAX_SIZE_DATA),e.getBytes(_,0,a.Constants.MAX_SIZE_DATA);for(let t=d-a.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else _=new ArrayBuffer(d),d>0&&e.getBytes(_,0,d);const g=(new o.MessageBuilder).flag(a.Flags.of(s)).sid(h).event(u).entity((new l.EntityDefault).dataSet(_).metaStringSet(c)).build();return new n.Frame(g.flag(),g)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(10==t)break;s>0&&s<=i||0!=t&&(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},628:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(895),r=s(67),i=s(351),a=s(797),o=s(911),l=s(905);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new n.StreamMangerDefault(this),this._codec=new l.CodecByteBuffer(this),this._charset="utf-8",this._idGenerator=new r.GuidGenerator,this._fragmentHandler=new i.FragmentHandlerDefault,this._fragmentSize=a.Constants.MAX_SIZE_DATA,this._coreThreads=2,this._maxThreads=4*this._coreThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=0,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}getIdGenerator(){return this._idGenerator}idGenerator(e){return o.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return o.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>a.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=t.Flags=t.Constants=void 0;const n=s(560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1_PROTOCOL:1,CLOSE2_PROTOCOL_ILLEGAL:2,CLOSE3_ERROR:3,CLOSE4_USER:4,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2},t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,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 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.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"}}},t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",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"}},165:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=t.StringEntity=t.EntityDefault=void 0;const n=s(404),r=s(608),i=s(797),a=s(560),o=s(921);class l{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(){return this.meta("@")}range(e,t){return this.metaPut(i.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(i.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 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 this.metaMap().set(e,t),this}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"))}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}putMeta(e,t){this.metaPut(e,t)}dataSet(e){return e instanceof ArrayBuffer?this._data=new a.ByteBuffer(e):this._data=new a.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new o.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 o.SocketdException("Blob does not support dataAsString");return n.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}t.EntityDefault=l,t.StringEntity=class extends l{constructor(e){super();const t=n.StrUtils.strToBuf(e);this.dataSet(t)}},t.FileEntity=class extends l{constructor(e){super(),this.dataSet(e),this.metaPut(i.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}},187:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(862),r=s(165),i=s(954),a=s(72),o=s(797),l=s(921);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(o.EntityMetas.META_DATA_LENGTH);if(!t)throw new l.SocketdCodecException("Missing '"+o.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 a.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(165),r=s(797),i=s(187);t.FragmentHandlerDefault=class{spliFragment(e,t,s,r){if(s.dataSize()>e.getConfig().getFragmentSize()){let n=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(n,i,e,t,s,r)}else null==s.data().getBlob()?(r(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{r((new n.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,i,a,o){e++,a.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new n.EntityDefault).dataSet(l);1==e&&h.metaMapPut(a.metaMap()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),o(h),null!=i&&i.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,i,a,o)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new i.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}}},72:(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}}},954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=t.Frame=void 0;const n=s(165),r=s(797),i=s(862),a=s(704);class o{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+r.Flags.name(this._flag)+", message="+this._message+"}"}}t.Frame=o,t.Frames=class{static connectFrame(e,t){const s=new n.StringEntity(t);return s.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),new o(r.Flags.Connect,(new i.MessageBuilder).sid(e).event(t).entity(s).build())}static connackFrame(e){const t=new n.EntityDefault;return t.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),t.dataSet(e.data().getArray()),new o(r.Flags.Connack,(new i.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build())}static pingFrame(){return new o(r.Flags.Ping,null)}static pongFrame(){return new o(r.Flags.Pong,null)}static closeFrame(){return new o(r.Flags.Close,null)}static alarmFrame(e,t){const s=new i.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new n.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new n.StringEntity(t)),new o(r.Flags.Alarm,s.build())}}},953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(797),r=s(404);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._paramMap=new Map;let s=r.StrUtils.parseUri(t);this._path=s.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))}}getSource(){return this._source}param(e){return this._paramMap.get(e)}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}uri(){return this._url}path(){return this._path}version(){return this._version}}},569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HeartbeatHandlerDefault=void 0,t.HeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}heartbeat(e){null==this._heartbeatHandler?e.sendPing():this._heartbeatHandler(e)}}},67:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},852:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=t.PathListener=t.EventListener=t.SimpleListener=void 0;const n=s(789);t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onClose(e){}onError(e,t){}},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)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}},t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}of(e,t){return this._pathRouteSelector.put(e,t),this}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)}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)}},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)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(797);t.MessageBuilder=class{constructor(){this._flag=n.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 r(this._flag,this._sid,this._event,this._entity)}};class r{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}at(){return this._entity.at()}rangeStart(){return this.metaAsInt(n.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(n.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==n.Flags.Request}isSubscribe(){return this._flag==n.Flags.Subscribe}isEnd(){return this._flag==n.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)}metaAsFloat(e){return this._entity.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}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=r},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(852),r=s(797),i=s(921),a=s(953);t.ProcessorDefault=class{constructor(){this._listener=new n.SimpleListener}setListener(e){null!=e&&(this._listener=e)}onReceive(e,t){if(t.flag()==r.Flags.Connect)e.setHandshake(new a.HandshakeDefault(t.message())),e.onOpenFuture(((s,n)=>{if(s&&e.isValid())try{e.sendConnack(t.message())}catch(n){this.onError(e,n)}})),this.onOpen(e);else if(t.flag()==r.Flags.Connack)e.setHandshake(new a.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(r.Constants.CLOSE1_PROTOCOL),t.flag()==r.Flags.Close)throw new i.SocketdConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}try{switch(t.flag()){case r.Flags.Ping:e.sendPong();break;case r.Flags.Pong:break;case r.Flags.Close:e.close(r.Constants.CLOSE1_PROTOCOL),this.onCloseInternal(e);break;case r.Flags.Alarm:{const s=new i.SocketdAlarmException(t.message()),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 r.Flags.Message:case r.Flags.Request:case r.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case r.Flags.Reply:case r.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:e.close(r.Constants.CLOSE2_PROTOCOL_ILLEGAL),this.onCloseInternal(e)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,i=1,a=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(r.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){i=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,i,t.message());if(n&&(a=parseInt(t.message().metaOrDefault(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,i,a));t=o}}s?(n&&n.onProgress(!1,i,a),e.retrieve(t,n)):this.onMessage(e,t.message())}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)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onClose(e){0==e.isClosed()&&this.onCloseInternal(e)}onCloseInternal(e){this._listener.onClose(e.getSession())}onError(e,t){this._listener.onError(e.getSession(),t)}}},789:(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}}},305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._sessionId=this.generateId()}sessionId(){return this._sessionId}name(){return this.param("@")}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)}generateId(){return this._channel.getConfig().getIdGenerator().generate()}}},39:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(305),r=s(862),i=s(954),a=s(797),o=s(895);class l extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}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){const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new o.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getRequestTimeout());const l=new o.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),l),l}sendAndSubscribe(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getStreamTimeout());const l=new o.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),l),l}reply(e,t){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){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)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose()}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(a.Constants.CLOSE4_USER)}}t.SessionDefault=l},895:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=t.SubscribeStreamImpl=t.RequestStreamImpl=t.SendStreamImpl=t.StreamBase=void 0;const n=s(921),r=s(911),i=s(797);class a{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}}t.StreamBase=a,t.SendStreamImpl=class extends a{constructor(e){super(e,i.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}},t.RequestStreamImpl=class extends a{constructor(e,t){super(e,i.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.SubscribeStreamImpl=class extends a{constructor(e,t){super(e,i.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.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(r.Asserts.assertNull("stream",t),t.demands()==i.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}`))}}},174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(608);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){throw new Error("Method not implemented.")}getLocalAddress(e){throw new Error("Method not implemented.")}}},976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(421),r=s(174),i=s(882);class a extends n.ClientBase{constructor(e){super(e,new r.WsChannelAssistant(e))}createConnector(){return new i.WsClientConnector(this)}}t.WsClient=a},882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(511),r=s(777),i=s(171),a=s(930),o=s(797),l=s(921);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{this._real=new u(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class u{constructor(e,t,s){this._real=i.EnvBridge.createSdWebSocketClient(e,this),this._client=t,this._channel=new a.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl())}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()==o.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{null==t?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,null)):this._handshakeFuture(new r.ClientHandshakeResult(this._channel,t))})),this._client.getProcessor().onReceive(this._channel,t))}catch(e){e instanceof l.SocketdConnectionException&&this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this._client.getProcessor().onError(this._channel,e)}close(){this._real.close()}}t.WebSocketClientImpl=u},481:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClientProvider=void 0;const n=s(976);t.WsClientProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}}},171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(14),r=s(769),i=s(73),a=s(865);var o;!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"}(o||(t.Runtime=o={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:window.navigator.userAgent.toLowerCase().indexOf("MicroMessenger")<0?o.Browser:o.Weixin:"undefined"!=typeof process&&process.versions&&process.versions.node?o.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:o.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==o.Weixin?(console.info("Client channel use xeixin api!"),new a.SdWebSocketWeixinImpl(e,t)):s==o.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappImpl(e,t)):s==o.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsImpl(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserImpl(e,t))}}},874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),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{},t.SdWebSocketMessageEventImpl=class{constructor(e){this._data=e}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{}},14:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserImpl=void 0;const n=s(874);t.SdWebSocketBrowserImpl=class{constructor(e,t){this._real=new WebSocket(e),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)}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._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},769: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.SdWebSocketNodeJsImpl=void 0;const r=s(874),i=n(s(241));t.SdWebSocketNodeJsImpl=class{constructor(e,t){this._real=new i.default(e),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))}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._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl;this._listener.onClose(e)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},73:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappImpl=void 0;const n=s(874);t.SdWebSocketUniappImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},865:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinImpl=void 0;const n=s(874);t.SdWebSocketWeixinImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e}),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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},404:(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=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){t||(t="utf-8");var s=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(s).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}(704),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.js b/javascript/socketd-examples/demo01-js-ws/js/socket.d.js index c6fc28a4..5c87ab76 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.3.2 + * Socket.D v2.3.3 * (c) 2023-2024 noear.org and other contributors * Released under the Apache-2.0 License. */ -var e={704:(e,t,s)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const r=s(911),i=s(545),a=s(243),o=s(481),l=s(165),h=s(852),u=s(797);class c{static version(){return"2.3.2"}static protocolVersion(){return"1.0"}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found.");return t}static createClientOrNull(e){r.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),n=this.clientProviderMap.get(s);if(null==n)return null;{const t=new i.ClientConfig(e);return n.createClient(t)}}static createClusterClient(e){return new a.ClusterClient(e)}static newEntity(e){return e?"[object String]"===toString.call(e)?new l.StringEntity(e.toString()):e instanceof File?new l.FileEntity(e):e instanceof ArrayBuffer||e instanceof Blob?(new l.EntityDefault).dataSet(e):new l.StringEntity(e.toString()):new l.EntityDefault}static newSimpleListener(){return new h.SimpleListener}static newEventListener(e){return new h.EventListener(e)}static newPathListener(e){return new h.PathListener(e)}static newPipelineListener(){return new h.PipelineListener}}t.SocketD=c,n=c,c.EntityMetas=u.EntityMetas,c.clientProviderMap=new Map,(()=>{const e=new o.WsClientProvider;for(const t of e.schemas())n.clientProviderMap.set(t,e);"undefined"!=typeof window&&(window.SocketD=n)})()},243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(270),i=s(704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}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*(){const e=new Array;for(const t of this._serverUrls)for(let s of t.split(",")){if(s=s.trim(),!s)continue;const t=i.SocketD.createClient(s);null!=this._listener&&t.listen(this._listener),null!=this._configHandler&&t.config(this._configHandler),null!=this._heartbeatHandler&&t.heartbeatHandler(this._heartbeatHandler);const n=yield t.open();e.push(n)}return new r.ClusterClientSession(e)}))}}},270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(404),r=s(921),i=s(422);t.ClusterClientSession=class{constructor(e){this._sessionSet=e,this._sessionId=n.StrUtils.guid(),this._sessionRoundCounter=0}getSessionAll(){return this._sessionSet}getSessionOne(){if(0==this._sessionSet.length)throw new r.SocketdException("No session!");if(1==this._sessionSet.length)return this._sessionSet[0];{const e=new Array;for(const t of this._sessionSet)t.isValid()&&e.push(t);if(0==e.length)throw new r.SocketdException("No session is available!");if(1==e.length)return e[0];const t=this._sessionRoundCounter++,s=t%e.length;return t>999999999&&(this._sessionRoundCounter=0),e[s]}}isValid(){for(const e of this._sessionSet)if(e.isValid())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.getSessionOne().send(e,t)}sendAndRequest(e,t,s){return this.getSessionOne().sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionOne().sendAndSubscribe(e,t,s)}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close)}}},921:(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._from=e}getFrom(){return this._from}},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)}}},421:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const r=s(405),i=s(213),a=s(39);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new r.ProcessorDefault}getAssistant(){return this._assistant}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}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 n(this,void 0,void 0,(function*(){const e=this.createConnector(),t=yield e.connect(),s=new i.ClientChannel(t,e);s.setHandshake(t.getHandshake());const n=new a.SessionDefault(s);return t.setSession(n),console.info("Socket.D client successfully connected!"),n}))}}},213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(998),i=s(569),a=s(797),o=s(911),l=s(921),h=s(422);class u extends r.ChannelBase{constructor(e,t){super(e.getConfig()),this._connector=t,this._real=e,null==t.heartbeatHandler()?this._heartbeatHandler=new i.HeartbeatHandlerDefault(null):this._heartbeatHandler=new i.HeartbeatHandlerDefault(t.heartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>{try{this.heartbeatHandle()}catch(e){console.warn("Client channel heartbeat error",e)}}),this._connector.heartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(null!=this._real){if(null==this._real.getHandshake())return;if(this._real.isClosed()==a.Constants.CLOSE4_USER)return void console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`)}try{yield this.prepareCheck(),this._heartbeatHandler.heartbeat(this.getSession())}catch(e){if(e instanceof l.SocketdException)throw e;throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),new l.SocketdChannelException(e)}}))}prepareCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(this._real=yield this._connector.connect(),!0)}))}isValid(){return null!=this._real&&this._real.isValid()}isClosed(){return null==this._real?0:this._real.isClosed()}send(e,t){return n(this,void 0,void 0,(function*(){o.Asserts.assertClosedByUser(this._real);try{yield this.prepareCheck(),this._real.send(e,t)}catch(e){throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),e}}))}retrieve(e,t){this._real.retrieve(e,t)}reconnect(){this.initHeartbeat(),this.prepareCheck()}onError(e){this._real.onError(e)}close(e){h.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),h.RunUtils.runAndTry((()=>this._connector.close())),this._real&&h.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._real.getSession()}}t.ClientChannel=u},545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(628),r=s(404);class i extends n.ConfigBase{constructor(e){super(!0),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let t=r.StrUtils.parseUri(e);this._port=parseInt(t.port),this._schema=t.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getUrl(){return this._url}getLinkUrl(){return this._linkUrl}getHost(){return this._host}getPort(){return this._port}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._schema+"', charset="+this._charset+", url='"+this._url+"', 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},511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}heartbeatHandler(){return this._client.getHeartbeatHandler()}heartbeatInterval(){return this._client.getHeartbeatInterval()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},777:(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}}},911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(797),r=s(921);t.Asserts=class{static assertClosed(e){if(null!=e&&e.isClosed()>0)throw new r.SocketdChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertClosedByUser(e){if(null!=e&&e.isClosed()==n.Constants.CLOSE4_USER)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)}}}},560:(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,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}}},998:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(954);t.ChannelBase=class{constructor(e){this._isClosed=0,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)}isClosed(){return this._isClosed}close(e){this._isClosed=e,this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e){this.send(n.Frames.connectFrame(this.getConfig().getIdGenerator().generate(),e),null)}sendConnack(e){this.send(n.Frames.connackFrame(e),null)}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}sendClose(){this.send(n.Frames.closeFrame(),null)}sendAlarm(e,t){this.send(n.Frames.alarmFrame(e,t),null)}}},930:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(954),r=s(862),i=s(797),a=s(998),o=s(39);class l extends a.ChannelBase{constructor(e,t){super(t.getConfig()),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.isClosed()&&this._assistant.isValid(this._source)}config(){return this._config}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}send(e,t){if(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(i.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._assistant.write(this._source,i)}))}this._assistant.write(this._source,e),null!=t&&t.onProgress(!0,1,1)}retrieve(e,t){t?((t.demands(){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}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.CodecByteBuffer=void 0;const n=s(954),r=s(404),i=s(911),a=s(797),o=s(862),l=s(165);t.CodecByteBuffer=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()),o=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+o.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,a.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,a.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",o.byteLength,a.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),a.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(o),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(a.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),h=this.decodeString(e,i,a.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,a.Constants.MAX_SIZE_EVENT),c=this.decodeString(e,i,a.Constants.MAX_SIZE_META_STRING),d=t-e.position();let _;if(d>a.Constants.MAX_SIZE_DATA){_=new ArrayBuffer(a.Constants.MAX_SIZE_DATA),e.getBytes(_,0,a.Constants.MAX_SIZE_DATA);for(let t=d-a.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else _=new ArrayBuffer(d),d>0&&e.getBytes(_,0,d);const g=(new o.MessageBuilder).flag(a.Flags.of(s)).sid(h).event(u).entity((new l.EntityDefault).dataSet(_).metaStringSet(c)).build();return new n.Frame(g.flag(),g)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(10==t)break;s>0&&s<=i||0!=t&&(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},628:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(895),r=s(67),i=s(351),a=s(797),o=s(911),l=s(905);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new n.StreamMangerDefault(this),this._codec=new l.CodecByteBuffer(this),this._charset="utf-8",this._idGenerator=new r.GuidGenerator,this._fragmentHandler=new i.FragmentHandlerDefault,this._fragmentSize=a.Constants.MAX_SIZE_DATA,this._coreThreads=2,this._maxThreads=4*this._coreThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=0,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}getIdGenerator(){return this._idGenerator}idGenerator(e){return o.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return o.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>a.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=t.Flags=t.Constants=void 0;const n=s(560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1_PROTOCOL:1,CLOSE2_PROTOCOL_ILLEGAL:2,CLOSE3_ERROR:3,CLOSE4_USER:4,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2},t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,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 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.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"}}},t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",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"}},165:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=t.StringEntity=t.EntityDefault=void 0;const n=s(404),r=s(608),i=s(797),a=s(560),o=s(921);class l{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(){return this.meta("@")}range(e,t){return this.metaPut(i.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(i.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 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 this.metaMap().set(e,t),this}metaString(){return this.metaMap().toString()}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"))}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}putMeta(e,t){this.metaPut(e,t)}dataSet(e){return e instanceof ArrayBuffer?this._data=new a.ByteBuffer(e):this._data=new a.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new o.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 o.SocketdException("Blob does not support dataAsString");return n.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}t.EntityDefault=l,t.StringEntity=class extends l{constructor(e){super();const t=n.StrUtils.strToBuf(e);this.dataSet(t)}},t.FileEntity=class extends l{constructor(e){super(),this.dataSet(e),this.metaPut(i.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}},187:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(862),r=s(165),i=s(954),a=s(72),o=s(797),l=s(921);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(o.EntityMetas.META_DATA_LENGTH);if(!t)throw new l.SocketdCodecException("Missing '"+o.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 a.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(165),r=s(797),i=s(187);t.FragmentHandlerDefault=class{spliFragment(e,t,s,r){if(s.dataSize()>e.getConfig().getFragmentSize()){let n=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(n,i,e,t,s,r)}else null==s.data().getBlob()?(r(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{r((new n.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,i,a,o){e++,a.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new n.EntityDefault).dataSet(l);1==e&&h.metaMapPut(a.metaMap()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),o(h),null!=i&&i.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,i,a,o)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new i.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}}},72:(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}}},954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=t.Frame=void 0;const n=s(165),r=s(797),i=s(862),a=s(704);class o{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+r.Flags.name(this._flag)+", message="+this._message+"}"}}t.Frame=o,t.Frames=class{static connectFrame(e,t){const s=new n.StringEntity(t);return s.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),new o(r.Flags.Connect,(new i.MessageBuilder).sid(e).event(t).entity(s).build())}static connackFrame(e){const t=new n.EntityDefault;return t.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),t.dataSet(e.data().getArray()),new o(r.Flags.Connack,(new i.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build())}static pingFrame(){return new o(r.Flags.Ping,null)}static pongFrame(){return new o(r.Flags.Pong,null)}static closeFrame(){return new o(r.Flags.Close,null)}static alarmFrame(e,t){const s=new i.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new n.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new n.StringEntity(t)),new o(r.Flags.Alarm,s.build())}}},953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(797),r=s(404);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._paramMap=new Map;let s=r.StrUtils.parseUri(t);this._path=s.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))}}getSource(){return this._source}param(e){return this._paramMap.get(e)}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}uri(){return this._url}path(){return this._path}version(){return this._version}}},569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HeartbeatHandlerDefault=void 0,t.HeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}heartbeat(e){null==this._heartbeatHandler?e.sendPing():this._heartbeatHandler(e)}}},67:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},852:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=t.PathListener=t.EventListener=t.SimpleListener=void 0;const n=s(789);t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onClose(e){}onError(e,t){}},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)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}},t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}of(e,t){return this._pathRouteSelector.put(e,t),this}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)}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)}},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)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(797);t.MessageBuilder=class{constructor(){this._flag=n.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 r(this._flag,this._sid,this._event,this._entity)}};class r{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}at(){return this._entity.at()}rangeStart(){return this.metaAsInt(n.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(n.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==n.Flags.Request}isSubscribe(){return this._flag==n.Flags.Subscribe}isEnd(){return this._flag==n.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)}metaAsFloat(e){return this._entity.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}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=r},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(852),r=s(797),i=s(921),a=s(953);t.ProcessorDefault=class{constructor(){this._listener=new n.SimpleListener}setListener(e){null!=e&&(this._listener=e)}onReceive(e,t){if(t.flag()==r.Flags.Connect)e.setHandshake(new a.HandshakeDefault(t.message())),e.onOpenFuture(((s,n)=>{if(s&&e.isValid())try{e.sendConnack(t.message())}catch(n){this.onError(e,n)}})),this.onOpen(e);else if(t.flag()==r.Flags.Connack)e.setHandshake(new a.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(r.Constants.CLOSE1_PROTOCOL),t.flag()==r.Flags.Close)throw new i.SocketdConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}try{switch(t.flag()){case r.Flags.Ping:e.sendPong();break;case r.Flags.Pong:break;case r.Flags.Close:e.close(r.Constants.CLOSE1_PROTOCOL),this.onCloseInternal(e);break;case r.Flags.Alarm:{const s=new i.SocketdAlarmException(t.message()),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 r.Flags.Message:case r.Flags.Request:case r.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case r.Flags.Reply:case r.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:e.close(r.Constants.CLOSE2_PROTOCOL_ILLEGAL),this.onCloseInternal(e)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,i=1,a=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(r.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){i=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,i,t.message());if(n&&(a=parseInt(t.message().metaOrDefault(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,i,a));t=o}}s?(n&&n.onProgress(!1,i,a),e.retrieve(t,n)):this.onMessage(e,t.message())}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)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onClose(e){0==e.isClosed()&&this.onCloseInternal(e)}onCloseInternal(e){this._listener.onClose(e.getSession())}onError(e,t){this._listener.onError(e.getSession(),t)}}},789:(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}}},305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._sessionId=this.generateId()}sessionId(){return this._sessionId}name(){return this.param("@")}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)}generateId(){return this._channel.getConfig().getIdGenerator().generate()}}},39:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(305),r=s(862),i=s(954),a=s(797),o=s(895);class l extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}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){const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new o.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getRequestTimeout());const l=new o.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),l),l}sendAndSubscribe(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getStreamTimeout());const l=new o.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),l),l}reply(e,t){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){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)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose()}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(a.Constants.CLOSE4_USER)}}t.SessionDefault=l},895:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=t.SubscribeStreamImpl=t.RequestStreamImpl=t.SendStreamImpl=t.StreamBase=void 0;const n=s(921),r=s(911),i=s(797);class a{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}}t.StreamBase=a,t.SendStreamImpl=class extends a{constructor(e){super(e,i.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}},t.RequestStreamImpl=class extends a{constructor(e,t){super(e,i.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.SubscribeStreamImpl=class extends a{constructor(e,t){super(e,i.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.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(r.Asserts.assertNull("stream",t),t.demands()==i.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}`))}}},174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(608);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){throw new Error("Method not implemented.")}getLocalAddress(e){throw new Error("Method not implemented.")}}},976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(421),r=s(174),i=s(882);class a extends n.ClientBase{constructor(e){super(e,new r.WsChannelAssistant(e))}createConnector(){return new i.WsClientConnector(this)}}t.WsClient=a},882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(511),r=s(777),i=s(171),a=s(930),o=s(797),l=s(921);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{this._real=new u(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class u{constructor(e,t,s){this._real=i.EnvBridge.createSdWebSocketClient(e,this),this._client=t,this._channel=new a.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl())}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()==o.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{null==t?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,null)):this._handshakeFuture(new r.ClientHandshakeResult(this._channel,t))})),this._client.getProcessor().onReceive(this._channel,t))}catch(e){e instanceof l.SocketdConnectionException&&this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this._client.getProcessor().onError(this._channel,e)}close(){this._real.close()}}t.WebSocketClientImpl=u},481:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClientProvider=void 0;const n=s(976);t.WsClientProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}}},171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(14),r=s(769),i=s(73),a=s(865);var o;!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"}(o||(t.Runtime=o={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:window.navigator.userAgent.toLowerCase().indexOf("MicroMessenger")<0?o.Browser:o.Weixin:"undefined"!=typeof process&&process.versions&&process.versions.node?o.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:o.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==o.Weixin?(console.info("Client channel use xeixin api!"),new a.SdWebSocketWeixinImpl(e,t)):s==o.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappImpl(e,t)):s==o.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsImpl(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserImpl(e,t))}}},874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),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{},t.SdWebSocketMessageEventImpl=class{constructor(e){this._data=e}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{}},14:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserImpl=void 0;const n=s(874);t.SdWebSocketBrowserImpl=class{constructor(e,t){this._real=new WebSocket(e),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)}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._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},769: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.SdWebSocketNodeJsImpl=void 0;const r=s(874),i=n(s(241));t.SdWebSocketNodeJsImpl=class{constructor(e,t){this._real=new i.default(e),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))}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._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl;this._listener.onClose(e)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},73:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappImpl=void 0;const n=s(874);t.SdWebSocketUniappImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},865:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinImpl=void 0;const n=s(874);t.SdWebSocketWeixinImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e}),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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},404:(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=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){t||(t="utf-8");var s=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(s).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}(704),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={704:(e,t,s)=>{var n;Object.defineProperty(t,"__esModule",{value:!0}),t.SocketD=void 0;const r=s(911),i=s(545),a=s(243),o=s(481),l=s(165),h=s(852),u=s(797);class c{static version(){return"2.3.3"}static protocolVersion(){return"1.0"}static createClient(e){const t=this.createClientOrNull(e);if(null==t)throw new Error("No socketd client providers were found.");return t}static createClientOrNull(e){r.Asserts.assertNull("serverUrl",e);const t=e.indexOf("://");if(t<2)throw new Error("The serverUrl invalid: "+e);const s=e.substring(0,t),n=this.clientProviderMap.get(s);if(null==n)return null;{const t=new i.ClientConfig(e);return n.createClient(t)}}static createClusterClient(e){return new a.ClusterClient(e)}static newEntity(e){return e?"[object String]"===toString.call(e)?new l.StringEntity(e.toString()):e instanceof File?new l.FileEntity(e):e instanceof ArrayBuffer||e instanceof Blob?(new l.EntityDefault).dataSet(e):new l.StringEntity(e.toString()):new l.EntityDefault}static newSimpleListener(){return new h.SimpleListener}static newEventListener(e){return new h.EventListener(e)}static newPathListener(e){return new h.PathListener(e)}static newPipelineListener(){return new h.PipelineListener}}t.SocketD=c,n=c,c.EntityMetas=u.EntityMetas,c.clientProviderMap=new Map,(()=>{const e=new o.WsClientProvider;for(const t of e.schemas())n.clientProviderMap.set(t,e);"undefined"!=typeof window&&(window.SocketD=n)})()},243:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClient=void 0;const r=s(270),i=s(704);t.ClusterClient=class{constructor(e){this._serverUrls=e instanceof Array?e:[e]}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*(){const e=new Array;for(const t of this._serverUrls)for(let s of t.split(",")){if(s=s.trim(),!s)continue;const t=i.SocketD.createClient(s);null!=this._listener&&t.listen(this._listener),null!=this._configHandler&&t.config(this._configHandler),null!=this._heartbeatHandler&&t.heartbeatHandler(this._heartbeatHandler);const n=yield t.open();e.push(n)}return new r.ClusterClientSession(e)}))}}},270:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClusterClientSession=void 0;const n=s(404),r=s(921),i=s(422);t.ClusterClientSession=class{constructor(e){this._sessionSet=e,this._sessionId=n.StrUtils.guid(),this._sessionRoundCounter=0}getSessionAll(){return this._sessionSet}getSessionOne(){if(0==this._sessionSet.length)throw new r.SocketdException("No session!");if(1==this._sessionSet.length)return this._sessionSet[0];{const e=new Array;for(const t of this._sessionSet)t.isValid()&&e.push(t);if(0==e.length)throw new r.SocketdException("No session is available!");if(1==e.length)return e[0];const t=this._sessionRoundCounter++,s=t%e.length;return t>999999999&&(this._sessionRoundCounter=0),e[s]}}isValid(){for(const e of this._sessionSet)if(e.isValid())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.getSessionOne().send(e,t)}sendAndRequest(e,t,s){return this.getSessionOne().sendAndRequest(e,t,s)}sendAndSubscribe(e,t,s){return this.getSessionOne().sendAndSubscribe(e,t,s)}close(){for(const e of this._sessionSet)i.RunUtils.runAndTry(e.close)}}},921:(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._from=e}getFrom(){return this._from}},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)}}},421:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientBase=void 0;const r=s(405),i=s(213),a=s(39);t.ClientBase=class{constructor(e,t){this._config=e,this._assistant=t,this._processor=new r.ProcessorDefault}getAssistant(){return this._assistant}getHeartbeatHandler(){return this._heartbeatHandler}getHeartbeatInterval(){return this.getConfig().getHeartbeatInterval()}getConfig(){return this._config}getProcessor(){return this._processor}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 n(this,void 0,void 0,(function*(){const e=this.createConnector(),t=yield e.connect(),s=new i.ClientChannel(t,e);s.setHandshake(t.getHandshake());const n=new a.SessionDefault(s);return t.setSession(n),console.info("Socket.D client successfully connected!"),n}))}}},213:function(e,t,s){var n=this&&this.__awaiter||function(e,t,s,n){return new(s||(s=Promise))((function(r,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function o(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(a,o)}l((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.ClientChannel=void 0;const r=s(998),i=s(569),a=s(797),o=s(911),l=s(921),h=s(422);class u extends r.ChannelBase{constructor(e,t){super(e.getConfig()),this._connector=t,this._real=e,null==t.heartbeatHandler()?this._heartbeatHandler=new i.HeartbeatHandlerDefault(null):this._heartbeatHandler=new i.HeartbeatHandlerDefault(t.heartbeatHandler()),this.initHeartbeat()}initHeartbeat(){this._heartbeatScheduledFuture&&clearInterval(this._heartbeatScheduledFuture),this._connector.autoReconnect()&&(this._heartbeatScheduledFuture=setInterval((()=>{try{this.heartbeatHandle()}catch(e){console.warn("Client channel heartbeat error",e)}}),this._connector.heartbeatInterval()))}heartbeatHandle(){return n(this,void 0,void 0,(function*(){if(null!=this._real){if(null==this._real.getHandshake())return;if(this._real.isClosed()==a.Constants.CLOSE4_USER)return void console.debug(`Client channel is closed (pause heartbeat), sessionId=${this.getSession().sessionId()}`)}try{yield this.prepareCheck(),this._heartbeatHandler.heartbeat(this.getSession())}catch(e){if(e instanceof l.SocketdException)throw e;throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),new l.SocketdChannelException(e)}}))}prepareCheck(){return n(this,void 0,void 0,(function*(){return(null==this._real||0==this._real.isValid())&&(this._real=yield this._connector.connect(),!0)}))}isValid(){return null!=this._real&&this._real.isValid()}isClosed(){return null==this._real?0:this._real.isClosed()}send(e,t){return n(this,void 0,void 0,(function*(){o.Asserts.assertClosedByUser(this._real);try{yield this.prepareCheck(),this._real.send(e,t)}catch(e){throw this._connector.autoReconnect()&&(this._real.close(a.Constants.CLOSE3_ERROR),this._real=null),e}}))}retrieve(e,t){this._real.retrieve(e,t)}reconnect(){this.initHeartbeat(),this.prepareCheck()}onError(e){this._real.onError(e)}close(e){h.RunUtils.runAndTry((()=>clearInterval(this._heartbeatScheduledFuture))),h.RunUtils.runAndTry((()=>this._connector.close())),this._real&&h.RunUtils.runAndTry((()=>this._real.close(e))),super.close(e)}getSession(){return this._real.getSession()}}t.ClientChannel=u},545:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConfig=void 0;const n=s(628),r=s(404);class i extends n.ConfigBase{constructor(e){super(!0),e.startsWith("sd:")&&(e=e.substring(3)),this._url=e,this._linkUrl="sd:"+e;let t=r.StrUtils.parseUri(e);this._port=parseInt(t.port),this._schema=t.protocol,this._port<0&&(this._port=8602),this._connectTimeout=1e4,this._heartbeatInterval=2e4,this._autoReconnect=!0}getSchema(){return this._schema}getUrl(){return this._url}getLinkUrl(){return this._linkUrl}getHost(){return this._host}getPort(){return this._port}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._schema+"', charset="+this._charset+", url='"+this._url+"', 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},511:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ClientConnectorBase=void 0,t.ClientConnectorBase=class{constructor(e){this._client=e}heartbeatHandler(){return this._client.getHeartbeatHandler()}heartbeatInterval(){return this._client.getHeartbeatInterval()}autoReconnect(){return this._client.getConfig().isAutoReconnect()}}},777:(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}}},911:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Asserts=void 0;const n=s(797),r=s(921);t.Asserts=class{static assertClosed(e){if(null!=e&&e.isClosed()>0)throw new r.SocketdChannelException("This channel is closed, sessionId="+e.getSession().sessionId())}static assertClosedByUser(e){if(null!=e&&e.isClosed()==n.Constants.CLOSE4_USER)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)}}}},560:(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,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}}},998:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelBase=void 0;const n=s(954);t.ChannelBase=class{constructor(e){this._isClosed=0,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)}isClosed(){return this._isClosed}close(e){this._isClosed=e,this._attachments.clear()}getConfig(){return this._config}setHandshake(e){this._handshake=e}getHandshake(){return this._handshake}sendConnect(e){this.send(n.Frames.connectFrame(this.getConfig().getIdGenerator().generate(),e),null)}sendConnack(e){this.send(n.Frames.connackFrame(e),null)}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}sendClose(){this.send(n.Frames.closeFrame(),null)}sendAlarm(e,t){this.send(n.Frames.alarmFrame(e,t),null)}}},930:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ChannelDefault=void 0;const n=s(954),r=s(862),i=s(797),a=s(998),o=s(39);class l extends a.ChannelBase{constructor(e,t){super(t.getConfig()),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.isClosed()&&this._assistant.isValid(this._source)}config(){return this._config}sendPing(){this.send(n.Frames.pingFrame(),null)}sendPong(){this.send(n.Frames.pongFrame(),null)}send(e,t){if(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(i.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._assistant.write(this._source,i)}))}this._assistant.write(this._source,e),null!=t&&t.onProgress(!0,1,1)}retrieve(e,t){t?((t.demands(){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}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.CodecByteBuffer=void 0;const n=s(954),r=s(404),i=s(911),a=s(797),o=s(862),l=s(165);t.CodecByteBuffer=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()),o=r.StrUtils.strToBuf(e.message().metaString(),this._config.getCharset()),l=8+s.byteLength+n.byteLength+o.byteLength+e.message().dataSize()+6;i.Asserts.assertSize("sid",s.byteLength,a.Constants.MAX_SIZE_SID),i.Asserts.assertSize("event",n.byteLength,a.Constants.MAX_SIZE_EVENT),i.Asserts.assertSize("metaString",o.byteLength,a.Constants.MAX_SIZE_META_STRING),i.Asserts.assertSize("data",e.message().dataSize(),a.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(o),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(a.Constants.MAX_SIZE_META_STRING,e.remaining()),i=new ArrayBuffer(r),h=this.decodeString(e,i,a.Constants.MAX_SIZE_SID),u=this.decodeString(e,i,a.Constants.MAX_SIZE_EVENT),c=this.decodeString(e,i,a.Constants.MAX_SIZE_META_STRING),d=t-e.position();let _;if(d>a.Constants.MAX_SIZE_DATA){_=new ArrayBuffer(a.Constants.MAX_SIZE_DATA),e.getBytes(_,0,a.Constants.MAX_SIZE_DATA);for(let t=d-a.Constants.MAX_SIZE_DATA;t>0;t--)e.getByte()}else _=new ArrayBuffer(d),d>0&&e.getBytes(_,0,d);const g=(new o.MessageBuilder).flag(a.Flags.of(s)).sid(h).event(u).entity((new l.EntityDefault).dataSet(_).metaStringSet(c)).build();return new n.Frame(g.flag(),g)}}decodeString(e,t,s){const n=new DataView(t);let i=0;for(;;){const t=e.getByte();if(10==t)break;s>0&&s<=i||0!=t&&(n.setInt8(i,t),i++)}return i<1?"":r.StrUtils.bufToStr(t,0,i,this._config.getCharset())}}},628:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigBase=void 0;const n=s(895),r=s(67),i=s(351),a=s(797),o=s(911),l=s(905);t.ConfigBase=class{constructor(e){this._clientMode=e,this._streamManger=new n.StreamMangerDefault(this),this._codec=new l.CodecByteBuffer(this),this._charset="utf-8",this._idGenerator=new r.GuidGenerator,this._fragmentHandler=new i.FragmentHandlerDefault,this._fragmentSize=a.Constants.MAX_SIZE_DATA,this._coreThreads=2,this._maxThreads=4*this._coreThreads,this._readBufferSize=512,this._writeBufferSize=512,this._idleTimeout=0,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}getIdGenerator(){return this._idGenerator}idGenerator(e){return o.Asserts.assertNull("idGenerator",e),this._idGenerator=e,this}getFragmentHandler(){return this._fragmentHandler}fragmentHandler(e){return o.Asserts.assertNull("fragmentHandler",e),this._fragmentHandler=e,this}getFragmentSize(){return this._fragmentSize}fragmentSize(e){if(e>a.Constants.MAX_SIZE_DATA)throw new Error("The parameter fragmentSize cannot > 16m");if(e{Object.defineProperty(t,"__esModule",{value:!0}),t.EntityMetas=t.Flags=t.Constants=void 0;const n=s(560);t.Constants={DEF_SID:"",DEF_EVENT:"",DEF_META_STRING:"",DEF_DATA:new n.ByteBuffer(new ArrayBuffer(0)),CLOSE1_PROTOCOL:1,CLOSE2_PROTOCOL_ILLEGAL:2,CLOSE3_ERROR:3,CLOSE4_USER:4,MAX_SIZE_SID:64,MAX_SIZE_EVENT:512,MAX_SIZE_META_STRING:4096,MAX_SIZE_DATA:16777216,MIN_FRAGMENT_SIZE:1024,DEMANDS_ZERO:0,DEMANDS_SIGNLE:1,DEMANDS_MULTIPLE:2},t.Flags={Unknown:0,Connect:10,Connack:11,Ping:20,Pong:21,Close:30,Alarm:31,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 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.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"}}},t.EntityMetas={META_SOCKETD_VERSION:"Socket.D",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"}},165:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FileEntity=t.StringEntity=t.EntityDefault=void 0;const n=s(404),r=s(608),i=s(797),a=s(560),o=s(921);class l{constructor(){this._metaMap=null,this._data=i.Constants.DEF_DATA,this._dataAsReader=null}at(){return this.meta("@")}range(e,t){return this.metaPut(i.EntityMetas.META_RANGE_START,e.toString()),this.metaPut(i.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 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 this.metaMap().set(e,t),this}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"))}metaAsFloat(e){return parseFloat(this.metaOrDefault(e,"0"))}putMeta(e,t){this.metaPut(e,t)}dataSet(e){return e instanceof ArrayBuffer?this._data=new a.ByteBuffer(e):this._data=new a.BlobBuffer(e),this}data(){return this._data}dataAsReader(){if(null==this._data.getArray())throw new o.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 o.SocketdException("Blob does not support dataAsString");return n.StrUtils.bufToStrDo(this._data.getArray(),"")}dataSize(){return this._data.size()}release(){}toString(){return"Entity{meta='"+this.metaString()+"', data=byte["+this.dataSize()+"]}"}}t.EntityDefault=l,t.StringEntity=class extends l{constructor(e){super();const t=n.StrUtils.strToBuf(e);this.dataSet(t)}},t.FileEntity=class extends l{constructor(e){super(),this.dataSet(e),this.metaPut(i.EntityMetas.META_DATA_DISPOSITION_FILENAME,e.name)}}},187:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FragmentAggregatorDefault=void 0;const n=s(862),r=s(165),i=s(954),a=s(72),o=s(797),l=s(921);t.FragmentAggregatorDefault=class{constructor(e){this._fragmentHolders=new Array,this._dataStreamSize=0,this._dataLength=0,this._main=e;const t=e.meta(o.EntityMetas.META_DATA_LENGTH);if(!t)throw new l.SocketdCodecException("Missing '"+o.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 a.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(165),r=s(797),i=s(187);t.FragmentHandlerDefault=class{spliFragment(e,t,s,r){if(s.dataSize()>e.getConfig().getFragmentSize()){let n=0,i=Math.ceil(s.dataSize()/e.getConfig().getFragmentSize());this.spliFragmentDo(n,i,e,t,s,r)}else null==s.data().getBlob()?(r(s),null!=t&&t.onProgress(!0,1,1)):s.data().getBytes(e.getConfig().getFragmentSize(),(e=>{r((new n.EntityDefault).dataSet(e).metaMapPut(s.metaMap())),null!=t&&t.onProgress(!0,1,1)}))}spliFragmentDo(e,t,s,i,a,o){e++,a.data().getBytes(s.getConfig().getFragmentSize(),(l=>{const h=(new n.EntityDefault).dataSet(l);1==e&&h.metaMapPut(a.metaMap()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_IDX,e.toString()),h.metaPut(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,t.toString()),o(h),null!=i&&i.onProgress(!0,e,t),this.spliFragmentDo(e,t,s,i,a,o)}))}aggrFragment(e,t,s){let n=e.getAttachment(s.sid());return n||(n=new i.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}}},72:(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}}},954:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Frames=t.Frame=void 0;const n=s(165),r=s(797),i=s(862),a=s(704);class o{constructor(e,t){this._flag=e,this._message=t}flag(){return this._flag}message(){return this._message}toString(){return"Frame{flag="+r.Flags.name(this._flag)+", message="+this._message+"}"}}t.Frame=o,t.Frames=class{static connectFrame(e,t){const s=new n.StringEntity(t);return s.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),new o(r.Flags.Connect,(new i.MessageBuilder).sid(e).event(t).entity(s).build())}static connackFrame(e){const t=new n.EntityDefault;return t.metaPut(r.EntityMetas.META_SOCKETD_VERSION,a.SocketD.protocolVersion()),t.dataSet(e.data().getArray()),new o(r.Flags.Connack,(new i.MessageBuilder).sid(e.sid()).event(e.event()).entity(t).build())}static pingFrame(){return new o(r.Flags.Ping,null)}static pongFrame(){return new o(r.Flags.Pong,null)}static closeFrame(){return new o(r.Flags.Close,null)}static alarmFrame(e,t){const s=new i.MessageBuilder;return null!=e?(s.sid(e.sid()),s.event(e.event()),s.entity(new n.StringEntity(t).metaStringSet(e.metaString()))):s.entity(new n.StringEntity(t)),new o(r.Flags.Alarm,s.build())}}},953:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HandshakeDefault=void 0;const n=s(797),r=s(404);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._paramMap=new Map;let s=r.StrUtils.parseUri(t);this._path=s.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))}}getSource(){return this._source}param(e){return this._paramMap.get(e)}paramMap(){return this._paramMap}paramOrDefault(e,t){return this.param(e)||t}paramPut(e,t){this._paramMap.set(e,t)}uri(){return this._url}path(){return this._path}version(){return this._version}}},569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.HeartbeatHandlerDefault=void 0,t.HeartbeatHandlerDefault=class{constructor(e){this._heartbeatHandler=e}heartbeat(e){null==this._heartbeatHandler?e.sendPing():this._heartbeatHandler(e)}}},67:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GuidGenerator=void 0;const n=s(404);t.GuidGenerator=class{generate(){return n.StrUtils.guid()}}},852:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PipelineListener=t.PathListener=t.EventListener=t.SimpleListener=void 0;const n=s(789);t.SimpleListener=class{onOpen(e){}onMessage(e,t){}onClose(e){}onError(e,t){}},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)}onClose(e){this._doOnClose&&this._doOnClose(e)}onError(e,t){this._doOnError&&this._doOnError(e,t)}},t.PathListener=class{constructor(e){this._pathRouteSelector=e||new n.RouteSelectorDefault}of(e,t){return this._pathRouteSelector.put(e,t),this}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)}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)}},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)}onClose(e){for(const t of this._deque)t.onClose(e)}onError(e,t){for(const s of this._deque)s.onError(e,t)}}},862:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MessageDefault=t.MessageBuilder=void 0;const n=s(797);t.MessageBuilder=class{constructor(){this._flag=n.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 r(this._flag,this._sid,this._event,this._entity)}};class r{constructor(e,t,s,n){this._flag=e,this._sid=t,this._event=s,this._entity=n}at(){return this._entity.at()}rangeStart(){return this.metaAsInt(n.EntityMetas.META_RANGE_START)}rangeSize(){return this.metaAsInt(n.EntityMetas.META_RANGE_SIZE)}flag(){return this._flag}isRequest(){return this._flag==n.Flags.Request}isSubscribe(){return this._flag==n.Flags.Subscribe}isEnd(){return this._flag==n.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)}metaAsFloat(e){return this._entity.metaAsFloat(e)}putMeta(e,t){this._entity.putMeta(e,t)}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=r},405:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ProcessorDefault=void 0;const n=s(852),r=s(797),i=s(921),a=s(953);t.ProcessorDefault=class{constructor(){this._listener=new n.SimpleListener}setListener(e){null!=e&&(this._listener=e)}onReceive(e,t){if(t.flag()==r.Flags.Connect)e.setHandshake(new a.HandshakeDefault(t.message())),e.onOpenFuture(((s,n)=>{if(s&&e.isValid())try{e.sendConnack(t.message())}catch(n){this.onError(e,n)}})),this.onOpen(e);else if(t.flag()==r.Flags.Connack)e.setHandshake(new a.HandshakeDefault(t.message())),this.onOpen(e);else{if(null==e.getHandshake()){if(e.close(r.Constants.CLOSE1_PROTOCOL),t.flag()==r.Flags.Close)throw new i.SocketdConnectionException("Connection request was rejected");return void console.warn(`${e.getConfig().getRoleName()} channel handshake is null, sessionId=${e.getSession().sessionId()}`)}try{switch(t.flag()){case r.Flags.Ping:e.sendPong();break;case r.Flags.Pong:break;case r.Flags.Close:e.close(r.Constants.CLOSE1_PROTOCOL),this.onCloseInternal(e);break;case r.Flags.Alarm:{const s=new i.SocketdAlarmException(t.message()),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 r.Flags.Message:case r.Flags.Request:case r.Flags.Subscribe:this.onReceiveDo(e,t,!1);break;case r.Flags.Reply:case r.Flags.ReplyEnd:this.onReceiveDo(e,t,!0);break;default:e.close(r.Constants.CLOSE2_PROTOCOL_ILLEGAL),this.onCloseInternal(e)}}catch(t){this.onError(e,t)}}}onReceiveDo(e,t,s){let n=null,i=1,a=1;if(s&&(n=e.getStream(t.message().sid())),e.getConfig().getFragmentHandler().aggrEnable()){const s=t.message().meta(r.EntityMetas.META_DATA_FRAGMENT_IDX);if(s){i=parseInt(s);const o=e.getConfig().getFragmentHandler().aggrFragment(e,i,t.message());if(n&&(a=parseInt(t.message().metaOrDefault(r.EntityMetas.META_DATA_FRAGMENT_TOTAL,"1"))),null==o)return void(n&&n.onProgress(!1,i,a));t=o}}s?(n&&n.onProgress(!1,i,a),e.retrieve(t,n)):this.onMessage(e,t.message())}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)}catch(t){console.warn(`${e.getConfig().getRoleName()} channel listener onMessage error`,t),this.onError(e,t)}}onClose(e){0==e.isClosed()&&this.onCloseInternal(e)}onCloseInternal(e){this._listener.onClose(e.getSession())}onError(e,t){this._listener.onError(e.getSession(),t)}}},789:(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}}},305:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionBase=void 0,t.SessionBase=class{constructor(e){this._channel=e,this._sessionId=this.generateId()}sessionId(){return this._sessionId}name(){return this.param("@")}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)}generateId(){return this._channel.getConfig().getIdGenerator().generate()}}},39:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionDefault=void 0;const n=s(305),r=s(862),i=s(954),a=s(797),o=s(895);class l extends n.SessionBase{constructor(e){super(e)}isValid(){return this._channel.isValid()}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){const s=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build(),n=new o.SendStreamImpl(s.sid());return this._channel.send(new i.Frame(a.Flags.Message,s),n),n}sendAndRequest(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getRequestTimeout());const l=new o.RequestStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Request,n),l),l}sendAndSubscribe(e,t,s){const n=(new r.MessageBuilder).sid(this.generateId()).event(e).entity(t).build();s||(s=0),s<10&&(s=this._channel.getConfig().getStreamTimeout());const l=new o.SubscribeStreamImpl(n.sid(),s);return this._channel.send(new i.Frame(a.Flags.Subscribe,n),l),l}reply(e,t){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){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)}close(){if(console.debug(`${this._channel.getConfig().getRoleName()} session will be closed, sessionId=${this.sessionId()}`),this._channel.isValid())try{this._channel.sendClose()}catch(e){console.warn(`${this._channel.getConfig().getRoleName()} channel sendClose error`,e)}this._channel.close(a.Constants.CLOSE4_USER)}}t.SessionDefault=l},895:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.StreamMangerDefault=t.SubscribeStreamImpl=t.RequestStreamImpl=t.SendStreamImpl=t.StreamBase=void 0;const n=s(921),r=s(911),i=s(797);class a{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}}t.StreamBase=a,t.SendStreamImpl=class extends a{constructor(e){super(e,i.Constants.DEMANDS_ZERO,0)}isDone(){return!0}onReply(e){}},t.RequestStreamImpl=class extends a{constructor(e,t){super(e,i.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.SubscribeStreamImpl=class extends a{constructor(e,t){super(e,i.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.StreamMangerDefault=class{constructor(e){this._config=e,this._streamMap=new Map}getStream(e){return this._streamMap.get(e)||null}addStream(e,t){if(r.Asserts.assertNull("stream",t),t.demands()==i.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}`))}}},174:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsChannelAssistant=void 0;const n=s(608);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){throw new Error("Method not implemented.")}getLocalAddress(e){throw new Error("Method not implemented.")}}},976:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClient=void 0;const n=s(421),r=s(174),i=s(882);class a extends n.ClientBase{constructor(e){super(e,new r.WsChannelAssistant(e))}createConnector(){return new i.WsClientConnector(this)}}t.WsClient=a},882:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WebSocketClientImpl=t.WsClientConnector=void 0;const n=s(511),r=s(777),i=s(171),a=s(930),o=s(797),l=s(921);class h extends n.ClientConnectorBase{constructor(e){super(e)}connect(){this.close();let e=this._client.getConfig().getUrl();return new Promise(((t,s)=>{this._real=new u(e,this._client,(e=>{e.getThrowable()?s(e.getThrowable()):t(e.getChannel())}))}))}close(){this._real&&this._real.close()}}t.WsClientConnector=h;class u{constructor(e,t,s){this._real=i.EnvBridge.createSdWebSocketClient(e,this),this._client=t,this._channel=new a.ChannelDefault(this._real,t),this._handshakeFuture=s}onOpen(e){try{this._channel.sendConnect(this._client.getConfig().getUrl())}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()==o.Flags.Connack&&this._channel.onOpenFuture(((e,t)=>{null==t?this._handshakeFuture(new r.ClientHandshakeResult(this._channel,null)):this._handshakeFuture(new r.ClientHandshakeResult(this._channel,t))})),this._client.getProcessor().onReceive(this._channel,t))}catch(e){e instanceof l.SocketdConnectionException&&this._handshakeFuture(new r.ClientHandshakeResult(this._channel,e)),console.warn("WebSocket client onMessage error",e)}}onClose(e){this._client.getProcessor().onClose(this._channel)}onError(e){this._client.getProcessor().onError(this._channel,e)}close(){this._real.close()}}t.WebSocketClientImpl=u},481:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WsClientProvider=void 0;const n=s(976);t.WsClientProvider=class{schemas(){return["ws","wss","sd:ws","sd:wss"]}createClient(e){return new n.WsClient(e)}}},171:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EnvBridge=t.Runtime=void 0;const n=s(14),r=s(769),i=s(73),a=s(865);var o;!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"}(o||(t.Runtime=o={})),t.EnvBridge=class{static getRuntime(){return"undefined"!=typeof window?"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:window.navigator.userAgent.toLowerCase().indexOf("MicroMessenger")<0?o.Browser:o.Weixin:"undefined"!=typeof process&&process.versions&&process.versions.node?o.NodeJs:"undefined"!=typeof uni&&uni.connectSocket?o.Uniapp:o.Unknown}static createSdWebSocketClient(e,t){let s=this.getRuntime();return s==o.Weixin?(console.info("Client channel use xeixin api!"),new a.SdWebSocketWeixinImpl(e,t)):s==o.Uniapp?(console.info("Client channel use uniapp api!"),new i.SdWebSocketUniappImpl(e,t)):s==o.NodeJs?(console.info("Client channel use nodejs api"),new r.SdWebSocketNodeJsImpl(e,t)):(console.info("Client channel use browser api"),new n.SdWebSocketBrowserImpl(e,t))}}},874:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),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{},t.SdWebSocketMessageEventImpl=class{constructor(e){this._data=e}data(){return this._data}},t.SdWebSocketCloseEventImpl=class{}},14:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketBrowserImpl=void 0;const n=s(874);t.SdWebSocketBrowserImpl=class{constructor(e,t){this._real=new WebSocket(e),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)}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._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},769: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.SdWebSocketNodeJsImpl=void 0;const r=s(874),i=n(s(241));t.SdWebSocketNodeJsImpl=class{constructor(e,t){this._real=new i.default(e),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))}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._listener.onOpen(e)}onMessage(e){let t=new r.SdWebSocketMessageEventImpl(e);this._listener.onMessage(t)}onClose(){let e=new r.SdWebSocketCloseEventImpl;this._listener.onClose(e)}onError(e){this._listener.onError(e)}close(){this._real.close()}send(e){this._real.send(e)}}},73:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketUniappImpl=void 0;const n=s(874);t.SdWebSocketUniappImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=uni.connectSocket({url:e,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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},865:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SdWebSocketWeixinImpl=void 0;const n=s(874);t.SdWebSocketWeixinImpl=class{constructor(e,t){this._state=n.SdWebSocketState.CONNECTING,this._real=wx.connectSocket({url:e}),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))}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._state=n.SdWebSocketState.OPEN,this._listener.onOpen(t)}onMessage(e){let t=new n.SdWebSocketMessageEventImpl(e.data);this._listener.onMessage(t)}onClose(e){let t=new n.SdWebSocketCloseEventImpl;this._state=n.SdWebSocketState.CLOSED,this._listener.onClose(t)}onError(e){this._listener.onError(e)}close(){this._state=n.SdWebSocketState.CLOSING,this._real.close({complete:()=>{this._state=n.SdWebSocketState.CLOSED}})}send(e){this._real.send({data:e})}}},422:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.RunUtils=void 0,t.RunUtils=class{static runAndTry(e){try{e()}catch(e){}}}},404:(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=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){t||(t="utf-8");var s=unescape(encodeURIComponent(e)).split("").map((e=>e.charCodeAt(0)));return new Uint8Array(s).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}(704),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 b417a140..a2e3c05e 100644 --- a/javascript/socketd-examples/demo02-node-ws/package.json +++ b/javascript/socketd-examples/demo02-node-ws/package.json @@ -3,6 +3,6 @@ "description": "SocketD Node Test Project", "author": "aoshiguchen", "dependencies": { - "@noear/socket.d": "2.3.2" + "@noear/socket.d": "2.3.3" } } diff --git a/javascript/socketd-examples/demo03-uniapp-ws/manifest.json b/javascript/socketd-examples/demo03-uniapp-ws/manifest.json index 6c891572..c24c79e9 100644 --- a/javascript/socketd-examples/demo03-uniapp-ws/manifest.json +++ b/javascript/socketd-examples/demo03-uniapp-ws/manifest.json @@ -1,5 +1,5 @@ { - "name" : "test-socktd", + "name" : "demo03-uniapp-ws", "appid" : "", "description" : "", "versionName" : "1.0.0", diff --git a/javascript/socketd-examples/demo03-uniapp-ws/package-lock.json b/javascript/socketd-examples/demo03-uniapp-ws/package-lock.json deleted file mode 100644 index ffb6dd3d..00000000 --- a/javascript/socketd-examples/demo03-uniapp-ws/package-lock.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "requires": true, - "lockfileVersion": 1, - "dependencies": { - "@noear/socket.d": { - "version": "2.3.2-M2", - "resolved": "https://registry.npmjs.org/@noear/socket.d/-/socket.d-2.3.2-M2.tgz", - "integrity": "sha512-SG3jzK2y5LQYEVCbqR1t8nGHAr2s521FywiV3z95vtFQlS0z+Y2J8Kq9wy2EElDu5CSGEZegGm1gkwNoPfNRZg==", - "requires": { - "ws": "^8.16.0" - } - }, - "ws": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", - "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==" - } - } -} diff --git a/javascript/socketd-examples/demo03-uniapp-ws/package.json b/javascript/socketd-examples/demo03-uniapp-ws/package.json new file mode 100644 index 00000000..c1e79a7d --- /dev/null +++ b/javascript/socketd-examples/demo03-uniapp-ws/package.json @@ -0,0 +1,8 @@ +{ + "name": "demo03-uniapp-ws", + "description": "SocketD Uniapp Test Project", + "author": "ZhangQi", + "dependencies": { + "@noear/socket.d": "2.3.3" + } +} diff --git a/javascript/socketd-examples/demo03-uniapp-ws/pages/index/index.vue b/javascript/socketd-examples/demo03-uniapp-ws/pages/index/index.vue index e3f93655..c112accb 100644 --- a/javascript/socketd-examples/demo03-uniapp-ws/pages/index/index.vue +++ b/javascript/socketd-examples/demo03-uniapp-ws/pages/index/index.vue @@ -3,7 +3,7 @@ -

socket.d uniapp demo

+

socket.d js uniapp demo


@@ -44,7 +44,7 @@ - +
@@ -88,7 +88,7 @@ export default { .config((c) => c.fragmentSize(1024 * 1024)) .listen( SocketD.newEventListener().doOnMessage((s, m) => { - appendToMessageList('收到推送', m.dataAsString()); + this.appendToMessageList('收到推送', m.dataAsString()); }) ) .open(); @@ -160,8 +160,6 @@ export default { }); } else { this.open(() => { - debugger - this.openBtnText = '关闭'; this.isOpen = true; }); @@ -218,7 +216,7 @@ export default { } }, downloadFile() { - if (isOpen) { + if (this.isOpen) { this.appendToMessageList('下载文件', '...'); this.clientSession .sendAndRequest('/download', SocketD.newEntity()) @@ -254,7 +252,7 @@ export default { } }, uploadData() { - if (isOpen) { + if (this.isOpen) { const strSize = 1024 * 1024 * 10; let str = ''; while (str.length < strSize) { @@ -341,11 +339,9 @@ export default { .btn { /* width: 200upx; */ - width: 23%; - margin: 0 0.5%; - /* height: 200px; */ - /* background-color: red; */ - margin-bottom: 20px; + width: 46%; + margin: 0 2%; + margin-bottom: 10px; } .content { diff --git a/javascript/socketd/src/socketd/SocketD.ts b/javascript/socketd/src/socketd/SocketD.ts index 57fcb1aa..908609a5 100644 --- a/javascript/socketd/src/socketd/SocketD.ts +++ b/javascript/socketd/src/socketd/SocketD.ts @@ -35,7 +35,7 @@ export class SocketD { * 框架版本号 */ static version(): string { - return "2.3.2"; + return "2.3.3"; } /** diff --git a/javascript/socketd/src/socketd/transport/core/Entity.ts b/javascript/socketd/src/socketd/transport/core/Entity.ts index cd40633c..cc54c52f 100644 --- a/javascript/socketd/src/socketd/transport/core/Entity.ts +++ b/javascript/socketd/src/socketd/transport/core/Entity.ts @@ -184,7 +184,15 @@ export class EntityDefault implements Entity { * 获取元信息字符串(queryString style) */ metaString(): string { - return this.metaMap().toString(); + let str = ""; + this.metaMap().forEach((val, key,p) => { + str += `${key}=${val}&`; + }); + if (str.length > 0) { + return str.substring(0, str.length - 1); + } else { + return str; + } } /** diff --git a/javascript/socketd/webpack.md b/javascript/socketd/webpack.md index 96e6105f..0e28e058 100644 --- a/javascript/socketd/webpack.md +++ b/javascript/socketd/webpack.md @@ -33,4 +33,15 @@ cnpm i -D webpack-cli ``` npm publish +``` + + +```javascript + +/*! + * Socket.D v2.3.3 + * (c) 2023-2024 noear.org and other contributors + * Released under the Apache-2.0 License. + */ + ``` \ No newline at end of file