justrun-ws 0.1.2 → 0.2.0

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.
@@ -1,91 +1,88 @@
1
- import { a, c } from './common';
2
- export class SimpleMessageHandler {
3
- constructor(wrapperCtor, d, e = true) {
4
- this.g = wrapperCtor;
5
- this.m = d;
6
- this.n = e;
1
+ import { c, b } from './common';
2
+ export class j {
3
+ constructor(wrapperCtor, d, f = true) {
4
+ this.l = wrapperCtor;
5
+ this.x = d;
6
+ this.y = f;
7
7
  }
8
8
  get pkgType() {
9
- return this.g.pkgType;
9
+ return this.l.pkgType;
10
10
  }
11
- get pkgName() {
12
- return this.g.name;
11
+ get m() {
12
+ return this.l.name;
13
13
  }
14
- async run(conn, parseResult) {
15
- const { buff, bodyOffset } = parseResult;
16
- const b = buff.subarray(bodyOffset);
17
- const message = new this.g(b, true);
18
- if (conn.context !== undefined || !this.n) {
14
+ async $(conn, a) {
15
+ const { buff, bodyOffset } = a;
16
+ const h = buff.subarray(bodyOffset);
17
+ const message = new this.l(h, true);
18
+ if (conn.context !== undefined || !this.y) {
19
19
  try {
20
- await this.m(conn, message);
20
+ await this.x(conn, message);
21
21
  }
22
22
  catch (err) {
23
23
  if (!err.isError) {
24
- this.wrapUncaughtError(conn, err);
24
+ b(conn, err);
25
25
  }
26
26
  }
27
27
  }
28
28
  else {
29
- this.wrapUncaughtError(conn, a);
29
+ b(conn, c);
30
30
  }
31
31
  if (conn.context === undefined) {
32
32
  await conn.close();
33
33
  }
34
34
  }
35
- async runLocal(conn, message) {
36
- if (conn.context !== undefined || !this.n) {
35
+ async r(conn, message) {
36
+ if (conn.context !== undefined || !this.y) {
37
37
  try {
38
- return await this.m(conn, message);
38
+ return await this.x(conn, message);
39
39
  }
40
40
  catch (err) {
41
41
  if (!err.isError) {
42
- this.wrapUncaughtError(conn, err);
42
+ b(conn, err);
43
43
  }
44
44
  }
45
45
  }
46
46
  else {
47
- this.wrapUncaughtError(conn, a);
47
+ b(conn, c);
48
48
  }
49
49
  }
50
- wrapUncaughtError(conn, err) {
51
- return c(conn, err);
52
- }
53
- g;
54
- m;
55
- n;
50
+ l;
51
+ x;
52
+ y;
56
53
  }
57
- export class h {
58
- constructor(wrapperCtor, d, e = true) {
59
- this.g = wrapperCtor;
60
- this.m = d;
61
- this.n = e;
54
+ export class n {
55
+ constructor(wrapperCtor, d, f = true) {
56
+ this.l = wrapperCtor;
57
+ this.x = d;
58
+ this.y = f;
62
59
  }
63
60
  get pkgType() {
64
- return this.g.pkgType;
61
+ return this.l.pkgType;
65
62
  }
66
- get pkgName() {
67
- return this.g.name;
63
+ get m() {
64
+ return this.l.name;
68
65
  }
69
- async run(conn, parseResult) {
70
- const { buff, requestId, bodyOffset } = parseResult;
71
- const b = buff.subarray(bodyOffset);
72
- const request = new this.g(b, true);
66
+ async $(conn, a) {
67
+ const { buff, requestId, bodyOffset } = a;
68
+ const h = buff.subarray(bodyOffset);
69
+ const request = new this.l(h, true);
73
70
  let error;
74
- if (conn.context !== undefined || !this.n) {
71
+ if (conn.context !== undefined || !this.y) {
75
72
  try {
76
- await this.m(conn, request);
73
+ await this.x(conn, request);
77
74
  }
78
75
  catch (err) {
79
76
  if (err.isError) {
80
77
  error = err;
81
78
  }
82
79
  else {
83
- error = this.wrapUncaughtError(conn, err);
80
+ error = b(conn, err);
84
81
  }
85
82
  }
86
83
  }
87
84
  else {
88
- error = this.wrapUncaughtError(conn, a);
85
+ error = b(conn, c);
89
86
  }
90
87
  try {
91
88
  if (!error) {
@@ -102,27 +99,24 @@ export class h {
102
99
  await conn.close(err);
103
100
  }
104
101
  }
105
- async runLocal(conn, request) {
106
- if (conn.context !== undefined || !this.n) {
102
+ async r(conn, request) {
103
+ if (conn.context !== undefined || !this.y) {
107
104
  try {
108
- return await this.m(conn, request);
105
+ return await this.x(conn, request);
109
106
  }
110
107
  catch (err) {
111
108
  if (err.isError) {
112
109
  throw err;
113
110
  }
114
111
  else {
115
- throw this.wrapUncaughtError(conn, err);
112
+ throw b(conn, err);
116
113
  }
117
114
  }
118
115
  }
119
- throw this.wrapUncaughtError(conn, a);
120
- }
121
- wrapUncaughtError(conn, err) {
122
- return c(conn, err);
116
+ throw b(conn, c);
123
117
  }
124
- g;
125
- m;
126
- n;
118
+ l;
119
+ x;
120
+ y;
127
121
  }
128
122
  //# sourceMappingURL=SimpleHandler.js.map
@@ -1,14 +1,11 @@
1
1
  import { JsonError } from '../net/JsonPackageWrapper';
2
- export class f extends JsonError {
2
+ export class CommonError extends JsonError {
3
3
  }
4
- export const a = { message: 'Connection is not authenticated' };
5
- let e = (b, err) => {
6
- return new f(err.message);
4
+ export const c = new Error('Connection is not authenticated');
5
+ export let b = (a, err) => {
6
+ return new CommonError(err.message);
7
7
  };
8
- export const c = (conn, err) => {
9
- return e(conn, err);
10
- };
11
- export const h = (handler) => {
12
- e = handler;
8
+ export const handleUncaughtErrorWith = (handler) => {
9
+ b = handler;
13
10
  };
14
11
  //# sourceMappingURL=common.js.map
package/lib/index.d.ts CHANGED
@@ -43,34 +43,6 @@ export declare abstract class RequestWrapper<RequestT, ResponseT> extends PkgWra
43
43
  export type ErrorWrapperCtor<ErrorT, WrapperT extends ErrorWrapper<ErrorT> = ErrorWrapper<ErrorT>> = new (error: ErrorT | Uint8Array, needParse?: true) => WrapperT;
44
44
  export type MessageWrapperCtor<MessageT, WrapperT extends MessageWrapper<MessageT> = MessageWrapper<MessageT>> = new (message: MessageT | Uint8Array, needParse?: true) => WrapperT;
45
45
  export type RequestWrapperCtor<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT> = RequestWrapper<RequestT, ResponseT>> = new (request: RequestT | Uint8Array, needParse?: true, _response?: ResponseT) => WrapperT;
46
- export interface AddressInfo {
47
- address: string;
48
- family: string;
49
- port: number;
50
- }
51
- export interface IRawPkgConn {
52
- readonly localAddress?: string;
53
- readonly localPort?: number;
54
- readonly remoteAddress?: string;
55
- readonly remoteFamily?: string;
56
- readonly remotePort?: number;
57
- sendPkgBuff(buff: Uint8Array): Promise<void>;
58
- sendPkgBuffV(buffVector: Uint8Array[]): Promise<void>;
59
- close(err?: Error): Promise<void>;
60
- hadClosed(): boolean;
61
- }
62
- export interface IPkgConnWrapper<ConnWrapperT> {
63
- readonly conn: ConnWrapperT;
64
- onPkgBuff: (buff: Uint8Array) => void;
65
- onClose: (err?: Error) => void;
66
- }
67
- export interface INet<ConnWrapperT> {
68
- address(): AddressInfo | null;
69
- setConnWrapperMaker(makeWrapper: (conn: IRawPkgConn, isActive?: boolean) => IPkgConnWrapper<ConnWrapperT>): void;
70
- startListen(connStr?: string): Promise<boolean>;
71
- stopListen(): Promise<boolean>;
72
- connect(connStr: string): Promise<ConnWrapperT>;
73
- }
74
46
  export interface IConn<ConnContextT = void> {
75
47
  context?: ConnContextT | undefined;
76
48
  readonly id: number;
@@ -85,90 +57,12 @@ export interface IConn<ConnContextT = void> {
85
57
  sendResponse<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>, requestId: number): Promise<void>;
86
58
  close(err?: Error): Promise<void>;
87
59
  }
88
- export interface IPkgHub<ConnContextT = void, HubContextT = void> {
89
- context?: HubContextT | undefined;
90
- address(): AddressInfo | null;
91
- getConn(connId: number): IConn<ConnContextT> | undefined;
92
- connect(connStr: string): Promise<IConn<ConnContextT>>;
93
- connectLocal(): Promise<IConn<ConnContextT>>;
94
- startServer(connStr?: string): Promise<boolean>;
95
- stopServer(): Promise<boolean>;
96
- }
97
60
  export type ParseResult<PkgTypeT extends number | string> = {
98
61
  buff: Uint8Array;
99
62
  pkgType: PkgTypeT;
100
63
  requestId: number;
101
64
  bodyOffset: number;
102
65
  };
103
- export interface IPkgHandler<PkgTypeT extends number | string, ConnContextT = void> {
104
- get pkgType(): PkgTypeT;
105
- get pkgName(): string;
106
- run(conn: IConn<ConnContextT>, parseResult: ParseResult<PkgTypeT>): void | Promise<void>;
107
- wrapUncaughtError(conn: IConn<unknown>, err: Error): ErrorWrapper<unknown>;
108
- }
109
- export interface IMessageHandler<PkgTypeT extends number | string, MessageT, WrapperT extends MessageWrapper<MessageT>, ConnContextT = void> extends IPkgHandler<PkgTypeT, ConnContextT> {
110
- runLocal(conn: IConn<ConnContextT>, message: WrapperT): void | Promise<void>;
111
- }
112
- export interface IRequestHandler<PkgTypeT extends number | string, RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>, ConnContextT = void> extends IPkgHandler<PkgTypeT, ConnContextT> {
113
- runLocal(conn: IConn<ConnContextT>, request: WrapperT): void | Promise<void>;
114
- }
115
- export type HandleFunc<WrapperT, ConnContextT> = (conn: IConn<ConnContextT>, wrapper: WrapperT) => void | Promise<void>;
116
- export declare class SimpleMessageHandler<PkgTypeT extends number | string, MessageT, WrapperT extends MessageWrapper<MessageT>, ConnContextT> implements IMessageHandler<PkgTypeT, MessageT, WrapperT, ConnContextT> {
117
- constructor(wrapperCtor: MessageWrapperCtor<MessageT, WrapperT>, handleFunc: HandleFunc<WrapperT, ConnContextT>, checkContext?: boolean);
118
- get pkgType(): PkgTypeT;
119
- get pkgName(): string;
120
- run(conn: IConn<ConnContextT>, parseResult: ParseResult<PkgTypeT>): Promise<void>;
121
- runLocal(conn: IConn<ConnContextT>, message: WrapperT): Promise<void>;
122
- wrapUncaughtError(conn: IConn<unknown>, err: Error): ErrorWrapper<unknown>;
123
- private _wrapperCtor;
124
- private _handleFunc;
125
- private _checkContext;
126
- }
127
- export declare class BrowserWsNet<ConnWrapperT> implements INet<ConnWrapperT> {
128
- address(): AddressInfo | null;
129
- setConnWrapperMaker(makeWrapper: (conn: IRawPkgConn, isActive?: boolean) => IPkgConnWrapper<ConnWrapperT>): void;
130
- startListen(_connStr?: string): Promise<boolean>;
131
- stopListen(): Promise<boolean>;
132
- connect(connStr: string): Promise<ConnWrapperT>;
133
- private setupConn;
134
- private makeWrapper;
135
- }
136
- export declare const makeNumTypePkgBuff: (pkgType: number, requestId: number, encoded: Uint8Array[]) => void;
137
- export declare const parseNumTypePkgBuff: (buff: Uint8Array) => ParseResult<number>;
138
- export declare abstract class JsonError<ErrorT> extends ErrorWrapper<ErrorT> {
139
- protected encode(data: ErrorT): Uint8Array;
140
- protected decode(buffer: Uint8Array): ErrorT;
141
- }
142
- export declare abstract class JsonMessage<MessageT> extends MessageWrapper<MessageT> {
143
- protected encode(data: MessageT): Uint8Array;
144
- protected decode(buffer: Uint8Array): MessageT;
145
- }
146
- export declare abstract class JsonRequest<RequestT, ResponseT> extends RequestWrapper<RequestT, ResponseT> {
147
- protected encode(data: RequestT): Uint8Array;
148
- protected decode(buffer: Uint8Array): RequestT;
149
- protected encodeResponse(response: ResponseT): Uint8Array;
150
- protected decodeResponse(buffer: Uint8Array): ResponseT;
151
- }
152
- export declare class LazyConn<ConnContextT> implements IConn<ConnContextT> {
153
- constructor(connectFunc: () => Promise<IConn<ConnContextT> | undefined>);
154
- get id(): number;
155
- get context(): ConnContextT | undefined;
156
- set context(val: ConnContextT | undefined);
157
- localAddress?: string | undefined;
158
- localPort?: number | undefined;
159
- remoteAddress?: string | undefined;
160
- remoteFamily?: string | undefined;
161
- remotePort?: number | undefined;
162
- sendErrorResponse<ErrorT>(error: ErrorWrapper<ErrorT>, requestId: number): Promise<void>;
163
- sendResponse<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>, requestId: number): Promise<void>;
164
- sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
165
- sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<void>;
166
- close(err?: Error): Promise<void>;
167
- private connect;
168
- private _connectFunc;
169
- private _conn?;
170
- private _waitingConn?;
171
- }
172
66
  declare class ListNode {
173
67
  constructor();
174
68
  getPrev<SelfT extends ListNode>(this: SelfT): SelfT;
@@ -203,38 +97,57 @@ export type TypedPkgHubOpts<PkgTypeT extends number | string> = {
203
97
  makePkgBuff: (pkgType: PkgTypeT, requestId: number, encoded: Uint8Array[]) => void;
204
98
  parsePkgBuff: (buff: Uint8Array) => ParseResult<PkgTypeT>;
205
99
  };
206
- export declare class TypedPkgHub<PkgTypeT extends number | string, ConnContextT = void, HubContextT = void> implements IPkgHub<ConnContextT, HubContextT> {
207
- constructor(net: INet<IConn<ConnContextT>>, opts: TypedPkgHubOpts<PkgTypeT>);
208
- readonly responsePkgType: PkgTypeT;
209
- context?: HubContextT | undefined;
210
- onConnOpen?: (pkgHub: IPkgHub<ConnContextT, HubContextT>, conn: IConn<ConnContextT>, activeOpen: boolean) => void;
211
- onConnClose?: (pkgHub: IPkgHub<ConnContextT, HubContextT>, conn: IConn<ConnContextT>, activeClose: boolean, err?: Error) => void;
212
- address(): AddressInfo | null;
213
- getConn(connId: number): IConn<ConnContextT> | undefined;
214
- connect(connStr: string): Promise<IConn<ConnContextT>>;
215
- connectLocal(): Promise<IConn<ConnContextT>>;
216
- startServer(connStr?: string): Promise<boolean>;
217
- stopServer(): Promise<boolean>;
218
- sendMessageLocal<MessageT>(conn: IConn<ConnContextT>, message: MessageWrapper<MessageT>): void | Promise<void>;
219
- sendRequestLocal<RequestT, ResponseT>(conn: IConn<ConnContextT>, request: RequestWrapper<RequestT, ResponseT>): void | Promise<void>;
100
+ export declare abstract class JsonError<ErrorT> extends ErrorWrapper<ErrorT> {
101
+ protected encode(data: ErrorT): Uint8Array;
102
+ protected decode(buffer: Uint8Array): ErrorT;
103
+ }
104
+ export declare abstract class JsonMessage<MessageT> extends MessageWrapper<MessageT> {
105
+ protected encode(data: MessageT): Uint8Array;
106
+ protected decode(buffer: Uint8Array): MessageT;
107
+ }
108
+ export declare abstract class JsonRequest<RequestT, ResponseT> extends RequestWrapper<RequestT, ResponseT> {
109
+ protected encode(data: RequestT): Uint8Array;
110
+ protected decode(buffer: Uint8Array): RequestT;
111
+ protected encodeResponse(response: ResponseT): Uint8Array;
112
+ protected decodeResponse(buffer: Uint8Array): ResponseT;
113
+ }
114
+ export declare class CommonError extends JsonError<string> {
115
+ }
116
+ export interface DoneResp<ResultT extends string | number | boolean = boolean> {
117
+ result: ResultT;
118
+ }
119
+ export interface IAuthResp {
120
+ cid: string;
121
+ token: string;
122
+ shard?: number;
123
+ }
124
+ export declare const handleUncaughtErrorWith: (handler: (conn: IConn<unknown>, err: Error) => ErrorWrapper<unknown>) => void;
125
+ export declare const createNumPkgTypeClient: (getConnStr: (shard?: number) => string, timeoutMonitor?: TimeoutMonitor) => WsClient<number>;
126
+ export declare class WsClient<PkgTypeT extends number | string> {
127
+ constructor(getConnStr: (shard?: number) => string, opts: TypedPkgHubOpts<PkgTypeT>);
220
128
  registerError<ErrorT>(pkgType: PkgTypeT, wrapperCtor: ErrorWrapperCtor<ErrorT>): void;
221
129
  registerMessage<MessageT>(pkgType: PkgTypeT, wrapperCtor: MessageWrapperCtor<MessageT>): void;
222
130
  registerRequest<RequestT, ResponseT>(pkgType: PkgTypeT, wrapperCtor: RequestWrapperCtor<RequestT, ResponseT>): void;
223
- handleMessageWith<MessageT, WrapperT extends MessageWrapper<MessageT>>(handler: IMessageHandler<PkgTypeT, MessageT, WrapperT, ConnContextT>): IPkgHandler<PkgTypeT, ConnContextT>;
224
- handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(handler: IRequestHandler<PkgTypeT, RequestT, ResponseT, WrapperT, ConnContextT>): IPkgHandler<PkgTypeT, ConnContextT>;
225
- removeHandler(handler: IPkgHandler<PkgTypeT, ConnContextT>): boolean;
226
- private connPkgBuffCallback;
227
- private connClosedCallback;
228
- private onResponse;
229
- private _connOpts;
230
- private _nextConnId;
231
- private _makePkgBuff;
232
- private _parsePkgBuff;
233
- private _net;
234
- private _connMap;
235
- private _handlerMap;
236
- private _errorWrapperMap;
237
- private _timeoutMonitor?;
131
+ handleMessageWith<MessageT, WrapperT extends MessageWrapper<MessageT>>(wrapperCtor: MessageWrapperCtor<MessageT, WrapperT>, handler: (message: MessageT) => void | Promise<void>): void;
132
+ handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(wrapperCtor: RequestWrapperCtor<RequestT, ResponseT, WrapperT>, handler: (request: RequestT) => ResponseT | Promise<ResponseT>): void;
133
+ sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
134
+ sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
135
+ sendCustomAuthRequest<RequestT, ResponseT extends IAuthResp>(_request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
136
+ resetAuthState(): void;
137
+ enableAuthenticate(proxyAuthPkgType: PkgTypeT, authStatusCallback: (cid: string) => void, allowAnonymous?: true): void;
138
+ reconnect(delay?: number): void;
139
+ onConnectionStatus(listener: (isOpen: boolean, active: boolean, err?: Error) => void): void;
140
+ private connect;
141
+ private onConnOpen;
142
+ private onConnClose;
143
+ private _pkgHub;
144
+ private _conn;
145
+ private _cid;
146
+ private _connState;
147
+ private _getConnStr;
148
+ private _originConnect;
149
+ private _connectDelay?;
150
+ private _listenerArr?;
238
151
  }
239
152
 
240
153
  export {};
package/lib/index.js CHANGED
@@ -1,9 +1,6 @@
1
- export { SimpleMessageHandler } from './handler/SimpleHandler';
2
- export { BrowserWsNet } from './net/BrowserWsNet';
3
- export { makeNumTypePkgBuff, parseNumTypePkgBuff } from './net/hubPkgSerializer';
1
+ export { CommonError, handleUncaughtErrorWith } from './handler/common';
4
2
  export { JsonError, JsonMessage, JsonRequest } from './net/JsonPackageWrapper';
5
- export { LazyConn } from './net/LazyConn';
6
3
  export { ErrorWrapper, EventWrapper, MessageWrapper, RequestWrapper } from './net/PackageWrapper';
7
4
  export { TimeoutMonitor } from './net/TimeoutMonitor';
8
- export { TypedPkgHub } from './net/TypedPkgHub';
5
+ export { createNumPkgTypeClient, WsClient } from './WsClient';
9
6
  //# sourceMappingURL=index.js.map
@@ -1,53 +1,56 @@
1
- import { l } from '../common/utils';
2
- export class BrowserWsNet {
3
- address() {
1
+ import { y } from '../common/utils';
2
+ export class l {
3
+ o() {
4
4
  return null;
5
5
  }
6
- setConnWrapperMaker(makeWrapper) {
7
- this.makeWrapper = makeWrapper;
6
+ N(C) {
7
+ this.C = C;
8
8
  }
9
- async startListen(_connStr) {
9
+ async O(r) {
10
10
  return false;
11
11
  }
12
- async stopListen() {
12
+ async P() {
13
13
  return false;
14
14
  }
15
- async connect(connStr) {
16
- const c = new WebSocket(connStr);
17
- return new Promise((f, g) => {
18
- c.onerror = (h) => {
19
- g(new Error('WebSocket error'));
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'));
20
20
  };
21
- c.onopen = () => {
22
- f(this.L(c, true));
21
+ e.onopen = () => {
22
+ f(this.a9(e, true));
23
23
  };
24
24
  });
25
25
  }
26
- L = (c, isActive) => {
27
- const a = new i(c);
28
- const { conn, onPkgBuff, onClose } = this.makeWrapper(a, isActive);
29
- c.onmessage = (e) => {
30
- e.data.arrayBuffer().then((buff) => {
31
- onPkgBuff(new Uint8Array(buff));
26
+ a9 = (e, q) => {
27
+ const b = new m(e);
28
+ const { conn, D, n } = this.C(b, q);
29
+ e.onmessage = (j) => {
30
+ j.data.arrayBuffer().then((buff) => {
31
+ D(new Uint8Array(buff));
32
32
  });
33
33
  };
34
- c.onerror = (h) => {
35
- onClose(new Error('WebSocket error'));
34
+ e.onerror = (k) => {
35
+ n(new Error('WebSocket error'));
36
36
  };
37
- c.onclose = (e) => {
38
- if (e.code === 1000) {
39
- onClose();
37
+ e.onclose = (j) => {
38
+ if (j.code === 1000) {
39
+ n();
40
+ }
41
+ else {
42
+ n(new Error(j.reason));
40
43
  }
41
44
  };
42
45
  return conn;
43
46
  };
44
- makeWrapper(b, j) {
47
+ C(a, s) {
45
48
  throw new Error('Need to call "setConnWrapperMaker" before using');
46
49
  }
47
50
  }
48
- class i {
49
- constructor(c) {
50
- this.d = c;
51
+ class m {
52
+ constructor(e) {
53
+ this.g = e;
51
54
  }
52
55
  get localAddress() {
53
56
  return;
@@ -64,36 +67,36 @@ class i {
64
67
  get remotePort() {
65
68
  return;
66
69
  }
67
- async sendPkgBuff(buff) {
68
- if (this.d) {
69
- return this.d.send(buff);
70
+ async I(buff) {
71
+ if (this.g) {
72
+ return this.g.send(buff);
70
73
  }
71
74
  throw new Error('Invalid socket');
72
75
  }
73
- async sendPkgBuffV(buffVector) {
74
- if (this.d) {
75
- const buff = l(buffVector);
76
- return this.d.send(buff);
76
+ async p(h) {
77
+ if (this.g) {
78
+ const buff = y(h);
79
+ return this.g.send(buff);
77
80
  }
78
81
  throw new Error('Invalid socket');
79
82
  }
80
83
  async close(err) {
81
- const { d } = this;
82
- if (d) {
83
- this.d = undefined;
84
+ const { g } = this;
85
+ if (g) {
86
+ this.g = undefined;
84
87
  if (!err) {
85
- if (d.readyState === WebSocket.OPEN) {
86
- d.close(1000);
88
+ if (g.readyState === WebSocket.OPEN) {
89
+ g.close(1000);
87
90
  }
88
91
  }
89
92
  else {
90
- d.close(3000, err.message);
93
+ g.close(3000, err.message);
91
94
  }
92
95
  }
93
96
  }
94
- hadClosed() {
95
- return !this.d;
97
+ J() {
98
+ return !this.g;
96
99
  }
97
- d;
100
+ g;
98
101
  }
99
102
  //# sourceMappingURL=BrowserWsNet.js.map
@@ -1,16 +1,16 @@
1
- export class LazyConn {
2
- constructor(c) {
3
- this.A = c;
1
+ export class g {
2
+ constructor(d) {
3
+ this.a1 = d;
4
4
  }
5
5
  get id() {
6
- return this.b?.id ?? -1;
6
+ return this.a?.id ?? -1;
7
7
  }
8
8
  get context() {
9
- return this.b?.context;
9
+ return this.a?.context;
10
10
  }
11
- set context(a) {
12
- if (this.b) {
13
- this.b.context = a;
11
+ set context(b) {
12
+ if (this.a) {
13
+ this.a.context = b;
14
14
  }
15
15
  }
16
16
  localAddress;
@@ -19,48 +19,59 @@ export class LazyConn {
19
19
  remoteFamily;
20
20
  remotePort;
21
21
  async sendErrorResponse(error, requestId) {
22
- return (this.b ?? await this.connect()).sendErrorResponse(error, requestId);
22
+ return (this.a ?? await this.c()).sendErrorResponse(error, requestId);
23
23
  }
24
24
  async sendResponse(request, requestId) {
25
- return (this.b ?? await this.connect()).sendResponse(request, requestId);
25
+ return (this.a ?? await this.c()).sendResponse(request, requestId);
26
26
  }
27
27
  async sendMessage(message) {
28
- return (this.b ?? await this.connect()).sendMessage(message);
28
+ return (this.a ?? await this.c()).sendMessage(message);
29
29
  }
30
30
  async sendRequest(request) {
31
- return (this.b ?? await this.connect()).sendRequest(request);
31
+ return (this.a ?? await this.c()).sendRequest(request);
32
32
  }
33
33
  async close(err) {
34
- const { b } = this;
35
- if (b) {
36
- this.b = undefined;
37
- await b.close(err);
34
+ const { a } = this;
35
+ if (a) {
36
+ this.a = undefined;
37
+ await a.close(err);
38
38
  return;
39
39
  }
40
- if (this.i) {
41
- await this.i.then((conn) => conn.close(err).then(() => this.b = undefined), () => this.b = undefined);
40
+ if (this.p) {
41
+ await this.p.then((conn) => {
42
+ this.a = undefined;
43
+ conn.close(err);
44
+ }, () => this.a = undefined);
42
45
  }
43
46
  }
44
- async connect() {
45
- let { i } = this;
46
- if (!i) {
47
- i = this.i = new Promise((f, g) => {
48
- this.A().then((conn) => {
47
+ async reconnect() {
48
+ if (!this.a) {
49
+ await this.c();
50
+ }
51
+ }
52
+ aa() {
53
+ this.a = undefined;
54
+ }
55
+ async c() {
56
+ let { p } = this;
57
+ if (!p) {
58
+ p = this.p = new Promise((f, i) => {
59
+ this.a1().then((conn) => {
49
60
  if (conn) {
50
61
  f(conn);
51
- this.b = conn;
52
- this.i = undefined;
62
+ this.a = conn;
63
+ this.p = undefined;
53
64
  }
54
65
  else {
55
- g(new Error('Connect failed'));
66
+ i(new Error('Connect failed'));
56
67
  }
57
68
  });
58
69
  });
59
70
  }
60
- return await i;
71
+ return await p;
61
72
  }
62
- A;
63
- b;
64
- i;
73
+ a1;
74
+ a;
75
+ p;
65
76
  }
66
77
  //# sourceMappingURL=LazyConn.js.map