justrun-ws 0.3.0 → 0.3.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/JustRunAuthProvider.js +137 -148
- package/lib/WsClient.js +48 -58
- package/lib/bundle.min.js +1 -1
- package/lib/common/AdjustableTimer.js +34 -24
- package/lib/common/DataWrapper.js +12 -12
- package/lib/common/List.js +10 -10
- package/lib/common/utils.js +8 -8
- package/lib/common/varUintOps.js +16 -16
- package/lib/handler/SimpleHandler.js +15 -15
- package/lib/index.d.ts +18 -14
- package/lib/net/BrowserWsNet.js +40 -46
- package/lib/net/LazyConn.js +14 -14
- package/lib/net/NetErrorString.js +11 -10
- package/lib/net/PackageWrapper.js +12 -12
- package/lib/net/TimeoutMonitor.js +34 -34
- package/lib/net/TypedPkgHub.js +122 -122
- package/package.json +3 -4
|
@@ -1,42 +1,52 @@
|
|
|
1
|
-
export class
|
|
2
|
-
constructor(a,
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
1
|
+
export class m {
|
|
2
|
+
constructor(a, onTimeout) {
|
|
3
|
+
this.a5 = new Promise((d) => {
|
|
4
|
+
this.u = d;
|
|
5
5
|
});
|
|
6
|
-
this.
|
|
6
|
+
this.M = onTimeout;
|
|
7
7
|
if (a > 0) {
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
|
|
8
|
+
this.k = setTimeout(() => {
|
|
9
|
+
this.k = undefined;
|
|
10
|
+
this.u(true);
|
|
11
|
+
onTimeout?.();
|
|
12
12
|
}, a);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
this.
|
|
15
|
+
this.u(true);
|
|
16
|
+
onTimeout?.();
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
ao(a) {
|
|
20
|
+
const { k, u, M } = this;
|
|
21
|
+
if (k) {
|
|
22
|
+
clearTimeout(k);
|
|
21
23
|
}
|
|
22
24
|
if (a > 0) {
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
this.k = setTimeout(() => {
|
|
26
|
+
this.k = undefined;
|
|
27
|
+
M?.();
|
|
28
|
+
u(true);
|
|
27
29
|
}, a);
|
|
28
30
|
}
|
|
29
31
|
else {
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
+
this.k = undefined;
|
|
33
|
+
u(true);
|
|
34
|
+
M?.();
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
ah() {
|
|
38
|
+
if (this.k) {
|
|
39
|
+
clearTimeout(this.k);
|
|
40
|
+
this.k = undefined;
|
|
41
|
+
this.u(false);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
ap() {
|
|
45
|
+
return this.a5;
|
|
36
46
|
}
|
|
37
|
-
L;
|
|
38
|
-
a8;
|
|
39
47
|
u;
|
|
40
|
-
|
|
48
|
+
a5;
|
|
49
|
+
k;
|
|
50
|
+
M;
|
|
41
51
|
}
|
|
42
52
|
//# sourceMappingURL=AdjustableTimer.js.map
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
export class DataWrapper {
|
|
2
2
|
constructor(a, needParse) {
|
|
3
3
|
if (needParse) {
|
|
4
|
-
this.
|
|
4
|
+
this.x = a;
|
|
5
5
|
}
|
|
6
6
|
else {
|
|
7
|
-
this.
|
|
7
|
+
this.y = a;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
get data() {
|
|
11
|
-
if (!this.
|
|
12
|
-
this.
|
|
11
|
+
if (!this.y) {
|
|
12
|
+
this.y = this.decode(this.x);
|
|
13
13
|
}
|
|
14
|
-
return this.
|
|
14
|
+
return this.y;
|
|
15
15
|
}
|
|
16
16
|
set data(b) {
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.y = b;
|
|
18
|
+
this.x = undefined;
|
|
19
19
|
}
|
|
20
20
|
get buff() {
|
|
21
|
-
if (!this.
|
|
22
|
-
this.
|
|
21
|
+
if (!this.x) {
|
|
22
|
+
this.x = this.encode(this.y);
|
|
23
23
|
}
|
|
24
|
-
return this.
|
|
24
|
+
return this.x;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
x;
|
|
27
|
+
y;
|
|
28
28
|
}
|
|
29
29
|
//# sourceMappingURL=DataWrapper.js.map
|
package/lib/common/List.js
CHANGED
|
@@ -30,23 +30,23 @@ export class ListNode {
|
|
|
30
30
|
}
|
|
31
31
|
export class c {
|
|
32
32
|
constructor() {
|
|
33
|
-
this.
|
|
33
|
+
this._ = new ListNode();
|
|
34
34
|
}
|
|
35
35
|
get e() {
|
|
36
|
-
return this.
|
|
36
|
+
return this._.getNext();
|
|
37
37
|
}
|
|
38
38
|
get a() {
|
|
39
|
-
return this.
|
|
39
|
+
return this._.getPrev();
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return node === this.
|
|
41
|
+
V(node) {
|
|
42
|
+
return node === this._;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
node.insertAfter(this.
|
|
44
|
+
W(node) {
|
|
45
|
+
node.insertAfter(this._);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
node.insertBefore(this.
|
|
47
|
+
am(node) {
|
|
48
|
+
node.insertBefore(this._);
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
_;
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=List.js.map
|
package/lib/common/utils.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export const i = (
|
|
2
|
-
return new Promise((
|
|
1
|
+
export const i = (e) => {
|
|
2
|
+
return new Promise((d) => setTimeout(d, e));
|
|
3
3
|
};
|
|
4
4
|
export const l = () => { };
|
|
5
|
-
export const j = (
|
|
6
|
-
return (Math.random() *
|
|
5
|
+
export const j = (g = 0x100000000) => {
|
|
6
|
+
return (Math.random() * g) >>> 0;
|
|
7
7
|
};
|
|
8
8
|
export const k = (c) => {
|
|
9
9
|
let hash = 5381, a = 0;
|
|
@@ -12,19 +12,19 @@ export const k = (c) => {
|
|
|
12
12
|
}
|
|
13
13
|
return hash >>> 0;
|
|
14
14
|
};
|
|
15
|
-
export const
|
|
15
|
+
export const y = (h) => {
|
|
16
16
|
let a = 0;
|
|
17
17
|
let b = 0;
|
|
18
18
|
while (a < h.length) {
|
|
19
19
|
b += h[a++].length;
|
|
20
20
|
}
|
|
21
|
-
const
|
|
21
|
+
const f = new Uint8Array(b);
|
|
22
22
|
b = 0;
|
|
23
23
|
while (a > 0) {
|
|
24
24
|
const buff = h[--a];
|
|
25
|
-
|
|
25
|
+
f.set(buff, b);
|
|
26
26
|
b += buff.length;
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return f;
|
|
29
29
|
};
|
|
30
30
|
//# sourceMappingURL=utils.js.map
|
package/lib/common/varUintOps.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
export const o = (b) => {
|
|
2
|
-
let
|
|
2
|
+
let f = 1;
|
|
3
3
|
while (b >>>= 7) {
|
|
4
|
-
|
|
4
|
+
f++;
|
|
5
5
|
}
|
|
6
|
-
return
|
|
6
|
+
return f;
|
|
7
7
|
};
|
|
8
8
|
export const j = (i) => {
|
|
9
9
|
let b;
|
|
10
10
|
let a = 0;
|
|
11
|
-
let
|
|
11
|
+
let f = 0;
|
|
12
12
|
while (a < i.length) {
|
|
13
|
-
|
|
13
|
+
f++;
|
|
14
14
|
b = i[a++];
|
|
15
15
|
while (b >>>= 7) {
|
|
16
|
-
|
|
16
|
+
f++;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return f;
|
|
20
20
|
};
|
|
21
21
|
export const p = (buffer, e = 0) => {
|
|
22
22
|
let c;
|
|
23
23
|
let d = e;
|
|
24
24
|
let b = 0;
|
|
25
|
-
let
|
|
25
|
+
let g = 0;
|
|
26
26
|
do {
|
|
27
27
|
c = buffer[d++];
|
|
28
|
-
b |= (c & 127) <<
|
|
29
|
-
|
|
28
|
+
b |= (c & 127) << g;
|
|
29
|
+
g += 7;
|
|
30
30
|
} while (c & 128);
|
|
31
|
-
if (c !== undefined &&
|
|
31
|
+
if (c !== undefined && g <= 35) {
|
|
32
32
|
return {
|
|
33
33
|
b: b,
|
|
34
34
|
k: d - e,
|
|
@@ -43,18 +43,18 @@ export const l = (n, buffer, e = 0) => {
|
|
|
43
43
|
let c;
|
|
44
44
|
let d = e;
|
|
45
45
|
let b = 0;
|
|
46
|
-
let
|
|
46
|
+
let g = 0;
|
|
47
47
|
const h = [];
|
|
48
48
|
for (a = 0; a < n; a++) {
|
|
49
49
|
do {
|
|
50
50
|
c = buffer[d++];
|
|
51
|
-
b |= (c & 127) <<
|
|
52
|
-
|
|
51
|
+
b |= (c & 127) << g;
|
|
52
|
+
g += 7;
|
|
53
53
|
} while (c & 128);
|
|
54
|
-
if (c !== undefined &&
|
|
54
|
+
if (c !== undefined && g <= 35) {
|
|
55
55
|
h.push(b);
|
|
56
56
|
b = 0;
|
|
57
|
-
|
|
57
|
+
g = 0;
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
60
|
throw new Error('Parsing failed');
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { NetErrorString } from '../net/NetErrorString';
|
|
2
2
|
import { b } from './common';
|
|
3
|
-
const
|
|
4
|
-
export class
|
|
5
|
-
constructor(wrapperCtor, e, f
|
|
3
|
+
const c = new Error(NetErrorString.NotAuthenticated);
|
|
4
|
+
export class h {
|
|
5
|
+
constructor(wrapperCtor, e, f) {
|
|
6
6
|
this.n = wrapperCtor;
|
|
7
7
|
this.v = e;
|
|
8
|
-
this.w = f;
|
|
8
|
+
this.w = !f;
|
|
9
9
|
}
|
|
10
10
|
get pkgType() {
|
|
11
11
|
return this.n.pkgType;
|
|
@@ -13,7 +13,7 @@ export class i {
|
|
|
13
13
|
get k() {
|
|
14
14
|
return this.n.name;
|
|
15
15
|
}
|
|
16
|
-
async
|
|
16
|
+
async x(conn, a) {
|
|
17
17
|
const { buff, bodyOffset } = a;
|
|
18
18
|
const body = buff.subarray(bodyOffset);
|
|
19
19
|
const message = new this.n(body, true);
|
|
@@ -28,7 +28,7 @@ export class i {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
b(conn,
|
|
31
|
+
b(conn, c);
|
|
32
32
|
}
|
|
33
33
|
if (conn.context === undefined) {
|
|
34
34
|
await conn.close();
|
|
@@ -46,18 +46,18 @@ export class i {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
b(conn,
|
|
49
|
+
b(conn, c);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
n;
|
|
53
53
|
v;
|
|
54
54
|
w;
|
|
55
55
|
}
|
|
56
|
-
export class
|
|
57
|
-
constructor(wrapperCtor, e, f
|
|
56
|
+
export class i {
|
|
57
|
+
constructor(wrapperCtor, e, f) {
|
|
58
58
|
this.n = wrapperCtor;
|
|
59
59
|
this.v = e;
|
|
60
|
-
this.w = f;
|
|
60
|
+
this.w = !f;
|
|
61
61
|
}
|
|
62
62
|
get pkgType() {
|
|
63
63
|
return this.n.pkgType;
|
|
@@ -65,7 +65,7 @@ export class j {
|
|
|
65
65
|
get k() {
|
|
66
66
|
return this.n.name;
|
|
67
67
|
}
|
|
68
|
-
async
|
|
68
|
+
async x(conn, a) {
|
|
69
69
|
const { buff, requestId, bodyOffset } = a;
|
|
70
70
|
const body = buff.subarray(bodyOffset);
|
|
71
71
|
const request = new this.n(body, true);
|
|
@@ -84,7 +84,7 @@ export class j {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
error = b(conn,
|
|
87
|
+
error = b(conn, c);
|
|
88
88
|
}
|
|
89
89
|
try {
|
|
90
90
|
if (!error) {
|
|
@@ -97,8 +97,8 @@ export class j {
|
|
|
97
97
|
await conn.close();
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
catch
|
|
101
|
-
|
|
100
|
+
catch {
|
|
101
|
+
return;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
async q(conn, request) {
|
|
@@ -115,7 +115,7 @@ export class j {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
throw b(conn,
|
|
118
|
+
throw b(conn, c);
|
|
119
119
|
}
|
|
120
120
|
n;
|
|
121
121
|
v;
|
package/lib/index.d.ts
CHANGED
|
@@ -76,18 +76,18 @@ declare class ListNode {
|
|
|
76
76
|
private _prev;
|
|
77
77
|
private _next;
|
|
78
78
|
}
|
|
79
|
-
declare abstract class
|
|
80
|
-
abstract
|
|
81
|
-
abstract
|
|
79
|
+
declare abstract class MonitorItem extends ListNode {
|
|
80
|
+
abstract warnTimeout(): void;
|
|
81
|
+
abstract onTimeout(): void;
|
|
82
82
|
}
|
|
83
83
|
export declare class TimeoutMonitor {
|
|
84
|
-
constructor(tickMilSec: number,
|
|
85
|
-
insert(
|
|
86
|
-
update(
|
|
87
|
-
remove(
|
|
84
|
+
constructor(tickMilSec: number, warningTick: number, timeoutTick: number);
|
|
85
|
+
insert(item: MonitorItem): void;
|
|
86
|
+
update(item: MonitorItem): void;
|
|
87
|
+
remove(item: MonitorItem): void;
|
|
88
88
|
private check;
|
|
89
89
|
private _tickMilSec;
|
|
90
|
-
private
|
|
90
|
+
private _warningTick;
|
|
91
91
|
private _timeoutTick;
|
|
92
92
|
private _currentTick;
|
|
93
93
|
private _monitorCount;
|
|
@@ -129,6 +129,7 @@ export declare enum NetErrorString {
|
|
|
129
129
|
InvalidConnection = "InvalidConnection",
|
|
130
130
|
InvalidPackage = "InvalidPackage",
|
|
131
131
|
NotAuthenticated = "NotAuthenticated",
|
|
132
|
+
NotFound = "NotFound",
|
|
132
133
|
Timeout = "Timeout",
|
|
133
134
|
UnknownError = "UnknownError"
|
|
134
135
|
}
|
|
@@ -137,8 +138,14 @@ export interface IAuthProvider {
|
|
|
137
138
|
preConnect(): Promise<string>;
|
|
138
139
|
}
|
|
139
140
|
export declare const createNumPkgTypeClient: (connUrl: string, timeoutMonitor?: TimeoutMonitor) => WsClient<number>;
|
|
141
|
+
declare enum ClientConnState {
|
|
142
|
+
NotConnected = 0,
|
|
143
|
+
Connecting = 1,
|
|
144
|
+
Connected = 2
|
|
145
|
+
}
|
|
140
146
|
export declare class WsClient<PkgTypeT extends number | string> {
|
|
141
147
|
constructor(connUrl: string, opts: TypedPkgHubOpts<PkgTypeT>);
|
|
148
|
+
getConnState(): ClientConnState;
|
|
142
149
|
enableAuthenticate(proxyPrivatePkgType: PkgTypeT, authProvider: IAuthProvider): void;
|
|
143
150
|
registerError<ErrorT>(pkgType: PkgTypeT, wrapperCtor: ErrorWrapperCtor<ErrorT>): void;
|
|
144
151
|
registerMessage<MessageT>(pkgType: PkgTypeT, wrapperCtor: MessageWrapperCtor<MessageT>): void;
|
|
@@ -147,7 +154,6 @@ export declare class WsClient<PkgTypeT extends number | string> {
|
|
|
147
154
|
handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(wrapperCtor: RequestWrapperCtor<RequestT, ResponseT, WrapperT>, handler: (request: RequestT) => ResponseT | Promise<ResponseT>): void;
|
|
148
155
|
sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
|
|
149
156
|
sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
|
|
150
|
-
startConnect(delay?: number): Promise<void>;
|
|
151
157
|
onConnectionStatus(listener: (isOpen: boolean, conn: IConn<string>, active: boolean, err?: Error) => void): void;
|
|
152
158
|
private connect;
|
|
153
159
|
private onConnOpen;
|
|
@@ -157,17 +163,16 @@ export declare class WsClient<PkgTypeT extends number | string> {
|
|
|
157
163
|
private _conn;
|
|
158
164
|
private _connState;
|
|
159
165
|
private _authProvider?;
|
|
160
|
-
private _connectDelay?;
|
|
161
166
|
private _listenerArr?;
|
|
162
167
|
}
|
|
163
168
|
export declare class JustrunAuthProvider implements IAuthProvider {
|
|
164
|
-
constructor(
|
|
169
|
+
constructor(authUrl: string, getConnUrl: (address: string, sid: string, kick?: boolean) => string, authStateCb: (cid: string, sid: string, connErr?: string) => void);
|
|
165
170
|
init<PkgTypeT extends number | string>(proxyPrivatePkgType: PkgTypeT, client: WsClient<PkgTypeT>): Promise<void>;
|
|
166
171
|
preConnect(): Promise<string>;
|
|
167
172
|
authWithCredential(type: "signin" | "signup", id: string, hash: string, extra: string): Promise<void>;
|
|
168
173
|
authWithOAuth2(returnTo: string, oauthUrl: string, clientId: string, scope: string): void;
|
|
169
174
|
resetAuthState(): Promise<void>;
|
|
170
|
-
|
|
175
|
+
resetConnState(forceKick: boolean): void;
|
|
171
176
|
private onConnStatus;
|
|
172
177
|
private extendToken;
|
|
173
178
|
private onSysMessage;
|
|
@@ -175,11 +180,10 @@ export declare class JustrunAuthProvider implements IAuthProvider {
|
|
|
175
180
|
private sendAuthRequest;
|
|
176
181
|
private _cid;
|
|
177
182
|
private _sid;
|
|
178
|
-
private _allowAnonymous;
|
|
179
183
|
private _authUrl;
|
|
180
|
-
private _kickedState;
|
|
181
184
|
private _currConnAddr;
|
|
182
185
|
private _conn?;
|
|
186
|
+
private _connErr?;
|
|
183
187
|
private _extendTokenTimer?;
|
|
184
188
|
private _getConnUrl;
|
|
185
189
|
private _authStateCb;
|
package/lib/net/BrowserWsNet.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { y } from '../common/utils';
|
|
2
2
|
import { NetErrorString } from './NetErrorString';
|
|
3
|
-
export class
|
|
3
|
+
export class m {
|
|
4
4
|
b() {
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
this.
|
|
7
|
+
init(E) {
|
|
8
|
+
this.E = E;
|
|
9
9
|
}
|
|
10
|
-
async
|
|
10
|
+
async I(r) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
13
|
+
async J() {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
async
|
|
17
|
-
const
|
|
18
|
-
return new Promise((
|
|
19
|
-
|
|
20
|
-
j(new Error(NetErrorString.
|
|
16
|
+
async g(c) {
|
|
17
|
+
const f = new WebSocket(c);
|
|
18
|
+
return new Promise((d, j) => {
|
|
19
|
+
f.onerror = (l) => {
|
|
20
|
+
j(new Error(NetErrorString.UnknownError));
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
f.onopen = () => {
|
|
23
|
+
d(this.ai(f, true));
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const { conn,
|
|
30
|
-
|
|
27
|
+
ai = (f, p) => {
|
|
28
|
+
const e = new q(f);
|
|
29
|
+
const { conn, _, o } = this.E(e, p);
|
|
30
|
+
f.onmessage = (k) => {
|
|
31
31
|
k.data.arrayBuffer().then((buff) => {
|
|
32
|
-
|
|
32
|
+
_(new Uint8Array(buff));
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
o(new Error(NetErrorString.
|
|
35
|
+
f.onerror = (l) => {
|
|
36
|
+
o(new Error(NetErrorString.UnknownError));
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
f.onclose = (k) => {
|
|
39
39
|
if (k.code === 1000) {
|
|
40
40
|
o();
|
|
41
41
|
}
|
|
@@ -45,53 +45,47 @@ export class q {
|
|
|
45
45
|
};
|
|
46
46
|
return conn;
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
E(a, s) {
|
|
49
49
|
throw new Error('Need to call "setConnWrapperMaker" before using');
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
class
|
|
53
|
-
constructor(
|
|
54
|
-
this.i =
|
|
55
|
-
}
|
|
56
|
-
get
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
get remoteFamily() {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
get remotePort() {
|
|
69
|
-
return;
|
|
52
|
+
class q {
|
|
53
|
+
constructor(f) {
|
|
54
|
+
this.i = f;
|
|
55
|
+
}
|
|
56
|
+
get socket() {
|
|
57
|
+
return {
|
|
58
|
+
localAddress: '',
|
|
59
|
+
localPort: 0,
|
|
60
|
+
remoteAddress: '',
|
|
61
|
+
remoteFamily: '',
|
|
62
|
+
remotePort: 0,
|
|
63
|
+
};
|
|
70
64
|
}
|
|
71
|
-
async
|
|
65
|
+
async F(buff) {
|
|
72
66
|
if (this.i) {
|
|
73
67
|
return this.i.send(buff);
|
|
74
68
|
}
|
|
75
|
-
throw new Error(NetErrorString.
|
|
69
|
+
throw new Error(NetErrorString.InvalidConnection);
|
|
76
70
|
}
|
|
77
71
|
async n(h) {
|
|
78
72
|
if (this.i) {
|
|
79
|
-
const buff =
|
|
73
|
+
const buff = y(h);
|
|
80
74
|
return this.i.send(buff);
|
|
81
75
|
}
|
|
82
|
-
throw new Error(NetErrorString.
|
|
76
|
+
throw new Error(NetErrorString.InvalidConnection);
|
|
83
77
|
}
|
|
84
78
|
async close(err) {
|
|
85
79
|
const { i } = this;
|
|
86
80
|
if (i) {
|
|
87
81
|
this.i = undefined;
|
|
88
82
|
if (!err) {
|
|
89
|
-
if (i.readyState
|
|
83
|
+
if (i.readyState <= WebSocket.OPEN) {
|
|
90
84
|
i.close(1000);
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
87
|
else {
|
|
94
|
-
i.close(
|
|
88
|
+
i.close(1006, err.message);
|
|
95
89
|
}
|
|
96
90
|
}
|
|
97
91
|
}
|
package/lib/net/LazyConn.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class e {
|
|
2
2
|
constructor(c) {
|
|
3
|
-
this.
|
|
3
|
+
this.a6 = c;
|
|
4
4
|
}
|
|
5
5
|
get id() {
|
|
6
6
|
return this.a?.id ?? -1;
|
|
@@ -19,16 +19,16 @@ export class h {
|
|
|
19
19
|
remoteFamily;
|
|
20
20
|
remotePort;
|
|
21
21
|
async sendErrorResponse(error, requestId) {
|
|
22
|
-
return (this.a ?? await this.
|
|
22
|
+
return (this.a ?? await this.g()).sendErrorResponse(error, requestId);
|
|
23
23
|
}
|
|
24
24
|
async sendResponse(request, requestId) {
|
|
25
|
-
return (this.a ?? await this.
|
|
25
|
+
return (this.a ?? await this.g()).sendResponse(request, requestId);
|
|
26
26
|
}
|
|
27
27
|
async sendMessage(message) {
|
|
28
|
-
return (this.a ?? await this.
|
|
28
|
+
return (this.a ?? await this.g()).sendMessage(message);
|
|
29
29
|
}
|
|
30
30
|
async sendRequest(request) {
|
|
31
|
-
return (this.a ?? await this.
|
|
31
|
+
return (this.a ?? await this.g()).sendRequest(request);
|
|
32
32
|
}
|
|
33
33
|
async close(err) {
|
|
34
34
|
const { a } = this;
|
|
@@ -44,21 +44,21 @@ export class h {
|
|
|
44
44
|
}, () => this.a = undefined);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
async
|
|
47
|
+
async aq() {
|
|
48
48
|
if (!this.a) {
|
|
49
|
-
await this.
|
|
49
|
+
await this.g();
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
aj() {
|
|
53
53
|
this.a = undefined;
|
|
54
54
|
}
|
|
55
|
-
async
|
|
55
|
+
async g() {
|
|
56
56
|
let { q } = this;
|
|
57
57
|
if (!q) {
|
|
58
|
-
q = this.q = new Promise((
|
|
59
|
-
this.
|
|
58
|
+
q = this.q = new Promise((d, j) => {
|
|
59
|
+
this.a6().then((conn) => {
|
|
60
60
|
if (conn) {
|
|
61
|
-
|
|
61
|
+
d(conn);
|
|
62
62
|
this.a = conn;
|
|
63
63
|
this.q = undefined;
|
|
64
64
|
}
|
|
@@ -70,7 +70,7 @@ export class h {
|
|
|
70
70
|
}
|
|
71
71
|
return await q;
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
a6;
|
|
74
74
|
a;
|
|
75
75
|
q;
|
|
76
76
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export var NetErrorString;
|
|
2
2
|
(function (NetErrorString) {
|
|
3
|
-
NetErrorString["
|
|
4
|
-
NetErrorString["
|
|
5
|
-
NetErrorString["
|
|
6
|
-
NetErrorString["
|
|
7
|
-
NetErrorString["
|
|
8
|
-
NetErrorString["
|
|
9
|
-
NetErrorString["
|
|
10
|
-
NetErrorString["
|
|
11
|
-
NetErrorString["
|
|
12
|
-
NetErrorString["
|
|
3
|
+
NetErrorString["AuthTimeout"] = "AuthTimeout";
|
|
4
|
+
NetErrorString["BadRequest"] = "BadRequest";
|
|
5
|
+
NetErrorString["ConnectFailed"] = "ConnectFailed";
|
|
6
|
+
NetErrorString["ConnectionClosed"] = "ConnectionClosed";
|
|
7
|
+
NetErrorString["InvalidConnString"] = "InvalidConnString";
|
|
8
|
+
NetErrorString["InvalidConnection"] = "InvalidConnection";
|
|
9
|
+
NetErrorString["InvalidPackage"] = "InvalidPackage";
|
|
10
|
+
NetErrorString["NotAuthenticated"] = "NotAuthenticated";
|
|
11
|
+
NetErrorString["NotFound"] = "NotFound";
|
|
12
|
+
NetErrorString["Timeout"] = "Timeout";
|
|
13
|
+
NetErrorString["UnknownError"] = "UnknownError";
|
|
13
14
|
})(NetErrorString || (NetErrorString = {}));
|
|
14
15
|
//# sourceMappingURL=NetErrorString.js.map
|