justrun-ws 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/WsClient.js CHANGED
@@ -1,54 +1,55 @@
1
1
  import { b } from './common/AdjustableTimer';
2
2
  import { CommonError } from './handler/common';
3
- import { j, n } from './handler/SimpleHandler';
4
- import { l } from './net/BrowserWsNet';
5
- import { o, p } from './net/hubPkgSerializer';
3
+ import { n, o } from './handler/SimpleHandler';
4
+ import { r } from './net/BrowserWsNet';
5
+ import { p, s } from './net/hubPkgSerializer';
6
6
  import { JsonRequest } from './net/JsonPackageWrapper';
7
7
  import { g } from './net/LazyConn';
8
- import { t } from './net/TypedPkgHub';
9
- class r extends JsonRequest {
8
+ import { NetErrorString } from './net/NetErrorString';
9
+ import { v } from './net/TypedPkgHub';
10
+ class l extends JsonRequest {
10
11
  }
11
12
  export const createNumPkgTypeClient = (getConnStr, timeoutMonitor) => {
12
13
  return new WsClient(getConnStr, {
13
14
  responsePkgType: 0,
14
- makePkgBuff: o,
15
- parsePkgBuff: p,
15
+ makePkgBuff: p,
16
+ parsePkgBuff: s,
16
17
  timeoutMonitor,
17
18
  });
18
19
  };
19
20
  export class WsClient {
20
21
  constructor(getConnStr, w) {
21
- const C = new l();
22
- const _ = this.f = new t(C, w);
22
+ const F = new r();
23
+ const _ = this.d = new v(F, w);
23
24
  this.h = '';
24
- this.k = [];
25
+ this.j = [];
25
26
  this.q = 0;
26
27
  this.a = new g(() => this.c());
27
- this.I = getConnStr;
28
+ this.H = getConnStr;
28
29
  this.O = this.c;
29
- _.F = this.F.bind(this);
30
- _.G = this.G.bind(this);
30
+ _.K = this.K.bind(this);
31
+ _.B = this.B.bind(this);
31
32
  }
32
33
  registerError(pkgType, wrapperCtor) {
33
- return this.f.registerError(pkgType, wrapperCtor);
34
+ return this.d.registerError(pkgType, wrapperCtor);
34
35
  }
35
36
  registerMessage(pkgType, wrapperCtor) {
36
- return this.f.registerMessage(pkgType, wrapperCtor);
37
+ return this.d.registerMessage(pkgType, wrapperCtor);
37
38
  }
38
39
  registerRequest(pkgType, wrapperCtor) {
39
- return this.f.registerRequest(pkgType, wrapperCtor);
40
+ return this.d.registerRequest(pkgType, wrapperCtor);
40
41
  }
41
42
  handleMessageWith(wrapperCtor, handler) {
42
- const i = (a, e) => {
43
- return handler(e.data);
43
+ const i = (a, f) => {
44
+ return handler(f.data);
44
45
  };
45
- this.f.handleMessageWith(new j(wrapperCtor, i, false));
46
+ this.d.handleMessageWith(new n(wrapperCtor, i, false));
46
47
  }
47
48
  handleRequestWith(wrapperCtor, handler) {
48
- const i = async (a, e) => {
49
- e.resp = await handler(e.data);
49
+ const i = async (a, f) => {
50
+ f.resp = await handler(f.data);
50
51
  };
51
- this.f.handleRequestWith(new n(wrapperCtor, i, false));
52
+ this.d.handleRequestWith(new o(wrapperCtor, i, false));
52
53
  }
53
54
  sendMessage(message) {
54
55
  return this.a.sendMessage(message);
@@ -63,21 +64,28 @@ export class WsClient {
63
64
  resetAuthState() {
64
65
  }
65
66
  enableAuthenticate(proxyAuthPkgType, authStatusCallback, allowAnonymous) {
66
- const { O, I, f, a } = this;
67
+ const { O, H, d, a } = this;
67
68
  if (this.c === O) {
68
- f.registerRequest(proxyAuthPkgType, r);
69
+ d.registerRequest(proxyAuthPkgType, l);
69
70
  let token = '';
70
71
  let shard = undefined;
71
72
  this.c = async () => {
72
73
  this.q = -1;
73
74
  if (this.m) {
74
- await this.m.a0();
75
+ await this.m.Y();
75
76
  }
76
77
  for (;;) {
77
- const d = I(shard);
78
- const conn = await f.c(d);
78
+ const e = H(shard);
79
+ let conn;
80
+ try {
81
+ conn = await d.c(e);
82
+ }
83
+ catch {
84
+ this.B(d, this.a, true, new Error(NetErrorString.k));
85
+ return;
86
+ }
79
87
  if (this.h || allowAnonymous) {
80
- const request = new r({
88
+ const request = new l({
81
89
  cid: this.h,
82
90
  token,
83
91
  });
@@ -140,7 +148,7 @@ export class WsClient {
140
148
  return;
141
149
  }
142
150
  if (this.m) {
143
- this.m.a6(delay ?? 0);
151
+ this.m.a3(delay ?? 0);
144
152
  }
145
153
  else if (delay) {
146
154
  this.m = new b(delay, () => this.m = undefined);
@@ -150,49 +158,54 @@ export class WsClient {
150
158
  }
151
159
  }
152
160
  onConnectionStatus(listener) {
153
- let { k } = this;
154
- if (!k) {
155
- this.k = k = [];
161
+ let { j } = this;
162
+ if (!j) {
163
+ this.j = j = [];
156
164
  }
157
- k.push(listener);
165
+ j.push(listener);
158
166
  }
159
167
  async c() {
160
- const { I, f, m } = this;
168
+ const { H, d, m } = this;
161
169
  this.q = -1;
162
170
  if (m) {
163
- await m.a0();
171
+ await m.Y();
172
+ }
173
+ const e = H();
174
+ try {
175
+ return d.c(e);
176
+ }
177
+ catch {
178
+ this.B(d, this.a, true, new Error(NetErrorString.k));
164
179
  }
165
- const d = I();
166
- return f.c(d);
167
180
  }
168
- F(f, conn, R) {
181
+ K(d, conn, W) {
169
182
  this.q = 1;
170
183
  conn.context = '';
171
- if (this.k) {
172
- for (const listener of this.k) {
173
- listener(true, R);
184
+ if (this.j) {
185
+ for (const listener of this.j) {
186
+ listener(true, W);
174
187
  }
175
188
  }
176
189
  }
177
- G(f, a, E, err) {
190
+ B(d, a, G, err) {
178
191
  this.q = 0;
179
- this.a.aa();
180
- if (!E) {
192
+ this.a.a5();
193
+ if (!G) {
181
194
  this.resetAuthState();
182
195
  }
183
- if (this.k) {
184
- for (const listener of this.k) {
185
- listener(false, E, err);
196
+ if (this.j) {
197
+ for (const listener of this.j) {
198
+ listener(false, G, err);
186
199
  }
187
200
  }
188
201
  }
189
- f;
202
+ d;
190
203
  a;
191
204
  h;
192
205
  q;
193
- I;
206
+ H;
194
207
  O;
195
208
  m;
196
- k;
209
+ j;
197
210
  }
198
211
  //# sourceMappingURL=WsClient.js.map
package/lib/bundle.min.js CHANGED
@@ -1 +1 @@
1
- var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{EK:()=>p,sr:()=>i,si:()=>o,N3:()=>d,sk:()=>u,wL:()=>l,bM:()=>n,h8:()=>h,Yu:()=>E,I9:()=>I,iU:()=>$,mx:()=>y});class s{constructor(t,e){e?(this.r=t,this.s=void 0):(this.r=void 0,this.s=t)}get data(){return this.s||(this.s=this.decode(this.r)),this.s}set data(t){this.s=t,this.r=void 0}get buff(){return this.r||(this.r=this.encode(this.s)),this.r}r;s}class r extends s{static context;static registerPkgType(t){let e;try{e=this.pkgType}catch{return void Object.defineProperty(this,"pkgType",{value:t,writable:!1,enumerable:!1})}if(e!==t)throw new Error(`Wrapper ${this.name} is already registered with type ${e}`)}static get pkgType(){throw new Error(`Wrapper ${this.name} need to be registered`)}}class i extends r{isError(){return!0}}class n extends r{isMessage(){return!0}}class o extends r{isEvent(){return!0}}class h extends r{constructor(t,e){super(t,e)}isRequest(){return!0}get resp(){return this.z||(this.z=this.decodeResponse(this.$)),this.z}set resp(t){this.z=t,this.$=void 0}get respBuff(){return this.$||(this.$=this.encodeResponse(this.z)),this.$}set respBuff(t){this.z=void 0,this.$=t}z;$}const a=new TextEncoder,c=new TextDecoder;class d extends i{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}}class u extends n{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}}class l extends h{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}encodeResponse(t){const e=JSON.stringify(t);return a.encode(e)}decodeResponse(t){const e=c.decode(t);return JSON.parse(e)}}class p extends d{}const g=new Error("Connection is not authenticated");let f=(t,e)=>new p(e.message);const y=t=>{f=t};class w{constructor(){this.d=this,this.i=this}getPrev(){return this.d}getNext(){return this.i}insertBefore(t){this.i=t,this.d=t.d,t.d=this,this.d.i=this}insertAfter(t){this.d=t,this.i=t.i,t.i=this,this.i.d=this}remove(){this.d.i=this.i,this.i.d=this.d}d;i}class m{constructor(){this._=new w}get e(){return this._.getNext()}get a(){return this._.getPrev()}P(t){return t===this._}Q(t){t.insertAfter(this._)}ab(t){t.insertBefore(this._)}_}const k=()=>{},v=t=>{let e=0,s=0;for(;e<t.length;)s+=t[e++].length;const r=new Uint8Array(s);for(s=0;e>0;){const i=t[--e];r.set(i,s),s+=i.length}return r};class b extends w{}class E{constructor(t,e,s){if(this.R=t,this.J=e,this.D=s,this.o=0,this.E=0,this.t=[],0===t)return this.insert=k,this.update=k,void(this.remove=k);for(let t=0;t<s;t++)this.t.push(new m)}insert(t){this.E||(this.S=setInterval(this.a2,this.R)),this.E++,this.t[this.o].Q(t)}update(t){t.remove(),this.t[this.o].Q(t)}remove(t){t.remove(),this.E--,this.E||clearInterval(this.S)}a2=()=>{const{J:t,D:e,t:s}=this;if(this.o++,this.o===e&&(this.o=0),t){let r=this.o+t;r>=e&&(r-=e);const i=s[r];for(let t=i.e;!i.P(t);t=t.getNext())t.keepAlive()}const r=s[this.o];for(let t=r.e;!r.P(t);t=t.getNext())t.timeout()};R;J;D;o;E;S;t}class P{constructor(t,e){this.Z=new Promise((t=>{this.H=t})),this.N=e,t>0?this.w=setTimeout((()=>{this.w=void 0,this.N?.(),this.H()}),t):this.H()}a6(t){this.w&&clearTimeout(this.w),t>0?this.w=setTimeout((()=>{this.w=void 0,this.N?.(),this.H()}),t):(this.w=void 0,this.H())}async a0(){await this.Z}H;Z;w;N}class x{constructor(t,e,s=!0){this.l=t,this.x=e,this.y=s}get pkgType(){return this.l.pkgType}get m(){return this.l.name}async $(t,e){const{buff:s,bodyOffset:r}=e,i=s.subarray(r),n=new this.l(i,!0);if(void 0===t.context&&this.y)f(t,g);else try{await this.x(t,n)}catch(e){e.isError||f(t,e)}void 0===t.context&&await t.close()}async r(t,e){if(void 0===t.context&&this.y)f(t,g);else try{return await this.x(t,e)}catch(e){e.isError||f(t,e)}}l;x;y}class T{constructor(t,e,s=!0){this.l=t,this.x=e,this.y=s}get pkgType(){return this.l.pkgType}get m(){return this.l.name}async $(t,e){const{buff:s,requestId:r,bodyOffset:i}=e,n=s.subarray(i),o=new this.l(n,!0);let h;if(void 0===t.context&&this.y)h=f(t,g);else try{await this.x(t,o)}catch(e){h=e.isError?e:f(t,e)}try{h?await t.sendErrorResponse(h,r):await t.sendResponse(o,r),void 0===t.context&&await t.close()}catch(e){await t.close(e)}}async r(t,e){if(void 0!==t.context||!this.y)try{return await this.x(t,e)}catch(e){throw e.isError?e:f(t,e)}throw f(t,g)}l;x;y}class R{o(){return null}N(t){this.C=t}async O(t){return!1}async P(){return!1}async c(t){const e=new WebSocket(t);return new Promise(((t,s)=>{e.onerror=t=>{s(new Error("WebSocket error"))},e.onopen=()=>{t(this.a9(e,!0))}}))}a9=(t,e)=>{const s=new A(t),{conn:r,D:i,n}=this.C(s,e);return t.onmessage=t=>{t.data.arrayBuffer().then((t=>{i(new Uint8Array(t))}))},t.onerror=t=>{n(new Error("WebSocket error"))},t.onclose=t=>{1e3===t.code?n():n(new Error(t.reason))},r};C(t,e){throw new Error('Need to call "setConnWrapperMaker" before using')}}class A{constructor(t){this.g=t}get localAddress(){}get localPort(){}get remoteAddress(){}get remoteFamily(){}get remotePort(){}async I(t){if(this.g)return this.g.send(t);throw new Error("Invalid socket")}async p(t){if(this.g){const e=v(t);return this.g.send(e)}throw new Error("Invalid socket")}async close(t){const{g:e}=this;e&&(this.g=void 0,t?e.close(3e3,t.message):e.readyState===WebSocket.OPEN&&e.close(1e3))}J(){return!this.g}g}const q=(t,e,s)=>{const r=[e,t],i=(t=>{let e,s=0,r=0;for(;s<t.length;)for(r++,e=t[s++];e>>>=7;)r++;return r})(r),n=new Uint8Array(i);((t,e,s=0)=>{let r,i,n=s;for(r=0;r<t.length;r++){i=t[r];let s=127&i;for(;i>>>=7;)e[n++]=128|s,s=127&i;e[n++]=s}if(n<=e.length)return n-s;throw new Error("Buffer overflow")})(r,n),s.push(n)},M=t=>{const{h:[e,s],k:r}=((t,e,s=0)=>{let r,i,n=s,o=0,h=0;const a=[];for(r=0;r<t;r++){do{i=e[n++],o|=(127&i)<<h,h+=7}while(128&i);if(!(void 0!==i&&h<=35))throw new Error("Parsing failed");a.push(o),o=0,h=0}return{h:a,k:n-s}})(2,t);return{buff:t,pkgType:s,requestId:e,bodyOffset:r}};class W{constructor(t){this.a1=t}get id(){return this.a?.id??-1}get context(){return this.a?.context}set context(t){this.a&&(this.a.context=t)}localAddress;localPort;remoteAddress;remoteFamily;remotePort;async sendErrorResponse(t,e){return(this.a??await this.c()).sendErrorResponse(t,e)}async sendResponse(t,e){return(this.a??await this.c()).sendResponse(t,e)}async sendMessage(t){return(this.a??await this.c()).sendMessage(t)}async sendRequest(t){return(this.a??await this.c()).sendRequest(t)}async close(t){const{a:e}=this;if(e)return this.a=void 0,void await e.close(t);this.p&&await this.p.then((e=>{this.a=void 0,e.close(t)}),(()=>this.a=void 0))}async reconnect(){this.a||await this.c()}aa(){this.a=void 0}async c(){let{p:t}=this;return t||(t=this.p=new Promise(((t,e)=>{this.a1().then((s=>{s?(t(s),this.a=s,this.p=void 0):e(new Error("Connect failed"))}))}))),await t}a1;a;p}class B{constructor(t,e){const{responsePkgType:s,timeoutMonitor:r,makePkgBuff:i,parsePkgBuff:n}=e;this.responsePkgType=s,this.context=void 0,this.F=void 0,this.G=void 0,this.u=0,this.v=new Map,this.e=new Map,this.L=new Map,this.T=i,this.U=n,this.A=t,this.K=r,this.$=this.a3;const o=[];this.T(s,2097152,o),this.V={makePkgBuff:i,responsePkgType:s,s:v(o)},this.e.set(s,this),this.A.N(((t,e)=>{do{this.u++}while(this.v.has(2097151&this.u));const s=new N(this.V,t,2097151&this.u);this.v.set(s.id,s),this.K?.insert(s);const r={conn:s,D:t=>this.a4(s,t),n:t=>this.a5(s,t)};return this.F?.(this,s,!!e),r}))}responsePkgType;context;F;G;o(){return this.A.o()}Z(t){return this.v.get(t)}c(t){return this.A.c(t)}async a0(){do{this.u++}while(this.v.has(2097151&this.u));const t=new O(2097151&this.u,this);return this.v.set(t.id,t),t}async a1(t){return this.A.O(t)}async a2(){return this.A.P()}a7(t,e){const s=e.constructor.pkgType,r=this.e.get(s);if(r)return r?.r(t,e);throw new Error("Invalid package")}a8(t,e){const s=e.constructor.pkgType,r=this.e.get(s);if(r)return r?.r(t,e);throw new Error("Invalid package")}registerError(t,e){e.registerPkgType(t),this.L.set(t,e);const s=this.e.get(this.responsePkgType);this.e.set(t,s)}registerMessage(t,e){e.registerPkgType(t)}registerRequest(t,e){e.registerPkgType(t)}handleMessageWith(t){const e=t.pkgType;if(typeof e!=typeof this.responsePkgType)throw new Error(`Wrapper ${t.m} has an incompatible pkgType ${typeof e}`);if(this.e.has(e))throw new Error(`Wrapper ${t.m} is already handled by another handler`);return this.e.set(e,t),t}handleRequestWith(t){const e=t.pkgType;if(typeof e!=typeof this.responsePkgType)throw new Error(`Wrapper ${t.m} has an incompatible pkgType ${typeof e}`);if(this.e.has(e))throw new Error(`Wrapper ${t.m} is already handled by another handler`);return this.e.set(e,t),t}ak(t){const e=t.pkgType;return this.e.get(e)===t&&(this.e.delete(e),!0)}a4(t,e){this.K?.update(t);const s=this.U(e),r=this.e.get(s.pkgType);r?r.$(t,s):t.close(new Error("Invalid package"))}a5(t,e){const s=t.id;this.v.delete(s),this.K?.remove(t),t.n(e),this.G?.(this,t,t.b.J(),e)}a3(t,e){const{buff:s,pkgType:r,requestId:i,bodyOffset:n}=e;if(r===this.responsePkgType){const e=s.subarray(n);t.W(i,e)}else{const e=this.L.get(r);if(e){const r=new e(s.subarray(n),!0);t.ac(i,r)}}}V;u;T;U;A;v;e;L;K}class N extends b{constructor(t,e,s){super(),this.context=void 0,this.id=s,this.b=e,this.B=t,this.j=void 0,this.X=0}context;id;b;get localAddress(){return this.b.localAddress}get localPort(){return this.b.localPort}get remoteAddress(){return this.b.remoteAddress}get remoteFamily(){return this.b.remoteFamily}get remotePort(){return this.b.remotePort}sendMessage(t){const e=t.constructor.pkgType,s=[t.buff];return this.B.makePkgBuff(e,0,s),this.b.p(s)}sendRequest(t){return this.j=new Map,this.sendRequest=this.Y,this.W=this.ad,this.n=this.ae,this.Y(t)}sendErrorResponse(t,e){const s=t.constructor.pkgType,r=[t.buff];return this.B.makePkgBuff(s,e,r),this.b.p(r)}sendResponse(t,e){const s=[t.respBuff],{makePkgBuff:r,responsePkgType:i}=this.B;return r(i,e,s),this.b.p(s)}async close(t){await this.b.close(t)}W(t,e){2097152===t&&void 0===this.context&&this.close(new Error("Authenticating timeout"))}ac(t,e){const s=this.j.get(t);if(s)return this.j.delete(t),s.i(e)}keepAlive(){this.b.I(this.B.s).catch(k)}timeout(){this.close(new Error("Connection timeout"))}n(t){}async Y(t){const e=2097151&this.X++,s=t.constructor.pkgType,r=[t.buff];this.B.makePkgBuff(s,e,r);const i=new Promise(((t,s)=>{const i={f:t,i:s};this.j.set(e,i),this.b.p(r).catch((t=>{this.j.delete(e),s(t)}))}));t.respBuff=await i}ad(t,e){const s=this.j.get(t);if(s)return this.j.delete(t),void s.f(e);2097152===t&&void 0===this.context&&this.close(new Error("Authenticating timeout"))}ae(t){const e=this.j;if(e.size>0){t||(t=new Error("Connection is closed"));for(const[s,r]of e)e.delete(s),r.i(t)}this.j=void 0}B;j;X}class O{constructor(t,e){this.context=void 0,this.id=t,this.M=e}context;id;localAddress;localPort;remoteAddress;remotePort;get remoteFamily(){return"Local"}async sendMessage(t){return this.M.a7(this,t)}async sendRequest(t){return this.M.a8(this,t)}sendErrorResponse(t,e){throw null}sendResponse(t,e){throw null}async close(t){}M}class S extends l{}const $=(t,e)=>new I(t,{responsePkgType:0,makePkgBuff:q,parsePkgBuff:M,timeoutMonitor:e});class I{constructor(t,e){const s=new R,r=this.f=new B(s,e);this.h="",this.k=[],this.q=0,this.a=new W((()=>this.c())),this.I=t,this.O=this.c,r.F=this.F.bind(this),r.G=this.G.bind(this)}registerError(t,e){return this.f.registerError(t,e)}registerMessage(t,e){return this.f.registerMessage(t,e)}registerRequest(t,e){return this.f.registerRequest(t,e)}handleMessageWith(t,e){this.f.handleMessageWith(new x(t,((t,s)=>e(s.data)),!1))}handleRequestWith(t,e){this.f.handleRequestWith(new T(t,(async(t,s)=>{s.resp=await e(s.data)}),!1))}sendMessage(t){return this.a.sendMessage(t)}async sendRequest(t){return await this.a.sendRequest(t),t.resp}async sendCustomAuthRequest(t){throw new Error('Need to call "enableAuthenticate" before using sendCustomAuthRequest')}resetAuthState(){}enableAuthenticate(t,e,s){const{O:r,I:i,f:n,a:o}=this;if(this.c===r){n.registerRequest(t,S);let r,h="";this.c=async()=>{for(this.q=-1,this.m&&await this.m.a0();;){const t=i(r),o=await n.c(t);if(this.h||s){const t=new S({cid:this.h,token:h});try{await o.sendRequest(t);const{resp:s}=t;if(this.h=s.cid,h=s.token,r=s.shard,r&&r<0){r=-r-1,o.close();continue}e(this.h)}catch(t){return t instanceof p&&"HitSessionLimit"===t.data&&(this.h="",h="",r=void 0,e(this.h)),void o.close(t)}}return o}},this.sendCustomAuthRequest=async t=>{await o.sendRequest(t);const{resp:s}=t;return this.h=s.cid,h=s.token,r=s.shard,r&&r<0&&(r=-r-1,o.close()),e(this.h),s},this.resetAuthState=()=>{this.h&&(this.h="",h="",r=void 0,o.close(),e(this.h))}}}reconnect(t){const{a:e,q:s}=this;s>0||(this.m?this.m.a6(t??0):t&&(this.m=new P(t,(()=>this.m=void 0))),s||e.reconnect())}onConnectionStatus(t){let{k:e}=this;e||(this.k=e=[]),e.push(t)}async c(){const{I:t,f:e,m:s}=this;this.q=-1,s&&await s.a0();const r=t();return e.c(r)}F(t,e,s){if(this.q=1,e.context="",this.k)for(const t of this.k)t(!0,s)}G(t,e,s,r){if(this.q=0,this.a.aa(),s||this.resetAuthState(),this.k)for(const t of this.k)t(!1,s,r)}f;a;h;q;I;O;m;k}var J=e.EK,C=e.sr,j=e.si,F=e.N3,U=e.sk,z=e.wL,L=e.bM,H=e.h8,K=e.Yu,_=e.I9,D=e.iU,G=e.mx;export{J as CommonError,C as ErrorWrapper,j as EventWrapper,F as JsonError,U as JsonMessage,z as JsonRequest,L as MessageWrapper,H as RequestWrapper,K as TimeoutMonitor,_ as WsClient,D as createNumPkgTypeClient,G as handleUncaughtErrorWith};
1
+ var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{EK:()=>p,sr:()=>i,si:()=>o,N3:()=>u,sk:()=>d,wL:()=>l,bM:()=>n,Lm:()=>y,h8:()=>h,Yu:()=>b,I9:()=>I,iU:()=>$,mx:()=>f});class s{constructor(t,e){e?this.x=t:this.y=t}get data(){return this.y||(this.y=this.decode(this.x)),this.y}set data(t){this.y=t,this.x=void 0}get buff(){return this.x||(this.x=this.encode(this.y)),this.x}x;y}class r extends s{static context;static registerPkgType(t){let e;try{e=this.pkgType}catch{return void Object.defineProperty(this,"pkgType",{value:t,writable:!1,enumerable:!1})}if(e!==t)throw new Error(`Wrapper ${this.name} is already registered with type ${e}`)}static get pkgType(){throw new Error(`Wrapper ${this.name} need to be registered`)}}class i extends r{isError(){return!0}}class n extends r{isMessage(){return!0}}class o extends r{isEvent(){return!0}}class h extends r{constructor(t,e){super(t,e)}isRequest(){return!0}get resp(){return this.z||(this.z=this.decodeResponse(this.$)),this.z}set resp(t){this.z=t,this.$=void 0}get respBuff(){return this.$||(this.$=this.encodeResponse(this.z)),this.$}set respBuff(t){this.z=void 0,this.$=t}z;$}const a=new TextEncoder,c=new TextDecoder;class u extends i{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}}class d extends n{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}}class l extends h{encode(t){const e=JSON.stringify(t);return a.encode(e)}decode(t){const e=c.decode(t);return JSON.parse(e)}encodeResponse(t){const e=JSON.stringify(t);return a.encode(e)}decodeResponse(t){const e=c.decode(t);return JSON.parse(e)}}class p extends u{}let g=(t,e)=>new p(e.message);const f=t=>{g=t};var y;!function(t){t.I="AuthTimeout",t.a="BadRequest",t.k="ConnectFailed",t.a1="ConnectionClosed",t.b="InvalidConnString",t.l="InvalidConnection",t.D="InvalidPackage",t.g="NotAuthenticated",t.a2="Timeout",t.m="UnknownError"}(y||(y={}));class w{constructor(){this.e=this,this.i=this}getPrev(){return this.e}getNext(){return this.i}insertBefore(t){this.i=t,this.e=t.e,t.e=this,this.e.i=this}insertAfter(t){this.e=t,this.i=t.i,t.i=this,this.i.e=this}remove(){this.e.i=this.i,this.i.e=this.e}e;i}class m{constructor(){this._=new w}get f(){return this._.getNext()}get a(){return this._.getPrev()}P(t){return t===this._}Q(t){t.insertAfter(this._)}a6(t){t.insertBefore(this._)}_}const k=()=>{},v=t=>{let e=0,s=0;for(;e<t.length;)s+=t[e++].length;const r=new Uint8Array(s);for(s=0;e>0;){const i=t[--e];r.set(i,s),s+=i.length}return r};class E extends w{}class b{constructor(t,e,s){if(this.R=t,this.I=e,this.E=s,this.o=0,this.F=0,this.r=[],0===t)return this.insert=k,this.update=k,void(this.remove=k);for(let t=0;t<s;t++)this.r.push(new m)}insert(t){this.F||(this.S=setInterval(this.a2,this.R)),this.F++,this.r[this.o].Q(t)}update(t){t.remove(),this.r[this.o].Q(t)}remove(t){t.remove(),this.F--,this.F||clearInterval(this.S)}a2=()=>{const{I:t,E:e,r:s}=this;if(this.o++,this.o===e&&(this.o=0),t){let r=this.o+t;r>=e&&(r-=e);const i=s[r];for(let t=i.f;!i.P(t);t=t.getNext())t.keepAlive()}const r=s[this.o];for(let t=r.f;!r.P(t);t=t.getNext())t.timeout()};R;I;E;o;F;S;r}class P{constructor(t,e){this.W=new Promise((t=>{this.G=t})),this.N=e,t>0?this.u=setTimeout((()=>{this.u=void 0,this.N?.(),this.G()}),t):this.G()}a3(t){this.u&&clearTimeout(this.u),t>0?this.u=setTimeout((()=>{this.u=void 0,this.N?.(),this.G()}),t):(this.u=void 0,this.G())}async Y(){await this.W}G;W;u;N}const T=new Error(y.g);class x{constructor(t,e,s=!0){this.l=t,this.v=e,this.w=s}get pkgType(){return this.l.pkgType}get m(){return this.l.name}async $(t,e){const{buff:s,bodyOffset:r}=e,i=s.subarray(r),n=new this.l(i,!0);if(void 0===t.context&&this.w)g(t,T);else try{await this.v(t,n)}catch(e){e.isError||g(t,e)}void 0===t.context&&await t.close()}async r(t,e){if(void 0===t.context&&this.w)g(t,T);else try{return await this.v(t,e)}catch(e){e.isError||g(t,e)}}l;v;w}class R{constructor(t,e,s=!0){this.l=t,this.v=e,this.w=s}get pkgType(){return this.l.pkgType}get m(){return this.l.name}async $(t,e){const{buff:s,requestId:r,bodyOffset:i}=e,n=s.subarray(i),o=new this.l(n,!0);let h;if(void 0===t.context&&this.w)h=g(t,T);else try{await this.v(t,o)}catch(e){h=e.isError?e:g(t,e)}try{h?await t.sendErrorResponse(h,r):await t.sendResponse(o,r),void 0===t.context&&await t.close()}catch(e){await t.close(e)}}async r(t,e){if(void 0!==t.context||!this.w)try{return await this.v(t,e)}catch(e){throw e.isError?e:g(t,e)}throw g(t,T)}l;v;w}class A{o(){return null}P(t){this.D=t}async Q(t){return!1}async R(){return!1}async c(t){const e=new WebSocket(t);return new Promise(((t,s)=>{e.onerror=t=>{s(new Error(y.m))},e.onopen=()=>{t(this.a4(e,!0))}}))}a4=(t,e)=>{const s=new q(t),{conn:r,E:i,n}=this.D(s,e);return t.onmessage=t=>{t.data.arrayBuffer().then((t=>{i(new Uint8Array(t))}))},t.onerror=t=>{n(new Error(y.m))},t.onclose=t=>{1e3===t.code?n():n(new Error(t.reason))},r};D(t,e){throw new Error('Need to call "setConnWrapperMaker" before using')}}class q{constructor(t){this.g=t}get localAddress(){}get localPort(){}get remoteAddress(){}get remoteFamily(){}get remotePort(){}async N(t){if(this.g)return this.g.send(t);throw new Error(y.l)}async p(t){if(this.g){const e=v(t);return this.g.send(e)}throw new Error(y.l)}async close(t){const{g:e}=this;e&&(this.g=void 0,t?e.close(3e3,t.message):e.readyState===WebSocket.OPEN&&e.close(1e3))}O(){return!this.g}g}const M=(t,e,s)=>{const r=[e,t],i=(t=>{let e,s=0,r=0;for(;s<t.length;)for(r++,e=t[s++];e>>>=7;)r++;return r})(r),n=new Uint8Array(i);((t,e,s=0)=>{let r,i,n=s;for(r=0;r<t.length;r++){i=t[r];let s=127&i;for(;i>>>=7;)e[n++]=128|s,s=127&i;e[n++]=s}if(n<=e.length)return n-s;throw new Error("Buffer overflow")})(r,n),s.push(n)},N=t=>{const{h:[e,s],k:r}=((t,e,s=0)=>{let r,i,n=s,o=0,h=0;const a=[];for(r=0;r<t;r++){do{i=e[n++],o|=(127&i)<<h,h+=7}while(128&i);if(!(void 0!==i&&h<=35))throw new Error("Parsing failed");a.push(o),o=0,h=0}return{h:a,k:n-s}})(2,t);return{buff:t,pkgType:s,requestId:e,bodyOffset:r}};class B{constructor(t){this.a1=t}get id(){return this.a?.id??-1}get context(){return this.a?.context}set context(t){this.a&&(this.a.context=t)}localAddress;localPort;remoteAddress;remoteFamily;remotePort;async sendErrorResponse(t,e){return(this.a??await this.c()).sendErrorResponse(t,e)}async sendResponse(t,e){return(this.a??await this.c()).sendResponse(t,e)}async sendMessage(t){return(this.a??await this.c()).sendMessage(t)}async sendRequest(t){return(this.a??await this.c()).sendRequest(t)}async close(t){const{a:e}=this;if(e)return this.a=void 0,void await e.close(t);this.p&&await this.p.then((e=>{this.a=void 0,e.close(t)}),(()=>this.a=void 0))}async reconnect(){this.a||await this.c()}a5(){this.a=void 0}async c(){let{p:t}=this;return t||(t=this.p=new Promise(((t,e)=>{this.a1().then((s=>{s?(t(s),this.a=s,this.p=void 0):e(new Error("Connect failed"))}))}))),await t}a1;a;p}class W{constructor(t,e){const{responsePkgType:s,timeoutMonitor:r,makePkgBuff:i,parsePkgBuff:n}=e;this.responsePkgType=s,this.s=0,this.t=new Map,this.f=new Map,this.L=new Map,this.T=i,this.U=n,this.A=t,this.J=r,this.$=this.a7;const o=[];this.T(s,2097152,o),this.V={makePkgBuff:i,responsePkgType:s,u:v(o)},this.f.set(s,this),this.A.P(((t,e)=>{do{this.s++}while(this.t.has(2097151&this.s));const s=new O(this.V,t,2097151&this.s);this.t.set(s.id,s),this.J?.insert(s);const r={conn:s,E:t=>this.a8(s,t),n:t=>this.a9(s,t)};return this.K?.(this,s,!!e),r}))}responsePkgType;context;K;B;o(){return this.A.o()}a3(t){return this.t.get(t)}c(t){return this.A.c(t)}async a4(){do{this.s++}while(this.t.has(2097151&this.s));const t=new C(2097151&this.s,this);return this.t.set(t.id,t),t}async a5(t){return this.A.Q(t)}async a6(){return this.A.R()}ab(t,e){const s=e.constructor.pkgType,r=this.f.get(s);if(r)return r?.r(t,e);throw new Error(y.D)}ac(t,e){const s=e.constructor.pkgType,r=this.f.get(s);if(r)return r?.r(t,e);throw new Error(y.D)}registerError(t,e){e.registerPkgType(t),this.L.set(t,e);const s=this.f.get(this.responsePkgType);this.f.set(t,s)}registerMessage(t,e){e.registerPkgType(t)}registerRequest(t,e){e.registerPkgType(t)}handleMessageWith(t){const e=t.pkgType;if(typeof e!=typeof this.responsePkgType)throw new Error(`Wrapper ${t.m} has an incompatible pkgType ${typeof e}`);if(this.f.has(e))throw new Error(`Wrapper ${t.m} is already handled by another handler`);return this.f.set(e,t),t}handleRequestWith(t){const e=t.pkgType;if(typeof e!=typeof this.responsePkgType)throw new Error(`Wrapper ${t.m} has an incompatible pkgType ${typeof e}`);if(this.f.has(e))throw new Error(`Wrapper ${t.m} is already handled by another handler`);return this.f.set(e,t),t}ao(t){const e=t.pkgType;return this.f.get(e)===t&&(this.f.delete(e),!0)}a8(t,e){this.J?.update(t);const s=this.U(e),r=this.f.get(s.pkgType);r?r.$(t,s):t.close(new Error(y.D))}a9(t,e){const s=t.id;this.t.delete(s),this.J?.remove(t),t.n(e),this.B?.(this,t,t.b.O(),e)}a7(t,e){const{buff:s,pkgType:r,requestId:i,bodyOffset:n}=e;if(r===this.responsePkgType){const e=s.subarray(n);t.X(i,e)}else{const e=this.L.get(r);if(e){const r=new e(s.subarray(n),!0);t.ag(i,r)}}}V;s;T;U;A;t;f;L;J}class O extends E{constructor(t,e,s){super(),this.id=s,this.b=e,this.C=t,this.Z=0}context;id;b;get localAddress(){return this.b.localAddress}get localPort(){return this.b.localPort}get remoteAddress(){return this.b.remoteAddress}get remoteFamily(){return this.b.remoteFamily}get remotePort(){return this.b.remotePort}sendMessage(t){const e=t.constructor.pkgType,s=[t.buff];return this.C.makePkgBuff(e,0,s),this.b.p(s)}sendRequest(t){return this.k=new Map,this.sendRequest=this.a0,this.X=this.ah,this.n=this.ai,this.a0(t)}sendErrorResponse(t,e){const s=t.constructor.pkgType,r=[t.buff];return this.C.makePkgBuff(s,e,r),this.b.p(r)}sendResponse(t,e){const s=[t.respBuff],{makePkgBuff:r,responsePkgType:i}=this.C;return r(i,e,s),this.b.p(s)}async close(t){await this.b.close(t)}X(t,e){2097152===t&&void 0===this.context&&this.close(new Error(y.I))}ag(t,e){const s=this.k.get(t);if(s)return this.k.delete(t),s.i(e)}keepAlive(){this.b.N(this.C.u).catch(k)}timeout(){this.close(new Error(y.a2))}n(t){}async a0(t){const e=2097151&this.Z++,s=t.constructor.pkgType,r=[t.buff];this.C.makePkgBuff(s,e,r);const i=new Promise(((t,s)=>{const i={d:t,i:s};this.k.set(e,i),this.b.p(r).catch((t=>{this.k.delete(e),s(t)}))}));t.respBuff=await i}ah(t,e){const s=this.k.get(t);if(s)return this.k.delete(t),void s.d(e);2097152===t&&void 0===this.context&&this.close(new Error(y.I))}ai(t){const e=this.k;if(e.size>0){t||(t=new Error(y.a1));for(const[s,r]of e)e.delete(s),r.i(t)}this.k=void 0}C;k;Z}class C{constructor(t,e){this.id=t,this.M=e}context;id;localAddress;localPort;remoteAddress;remotePort;get remoteFamily(){return"Local"}async sendMessage(t){return this.M.ab(this,t)}async sendRequest(t){return this.M.ac(this,t)}sendErrorResponse(t,e){throw null}sendResponse(t,e){throw null}async close(t){}M}class S extends l{}const $=(t,e)=>new I(t,{responsePkgType:0,makePkgBuff:M,parsePkgBuff:N,timeoutMonitor:e});class I{constructor(t,e){const s=new A,r=this.d=new W(s,e);this.h="",this.j=[],this.q=0,this.a=new B((()=>this.c())),this.H=t,this.O=this.c,r.K=this.K.bind(this),r.B=this.B.bind(this)}registerError(t,e){return this.d.registerError(t,e)}registerMessage(t,e){return this.d.registerMessage(t,e)}registerRequest(t,e){return this.d.registerRequest(t,e)}handleMessageWith(t,e){this.d.handleMessageWith(new x(t,((t,s)=>e(s.data)),!1))}handleRequestWith(t,e){this.d.handleRequestWith(new R(t,(async(t,s)=>{s.resp=await e(s.data)}),!1))}sendMessage(t){return this.a.sendMessage(t)}async sendRequest(t){return await this.a.sendRequest(t),t.resp}async sendCustomAuthRequest(t){throw new Error('Need to call "enableAuthenticate" before using sendCustomAuthRequest')}resetAuthState(){}enableAuthenticate(t,e,s){const{O:r,H:i,d:n,a:o}=this;if(this.c===r){n.registerRequest(t,S);let r,h="";this.c=async()=>{for(this.q=-1,this.m&&await this.m.Y();;){const t=i(r);let o;try{o=await n.c(t)}catch{return void this.B(n,this.a,!0,new Error(y.k))}if(this.h||s){const t=new S({cid:this.h,token:h});try{await o.sendRequest(t);const{resp:s}=t;if(this.h=s.cid,h=s.token,r=s.shard,r&&r<0){r=-r-1,o.close();continue}e(this.h)}catch(t){return t instanceof p&&"HitSessionLimit"===t.data&&(this.h="",h="",r=void 0,e(this.h)),void o.close(t)}}return o}},this.sendCustomAuthRequest=async t=>{await o.sendRequest(t);const{resp:s}=t;return this.h=s.cid,h=s.token,r=s.shard,r&&r<0&&(r=-r-1,o.close()),e(this.h),s},this.resetAuthState=()=>{this.h&&(this.h="",h="",r=void 0,o.close(),e(this.h))}}}reconnect(t){const{a:e,q:s}=this;s>0||(this.m?this.m.a3(t??0):t&&(this.m=new P(t,(()=>this.m=void 0))),s||e.reconnect())}onConnectionStatus(t){let{j:e}=this;e||(this.j=e=[]),e.push(t)}async c(){const{H:t,d:e,m:s}=this;this.q=-1,s&&await s.Y();const r=t();try{return e.c(r)}catch{this.B(e,this.a,!0,new Error(y.k))}}K(t,e,s){if(this.q=1,e.context="",this.j)for(const t of this.j)t(!0,s)}B(t,e,s,r){if(this.q=0,this.a.a5(),s||this.resetAuthState(),this.j)for(const t of this.j)t(!1,s,r)}d;a;h;q;H;O;m;j}var J=e.EK,F=e.sr,j=e.si,L=e.N3,U=e.sk,z=e.wL,D=e.bM,K=e.Lm,_=e.h8,G=e.Yu,H=e.I9,Q=e.iU,Y=e.mx;export{J as CommonError,F as ErrorWrapper,j as EventWrapper,L as JsonError,U as JsonMessage,z as JsonRequest,D as MessageWrapper,K as NetErrorString,_ as RequestWrapper,G as TimeoutMonitor,H as WsClient,Q as createNumPkgTypeClient,Y as handleUncaughtErrorWith};
@@ -1,42 +1,42 @@
1
1
  export class b {
2
2
  constructor(a, c) {
3
- this.Z = new Promise((f) => {
4
- this.H = f;
3
+ this.W = new Promise((d) => {
4
+ this.G = d;
5
5
  });
6
6
  this.N = c;
7
7
  if (a > 0) {
8
- this.w = setTimeout(() => {
9
- this.w = undefined;
8
+ this.u = setTimeout(() => {
9
+ this.u = undefined;
10
10
  this.N?.();
11
- this.H();
11
+ this.G();
12
12
  }, a);
13
13
  }
14
14
  else {
15
- this.H();
15
+ this.G();
16
16
  }
17
17
  }
18
- a6(a) {
19
- if (this.w) {
20
- clearTimeout(this.w);
18
+ a3(a) {
19
+ if (this.u) {
20
+ clearTimeout(this.u);
21
21
  }
22
22
  if (a > 0) {
23
- this.w = setTimeout(() => {
24
- this.w = undefined;
23
+ this.u = setTimeout(() => {
24
+ this.u = undefined;
25
25
  this.N?.();
26
- this.H();
26
+ this.G();
27
27
  }, a);
28
28
  }
29
29
  else {
30
- this.w = undefined;
31
- this.H();
30
+ this.u = undefined;
31
+ this.G();
32
32
  }
33
33
  }
34
- async a0() {
35
- await this.Z;
34
+ async Y() {
35
+ await this.W;
36
36
  }
37
- H;
38
- Z;
39
- w;
37
+ G;
38
+ W;
39
+ u;
40
40
  N;
41
41
  }
42
42
  //# sourceMappingURL=AdjustableTimer.js.map
@@ -1,31 +1,29 @@
1
1
  export class DataWrapper {
2
2
  constructor(a, needParse) {
3
3
  if (needParse) {
4
- this.r = a;
5
- this.s = undefined;
4
+ this.x = a;
6
5
  }
7
6
  else {
8
- this.r = undefined;
9
- this.s = a;
7
+ this.y = a;
10
8
  }
11
9
  }
12
10
  get data() {
13
- if (!this.s) {
14
- this.s = this.decode(this.r);
11
+ if (!this.y) {
12
+ this.y = this.decode(this.x);
15
13
  }
16
- return this.s;
14
+ return this.y;
17
15
  }
18
16
  set data(b) {
19
- this.s = b;
20
- this.r = undefined;
17
+ this.y = b;
18
+ this.x = undefined;
21
19
  }
22
20
  get buff() {
23
- if (!this.r) {
24
- this.r = this.encode(this.s);
21
+ if (!this.x) {
22
+ this.x = this.encode(this.y);
25
23
  }
26
- return this.r;
24
+ return this.x;
27
25
  }
28
- r;
29
- s;
26
+ x;
27
+ y;
30
28
  }
31
29
  //# sourceMappingURL=DataWrapper.js.map
@@ -1,38 +1,38 @@
1
1
  export class ListNode {
2
2
  constructor() {
3
- this.d = this;
3
+ this.e = this;
4
4
  this.i = this;
5
5
  }
6
6
  getPrev() {
7
- return this.d;
7
+ return this.e;
8
8
  }
9
9
  getNext() {
10
10
  return this.i;
11
11
  }
12
12
  insertBefore(node) {
13
13
  this.i = node;
14
- this.d = node.d;
15
- node.d = this;
16
- this.d.i = this;
14
+ this.e = node.e;
15
+ node.e = this;
16
+ this.e.i = this;
17
17
  }
18
18
  insertAfter(node) {
19
- this.d = node;
19
+ this.e = node;
20
20
  this.i = node.i;
21
21
  node.i = this;
22
- this.i.d = this;
22
+ this.i.e = this;
23
23
  }
24
24
  remove() {
25
- this.d.i = this.i;
26
- this.i.d = this.d;
25
+ this.e.i = this.i;
26
+ this.i.e = this.e;
27
27
  }
28
- d;
28
+ e;
29
29
  i;
30
30
  }
31
31
  export class c {
32
32
  constructor() {
33
33
  this._ = new ListNode();
34
34
  }
35
- get e() {
35
+ get f() {
36
36
  return this._.getNext();
37
37
  }
38
38
  get a() {
@@ -44,7 +44,7 @@ export class c {
44
44
  Q(node) {
45
45
  node.insertAfter(this._);
46
46
  }
47
- ab(node) {
47
+ a6(node) {
48
48
  node.insertBefore(this._);
49
49
  }
50
50
  _;
@@ -1,14 +1,14 @@
1
- export const j = (e) => {
2
- return new Promise((f) => setTimeout(f, e));
1
+ export const j = (f) => {
2
+ return new Promise((d) => setTimeout(d, f));
3
3
  };
4
4
  export const l = () => { };
5
5
  export const k = (i = 0x100000000) => {
6
6
  return (Math.random() * i) >>> 0;
7
7
  };
8
- export const m = (d) => {
8
+ export const m = (e) => {
9
9
  let c = 5381, a = 0;
10
- while (a < d.length) {
11
- c = ((c << 5) + c) + d.charCodeAt(a++);
10
+ while (a < e.length) {
11
+ c = ((c << 5) + c) + e.charCodeAt(a++);
12
12
  }
13
13
  return c >>> 0;
14
14
  };
@@ -1,9 +1,11 @@
1
- import { c, b } from './common';
2
- export class j {
3
- constructor(wrapperCtor, d, f = true) {
1
+ import { NetErrorString } from '../net/NetErrorString';
2
+ import { b } from './common';
3
+ const c = new Error(NetErrorString.g);
4
+ export class n {
5
+ constructor(wrapperCtor, d, e = true) {
4
6
  this.l = wrapperCtor;
5
- this.x = d;
6
- this.y = f;
7
+ this.v = d;
8
+ this.w = e;
7
9
  }
8
10
  get pkgType() {
9
11
  return this.l.pkgType;
@@ -15,9 +17,9 @@ export class j {
15
17
  const { buff, bodyOffset } = a;
16
18
  const h = buff.subarray(bodyOffset);
17
19
  const message = new this.l(h, true);
18
- if (conn.context !== undefined || !this.y) {
20
+ if (conn.context !== undefined || !this.w) {
19
21
  try {
20
- await this.x(conn, message);
22
+ await this.v(conn, message);
21
23
  }
22
24
  catch (err) {
23
25
  if (!err.isError) {
@@ -33,9 +35,9 @@ export class j {
33
35
  }
34
36
  }
35
37
  async r(conn, message) {
36
- if (conn.context !== undefined || !this.y) {
38
+ if (conn.context !== undefined || !this.w) {
37
39
  try {
38
- return await this.x(conn, message);
40
+ return await this.v(conn, message);
39
41
  }
40
42
  catch (err) {
41
43
  if (!err.isError) {
@@ -48,14 +50,14 @@ export class j {
48
50
  }
49
51
  }
50
52
  l;
51
- x;
52
- y;
53
+ v;
54
+ w;
53
55
  }
54
- export class n {
55
- constructor(wrapperCtor, d, f = true) {
56
+ export class o {
57
+ constructor(wrapperCtor, d, e = true) {
56
58
  this.l = wrapperCtor;
57
- this.x = d;
58
- this.y = f;
59
+ this.v = d;
60
+ this.w = e;
59
61
  }
60
62
  get pkgType() {
61
63
  return this.l.pkgType;
@@ -68,9 +70,9 @@ export class n {
68
70
  const h = buff.subarray(bodyOffset);
69
71
  const request = new this.l(h, true);
70
72
  let error;
71
- if (conn.context !== undefined || !this.y) {
73
+ if (conn.context !== undefined || !this.w) {
72
74
  try {
73
- await this.x(conn, request);
75
+ await this.v(conn, request);
74
76
  }
75
77
  catch (err) {
76
78
  if (err.isError) {
@@ -100,9 +102,9 @@ export class n {
100
102
  }
101
103
  }
102
104
  async r(conn, request) {
103
- if (conn.context !== undefined || !this.y) {
105
+ if (conn.context !== undefined || !this.w) {
104
106
  try {
105
- return await this.x(conn, request);
107
+ return await this.v(conn, request);
106
108
  }
107
109
  catch (err) {
108
110
  if (err.isError) {
@@ -116,7 +118,7 @@ export class n {
116
118
  throw b(conn, c);
117
119
  }
118
120
  l;
119
- x;
120
- y;
121
+ v;
122
+ w;
121
123
  }
122
124
  //# sourceMappingURL=SimpleHandler.js.map
@@ -1,7 +1,6 @@
1
1
  import { JsonError } from '../net/JsonPackageWrapper';
2
2
  export class CommonError extends JsonError {
3
3
  }
4
- export const c = new Error('Connection is not authenticated');
5
4
  export let b = (a, err) => {
6
5
  return new CommonError(err.message);
7
6
  };
package/lib/index.d.ts CHANGED
@@ -122,6 +122,18 @@ export interface IAuthResp {
122
122
  shard?: number;
123
123
  }
124
124
  export declare const handleUncaughtErrorWith: (handler: (conn: IConn<unknown>, err: Error) => ErrorWrapper<unknown>) => void;
125
+ export declare enum NetErrorString {
126
+ AuthTimeout = "AuthTimeout",
127
+ BadRequest = "BadRequest",
128
+ ConnectFailed = "ConnectFailed",
129
+ ConnectionClosed = "ConnectionClosed",
130
+ InvalidConnString = "InvalidConnString",
131
+ InvalidConnection = "InvalidConnection",
132
+ InvalidPackage = "InvalidPackage",
133
+ NotAuthenticated = "NotAuthenticated",
134
+ Timeout = "Timeout",
135
+ UnknownError = "UnknownError"
136
+ }
125
137
  export declare const createNumPkgTypeClient: (getConnStr: (shard?: number) => string, timeoutMonitor?: TimeoutMonitor) => WsClient<number>;
126
138
  export declare class WsClient<PkgTypeT extends number | string> {
127
139
  constructor(getConnStr: (shard?: number) => string, opts: TypedPkgHubOpts<PkgTypeT>);
package/lib/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { CommonError, handleUncaughtErrorWith } from './handler/common';
2
2
  export { JsonError, JsonMessage, JsonRequest } from './net/JsonPackageWrapper';
3
+ export { NetErrorString } from './net/NetErrorString';
3
4
  export { ErrorWrapper, EventWrapper, MessageWrapper, RequestWrapper } from './net/PackageWrapper';
4
5
  export { TimeoutMonitor } from './net/TimeoutMonitor';
5
6
  export { createNumPkgTypeClient, WsClient } from './WsClient';
@@ -1,40 +1,41 @@
1
1
  import { y } from '../common/utils';
2
- export class l {
2
+ import { NetErrorString } from './NetErrorString';
3
+ export class r {
3
4
  o() {
4
5
  return null;
5
6
  }
6
- N(C) {
7
- this.C = C;
7
+ P(D) {
8
+ this.D = D;
8
9
  }
9
- async O(r) {
10
+ async Q(t) {
10
11
  return false;
11
12
  }
12
- async P() {
13
+ async R() {
13
14
  return false;
14
15
  }
15
- async c(d) {
16
- const e = new WebSocket(d);
17
- return new Promise((f, i) => {
18
- e.onerror = (k) => {
19
- i(new Error('WebSocket error'));
16
+ async c(e) {
17
+ const f = new WebSocket(e);
18
+ return new Promise((d, i) => {
19
+ f.onerror = (k) => {
20
+ i(new Error(NetErrorString.m));
20
21
  };
21
- e.onopen = () => {
22
- f(this.a9(e, true));
22
+ f.onopen = () => {
23
+ d(this.a4(f, true));
23
24
  };
24
25
  });
25
26
  }
26
- a9 = (e, q) => {
27
- const b = new m(e);
28
- const { conn, D, n } = this.C(b, q);
29
- e.onmessage = (j) => {
27
+ a4 = (f, q) => {
28
+ const b = new s(f);
29
+ const { conn, E, n } = this.D(b, q);
30
+ f.onmessage = (j) => {
30
31
  j.data.arrayBuffer().then((buff) => {
31
- D(new Uint8Array(buff));
32
+ E(new Uint8Array(buff));
32
33
  });
33
34
  };
34
- e.onerror = (k) => {
35
- n(new Error('WebSocket error'));
35
+ f.onerror = (k) => {
36
+ n(new Error(NetErrorString.m));
36
37
  };
37
- e.onclose = (j) => {
38
+ f.onclose = (j) => {
38
39
  if (j.code === 1000) {
39
40
  n();
40
41
  }
@@ -44,13 +45,13 @@ export class l {
44
45
  };
45
46
  return conn;
46
47
  };
47
- C(a, s) {
48
+ D(a, u) {
48
49
  throw new Error('Need to call "setConnWrapperMaker" before using');
49
50
  }
50
51
  }
51
- class m {
52
- constructor(e) {
53
- this.g = e;
52
+ class s {
53
+ constructor(f) {
54
+ this.g = f;
54
55
  }
55
56
  get localAddress() {
56
57
  return;
@@ -67,18 +68,18 @@ class m {
67
68
  get remotePort() {
68
69
  return;
69
70
  }
70
- async I(buff) {
71
+ async N(buff) {
71
72
  if (this.g) {
72
73
  return this.g.send(buff);
73
74
  }
74
- throw new Error('Invalid socket');
75
+ throw new Error(NetErrorString.l);
75
76
  }
76
77
  async p(h) {
77
78
  if (this.g) {
78
79
  const buff = y(h);
79
80
  return this.g.send(buff);
80
81
  }
81
- throw new Error('Invalid socket');
82
+ throw new Error(NetErrorString.l);
82
83
  }
83
84
  async close(err) {
84
85
  const { g } = this;
@@ -94,7 +95,7 @@ class m {
94
95
  }
95
96
  }
96
97
  }
97
- J() {
98
+ O() {
98
99
  return !this.g;
99
100
  }
100
101
  g;
@@ -1,6 +1,6 @@
1
1
  export class g {
2
- constructor(d) {
3
- this.a1 = d;
2
+ constructor(e) {
3
+ this.a1 = e;
4
4
  }
5
5
  get id() {
6
6
  return this.a?.id ?? -1;
@@ -49,16 +49,16 @@ export class g {
49
49
  await this.c();
50
50
  }
51
51
  }
52
- aa() {
52
+ a5() {
53
53
  this.a = undefined;
54
54
  }
55
55
  async c() {
56
56
  let { p } = this;
57
57
  if (!p) {
58
- p = this.p = new Promise((f, i) => {
58
+ p = this.p = new Promise((d, i) => {
59
59
  this.a1().then((conn) => {
60
60
  if (conn) {
61
- f(conn);
61
+ d(conn);
62
62
  this.a = conn;
63
63
  this.p = undefined;
64
64
  }
@@ -0,0 +1,14 @@
1
+ export var NetErrorString;
2
+ (function (NetErrorString) {
3
+ NetErrorString["I"] = "AuthTimeout";
4
+ NetErrorString["a"] = "BadRequest";
5
+ NetErrorString["k"] = "ConnectFailed";
6
+ NetErrorString["a1"] = "ConnectionClosed";
7
+ NetErrorString["b"] = "InvalidConnString";
8
+ NetErrorString["l"] = "InvalidConnection";
9
+ NetErrorString["D"] = "InvalidPackage";
10
+ NetErrorString["g"] = "NotAuthenticated";
11
+ NetErrorString["a2"] = "Timeout";
12
+ NetErrorString["m"] = "UnknownError";
13
+ })(NetErrorString || (NetErrorString = {}));
14
+ //# sourceMappingURL=NetErrorString.js.map
@@ -3,68 +3,68 @@ import { l } from '../common/utils';
3
3
  export class MonitorConn extends ListNode {
4
4
  }
5
5
  export class TimeoutMonitor {
6
- constructor(f, h, g) {
7
- this.R = f;
8
- this.J = h;
9
- this.D = g;
6
+ constructor(e, h, g) {
7
+ this.R = e;
8
+ this.I = h;
9
+ this.E = g;
10
10
  this.o = 0;
11
- this.E = 0;
12
- this.t = [];
13
- if (f === 0) {
11
+ this.F = 0;
12
+ this.r = [];
13
+ if (e === 0) {
14
14
  this.insert = l;
15
15
  this.update = l;
16
16
  this.remove = l;
17
17
  return;
18
18
  }
19
19
  for (let a = 0; a < g; a++) {
20
- this.t.push(new c());
20
+ this.r.push(new c());
21
21
  }
22
22
  }
23
23
  insert(conn) {
24
- if (!this.E) {
24
+ if (!this.F) {
25
25
  this.S = setInterval(this.a2, this.R);
26
26
  }
27
- this.E++;
28
- this.t[this.o].Q(conn);
27
+ this.F++;
28
+ this.r[this.o].Q(conn);
29
29
  }
30
30
  update(conn) {
31
31
  conn.remove();
32
- this.t[this.o].Q(conn);
32
+ this.r[this.o].Q(conn);
33
33
  }
34
34
  remove(conn) {
35
35
  conn.remove();
36
- this.E--;
37
- if (!this.E) {
36
+ this.F--;
37
+ if (!this.F) {
38
38
  clearInterval(this.S);
39
39
  }
40
40
  }
41
41
  a2 = () => {
42
- const { J, D, t } = this;
42
+ const { I, E, r } = this;
43
43
  this.o++;
44
- if (this.o === D) {
44
+ if (this.o === E) {
45
45
  this.o = 0;
46
46
  }
47
- if (J) {
48
- let d = this.o + J;
49
- if (d >= D) {
50
- d -= D;
47
+ if (I) {
48
+ let d = this.o + I;
49
+ if (d >= E) {
50
+ d -= E;
51
51
  }
52
- const b = t[d];
53
- for (let node = b.e; !b.P(node); node = node.getNext()) {
52
+ const b = r[d];
53
+ for (let node = b.f; !b.P(node); node = node.getNext()) {
54
54
  node.keepAlive();
55
55
  }
56
56
  }
57
- const b = t[this.o];
58
- for (let node = b.e; !b.P(node); node = node.getNext()) {
57
+ const b = r[this.o];
58
+ for (let node = b.f; !b.P(node); node = node.getNext()) {
59
59
  node.timeout();
60
60
  }
61
61
  };
62
62
  R;
63
- J;
64
- D;
65
- o;
63
+ I;
66
64
  E;
65
+ o;
66
+ F;
67
67
  S;
68
- t;
68
+ r;
69
69
  }
70
70
  //# sourceMappingURL=TimeoutMonitor.js.map
@@ -1,94 +1,92 @@
1
1
  import { y, l } from '../common/utils';
2
+ import { NetErrorString } from './NetErrorString';
2
3
  import { MonitorConn } from './TimeoutMonitor';
3
- export class t {
4
- constructor(C, w) {
4
+ export class v {
5
+ constructor(F, w) {
5
6
  const { responsePkgType, timeoutMonitor, makePkgBuff, parsePkgBuff } = w;
6
7
  this.responsePkgType = responsePkgType;
7
- this.context = undefined;
8
- this.F = undefined;
9
- this.G = undefined;
10
- this.u = 0;
11
- this.v = new Map();
12
- this.e = new Map();
8
+ this.s = 0;
9
+ this.t = new Map();
10
+ this.f = new Map();
13
11
  this.L = new Map();
14
12
  this.T = makePkgBuff;
15
13
  this.U = parsePkgBuff;
16
- this.A = C;
17
- this.K = timeoutMonitor;
18
- const Q = this;
19
- Q.$ = this.a3;
20
- const s = [];
21
- this.T(responsePkgType, 0x200000, s);
14
+ this.A = F;
15
+ this.J = timeoutMonitor;
16
+ const S = this;
17
+ S.$ = this.a7;
18
+ const u = [];
19
+ this.T(responsePkgType, 0x200000, u);
22
20
  this.V = {
23
21
  makePkgBuff: makePkgBuff,
24
22
  responsePkgType: responsePkgType,
25
- s: y(s),
23
+ u: y(u),
26
24
  };
27
- this.e.set(responsePkgType, Q);
28
- this.A.N((b, q) => {
25
+ this.f.set(responsePkgType, S);
26
+ this.A.P((b, q) => {
29
27
  do {
30
- this.u++;
31
- } while (this.v.has(this.u & 0x1fffff));
32
- const conn = new x(this.V, b, this.u & 0x1fffff);
33
- this.v.set(conn.id, conn);
34
- this.K?.insert(conn);
28
+ this.s++;
29
+ } while (this.t.has(this.s & 0x1fffff));
30
+ const conn = new x(this.V, b, this.s & 0x1fffff);
31
+ this.t.set(conn.id, conn);
32
+ this.J?.insert(conn);
35
33
  const g = {
36
34
  conn,
37
- D: (buff) => this.a4(conn, buff),
38
- n: (err) => this.a5(conn, err),
35
+ E: (buff) => this.a8(conn, buff),
36
+ n: (err) => this.a9(conn, err),
39
37
  };
40
- this.F?.(this, conn, !!q);
38
+ this.K?.(this, conn, !!q);
41
39
  return g;
42
40
  });
43
41
  }
44
42
  responsePkgType;
45
43
  context;
46
- F;
47
- G;
44
+ K;
45
+ B;
48
46
  o() {
49
47
  return this.A.o();
50
48
  }
51
- Z(z) {
52
- return this.v.get(z);
49
+ a3(z) {
50
+ return this.t.get(z);
53
51
  }
54
- c(d) {
55
- return this.A.c(d);
52
+ c(e) {
53
+ return this.A.c(e);
56
54
  }
57
- async a0() {
55
+ async a4() {
58
56
  do {
59
- this.u++;
60
- } while (this.v.has(this.u & 0x1fffff));
61
- const conn = new a6(this.u & 0x1fffff, this);
62
- this.v.set(conn.id, conn);
57
+ this.s++;
58
+ } while (this.t.has(this.s & 0x1fffff));
59
+ const conn = new aa(this.s & 0x1fffff, this);
60
+ this.t.set(conn.id, conn);
63
61
  return conn;
64
62
  }
65
- async a1(d) {
66
- return this.A.O(d);
63
+ async a5(e) {
64
+ return this.A.Q(e);
67
65
  }
68
- async a2() {
69
- return this.A.P();
66
+ async a6() {
67
+ return this.A.R();
70
68
  }
71
- a7(conn, message) {
69
+ ab(conn, message) {
72
70
  const pkgType = message.constructor.pkgType;
73
- const handler = this.e.get(pkgType);
71
+ const handler = this.f.get(pkgType);
74
72
  if (handler) {
75
73
  return handler?.r(conn, message);
76
74
  }
77
- throw new Error('Invalid package');
75
+ throw new Error(NetErrorString.D);
78
76
  }
79
- a8(conn, request) {
77
+ ac(conn, request) {
80
78
  const pkgType = request.constructor.pkgType;
81
- const handler = this.e.get(pkgType);
79
+ const handler = this.f.get(pkgType);
82
80
  if (handler) {
83
81
  return handler?.r(conn, request);
84
82
  }
85
- throw new Error('Invalid package');
83
+ throw new Error(NetErrorString.D);
86
84
  }
87
85
  registerError(pkgType, wrapperCtor) {
88
86
  wrapperCtor.registerPkgType(pkgType);
89
87
  this.L.set(pkgType, wrapperCtor);
90
- const a9 = this.e.get(this.responsePkgType);
91
- this.e.set(pkgType, a9);
88
+ const ad = this.f.get(this.responsePkgType);
89
+ this.f.set(pkgType, ad);
92
90
  }
93
91
  registerMessage(pkgType, wrapperCtor) {
94
92
  wrapperCtor.registerPkgType(pkgType);
@@ -101,10 +99,10 @@ export class t {
101
99
  if (typeof pkgType !== typeof this.responsePkgType) {
102
100
  throw new Error(`Wrapper ${handler.m} has an incompatible pkgType ${typeof pkgType}`);
103
101
  }
104
- if (this.e.has(pkgType)) {
102
+ if (this.f.has(pkgType)) {
105
103
  throw new Error(`Wrapper ${handler.m} is already handled by another handler`);
106
104
  }
107
- this.e.set(pkgType, handler);
105
+ this.f.set(pkgType, handler);
108
106
  return handler;
109
107
  }
110
108
  handleRequestWith(handler) {
@@ -112,72 +110,70 @@ export class t {
112
110
  if (typeof pkgType !== typeof this.responsePkgType) {
113
111
  throw new Error(`Wrapper ${handler.m} has an incompatible pkgType ${typeof pkgType}`);
114
112
  }
115
- if (this.e.has(pkgType)) {
113
+ if (this.f.has(pkgType)) {
116
114
  throw new Error(`Wrapper ${handler.m} is already handled by another handler`);
117
115
  }
118
- this.e.set(pkgType, handler);
116
+ this.f.set(pkgType, handler);
119
117
  return handler;
120
118
  }
121
- ak(handler) {
119
+ ao(handler) {
122
120
  const pkgType = handler.pkgType;
123
- const aa = this.e.get(pkgType);
124
- if (aa === handler) {
125
- this.e.delete(pkgType);
121
+ const ae = this.f.get(pkgType);
122
+ if (ae === handler) {
123
+ this.f.delete(pkgType);
126
124
  return true;
127
125
  }
128
126
  return false;
129
127
  }
130
- a4(conn, buff) {
131
- this.K?.update(conn);
128
+ a8(conn, buff) {
129
+ this.J?.update(conn);
132
130
  const a = this.U(buff);
133
- const handler = this.e.get(a.pkgType);
131
+ const handler = this.f.get(a.pkgType);
134
132
  if (handler) {
135
133
  handler.$(conn, a);
136
134
  return;
137
135
  }
138
- conn.close(new Error('Invalid package'));
136
+ conn.close(new Error(NetErrorString.D));
139
137
  }
140
- a5(conn, err) {
138
+ a9(conn, err) {
141
139
  const z = conn.id;
142
- this.v.delete(z);
143
- this.K?.remove(conn);
140
+ this.t.delete(z);
141
+ this.J?.remove(conn);
144
142
  conn.n(err);
145
- this.G?.(this, conn, conn.b.J(), err);
143
+ this.B?.(this, conn, conn.b.O(), err);
146
144
  }
147
- a3(conn, a) {
145
+ a7(conn, a) {
148
146
  const { buff, pkgType, requestId, bodyOffset } = a;
149
147
  if (pkgType === this.responsePkgType) {
150
148
  const h = buff.subarray(bodyOffset);
151
- conn.W(requestId, h);
149
+ conn.X(requestId, h);
152
150
  }
153
151
  else {
154
- const S = this.L.get(pkgType);
155
- if (S) {
152
+ const Y = this.L.get(pkgType);
153
+ if (Y) {
156
154
  const h = buff.subarray(bodyOffset);
157
- const ab = new S(h, true);
158
- conn.ac(requestId, ab);
155
+ const af = new Y(h, true);
156
+ conn.ag(requestId, af);
159
157
  }
160
158
  }
161
159
  }
162
160
  V;
163
- u;
161
+ s;
164
162
  T;
165
163
  U;
166
164
  A;
167
- v;
168
- e;
165
+ t;
166
+ f;
169
167
  L;
170
- K;
168
+ J;
171
169
  }
172
170
  class x extends MonitorConn {
173
171
  constructor(w, b, id) {
174
172
  super();
175
- this.context = undefined;
176
173
  this.id = id;
177
174
  this.b = b;
178
- this.B = w;
179
- this.j = undefined;
180
- this.X = 0;
175
+ this.C = w;
176
+ this.Z = 0;
181
177
  }
182
178
  context;
183
179
  id;
@@ -200,99 +196,98 @@ class x extends MonitorConn {
200
196
  sendMessage(message) {
201
197
  const pkgType = message.constructor.pkgType;
202
198
  const encoded = [message.buff];
203
- this.B.makePkgBuff(pkgType, 0, encoded);
199
+ this.C.makePkgBuff(pkgType, 0, encoded);
204
200
  return this.b.p(encoded);
205
201
  }
206
202
  sendRequest(request) {
207
- this.j = new Map();
208
- this.sendRequest = this.Y;
209
- this.W = this.ad;
210
- this.n = this.ae;
211
- return this.Y(request);
203
+ this.k = new Map();
204
+ this.sendRequest = this.a0;
205
+ this.X = this.ah;
206
+ this.n = this.ai;
207
+ return this.a0(request);
212
208
  }
213
209
  sendErrorResponse(error, requestId) {
214
210
  const pkgType = error.constructor.pkgType;
215
211
  const encoded = [error.buff];
216
- this.B.makePkgBuff(pkgType, requestId, encoded);
212
+ this.C.makePkgBuff(pkgType, requestId, encoded);
217
213
  return this.b.p(encoded);
218
214
  }
219
215
  sendResponse(request, requestId) {
220
216
  const encoded = [request.respBuff];
221
- const { makePkgBuff, responsePkgType } = this.B;
217
+ const { makePkgBuff, responsePkgType } = this.C;
222
218
  makePkgBuff(responsePkgType, requestId, encoded);
223
219
  return this.b.p(encoded);
224
220
  }
225
221
  async close(err) {
226
222
  await this.b.close(err);
227
223
  }
228
- W(requestId, al) {
224
+ X(requestId, ap) {
229
225
  if (requestId === 0x200000 && this.context === undefined) {
230
- this.close(new Error('Authenticating timeout'));
226
+ this.close(new Error(NetErrorString.I));
231
227
  }
232
228
  }
233
- ac(requestId, error) {
234
- const k = this.j.get(requestId);
235
- if (k) {
236
- this.j.delete(requestId);
237
- return k.i(error);
229
+ ag(requestId, error) {
230
+ const j = this.k.get(requestId);
231
+ if (j) {
232
+ this.k.delete(requestId);
233
+ return j.i(error);
238
234
  }
239
235
  }
240
236
  keepAlive() {
241
- this.b.I(this.B.s).catch(l);
237
+ this.b.N(this.C.u).catch(l);
242
238
  }
243
239
  timeout() {
244
- this.close(new Error('Connection timeout'));
240
+ this.close(new Error(NetErrorString.a2));
245
241
  }
246
- n(af) {
242
+ n(aj) {
247
243
  }
248
- async Y(request) {
249
- const requestId = (this.X++) & 0x1fffff;
244
+ async a0(request) {
245
+ const requestId = (this.Z++) & 0x1fffff;
250
246
  const pkgType = request.constructor.pkgType;
251
247
  const encoded = [request.buff];
252
- this.B.makePkgBuff(pkgType, requestId, encoded);
253
- const ag = new Promise((f, i) => {
254
- const ah = { f, i };
255
- this.j.set(requestId, ah);
248
+ this.C.makePkgBuff(pkgType, requestId, encoded);
249
+ const ak = new Promise((d, i) => {
250
+ const al = { d, i };
251
+ this.k.set(requestId, al);
256
252
  this.b.p(encoded).catch((err) => {
257
- this.j.delete(requestId);
253
+ this.k.delete(requestId);
258
254
  i(err);
259
255
  });
260
256
  });
261
- request.respBuff = await ag;
257
+ request.respBuff = await ak;
262
258
  }
263
- ad(requestId, h) {
264
- const k = this.j.get(requestId);
265
- if (k) {
266
- this.j.delete(requestId);
267
- k.f(h);
259
+ ah(requestId, h) {
260
+ const j = this.k.get(requestId);
261
+ if (j) {
262
+ this.k.delete(requestId);
263
+ j.d(h);
268
264
  return;
269
265
  }
270
266
  if (requestId === 0x200000 && this.context === undefined) {
271
- this.close(new Error('Authenticating timeout'));
267
+ this.close(new Error(NetErrorString.I));
272
268
  }
273
269
  }
274
- ae(err) {
275
- const H = this.j;
270
+ ai(err) {
271
+ const H = this.k;
276
272
  if (H.size > 0) {
277
273
  if (!err) {
278
- err = new Error('Connection is closed');
274
+ err = new Error(NetErrorString.a1);
279
275
  }
280
- for (const [requestId, k] of H) {
276
+ for (const [requestId, j] of H) {
281
277
  H.delete(requestId);
282
- k.i(err);
278
+ j.i(err);
283
279
  }
284
280
  }
285
- this.j = undefined;
281
+ this.k = undefined;
286
282
  }
287
- B;
288
- j;
289
- X;
283
+ C;
284
+ k;
285
+ Z;
290
286
  }
291
- class a6 {
292
- constructor(id, ai) {
293
- this.context = undefined;
287
+ class aa {
288
+ constructor(id, am) {
294
289
  this.id = id;
295
- this.M = ai;
290
+ this.M = am;
296
291
  }
297
292
  context;
298
293
  id;
@@ -304,18 +299,18 @@ class a6 {
304
299
  return 'Local';
305
300
  }
306
301
  async sendMessage(message) {
307
- return this.M.a7(this, message);
302
+ return this.M.ab(this, message);
308
303
  }
309
304
  async sendRequest(request) {
310
- return this.M.a8(this, request);
305
+ return this.M.ac(this, request);
311
306
  }
312
- sendErrorResponse(am, aj) {
307
+ sendErrorResponse(aq, an) {
313
308
  throw null;
314
309
  }
315
- sendResponse(_request, aj) {
310
+ sendResponse(_request, an) {
316
311
  throw null;
317
312
  }
318
- async close(af) {
313
+ async close(aj) {
319
314
  }
320
315
  M;
321
316
  }
@@ -1,12 +1,12 @@
1
1
  import { j, l, m } from '../common/varUintOps';
2
- export const o = (pkgType, requestId, encoded) => {
2
+ export const p = (pkgType, requestId, encoded) => {
3
3
  const i = [requestId, pkgType];
4
4
  const b = j(i);
5
5
  const a = new Uint8Array(b);
6
6
  m(i, a);
7
7
  encoded.push(a);
8
8
  };
9
- export const p = (buff) => {
9
+ export const s = (buff) => {
10
10
  const { h: [requestId, pkgType], k: bodyOffset } = l(2, buff);
11
11
  const result = { buff, pkgType, requestId, bodyOffset };
12
12
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "justrun-ws",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "scripts": {
5
5
  "start": "webpack serve"
6
6
  },