justrun-ws 0.2.2 → 0.3.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.
- package/lib/JustRunAuthProvider.js +242 -0
- package/lib/WsClient.js +72 -159
- package/lib/bundle.min.js +1 -1
- package/lib/common/AdjustableTimer.js +17 -17
- package/lib/common/DataWrapper.js +12 -12
- package/lib/common/List.js +27 -27
- package/lib/common/utils.js +10 -10
- package/lib/handler/SimpleHandler.js +31 -31
- package/lib/index.d.ts +43 -20
- package/lib/index.js +1 -0
- package/lib/net/BrowserWsNet.js +47 -47
- package/lib/net/LazyConn.js +23 -23
- package/lib/net/NetErrorString.js +7 -7
- package/lib/net/PackageWrapper.js +12 -12
- package/lib/net/TimeoutMonitor.js +32 -32
- package/lib/net/TypedPkgHub.js +164 -174
- package/lib/net/hubPkgSerializer.js +2 -2
- package/package.json +2 -2
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
export class DataWrapper {
|
|
2
2
|
constructor(a, needParse) {
|
|
3
3
|
if (needParse) {
|
|
4
|
-
this.
|
|
4
|
+
this._ = a;
|
|
5
5
|
}
|
|
6
6
|
else {
|
|
7
|
-
this.
|
|
7
|
+
this.A = a;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
get data() {
|
|
11
|
-
if (!this.
|
|
12
|
-
this.
|
|
11
|
+
if (!this.A) {
|
|
12
|
+
this.A = this.decode(this._);
|
|
13
13
|
}
|
|
14
|
-
return this.
|
|
14
|
+
return this.A;
|
|
15
15
|
}
|
|
16
16
|
set data(b) {
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
17
|
+
this.A = b;
|
|
18
|
+
this._ = undefined;
|
|
19
19
|
}
|
|
20
20
|
get buff() {
|
|
21
|
-
if (!this.
|
|
22
|
-
this.
|
|
21
|
+
if (!this._) {
|
|
22
|
+
this._ = this.encode(this.A);
|
|
23
23
|
}
|
|
24
|
-
return this.
|
|
24
|
+
return this._;
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
_;
|
|
27
|
+
A;
|
|
28
28
|
}
|
|
29
29
|
//# sourceMappingURL=DataWrapper.js.map
|
package/lib/common/List.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
export class ListNode {
|
|
2
2
|
constructor() {
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
3
|
+
this.b = this;
|
|
4
|
+
this.j = this;
|
|
5
5
|
}
|
|
6
6
|
getPrev() {
|
|
7
|
-
return this.
|
|
7
|
+
return this.b;
|
|
8
8
|
}
|
|
9
9
|
getNext() {
|
|
10
|
-
return this.
|
|
10
|
+
return this.j;
|
|
11
11
|
}
|
|
12
12
|
insertBefore(node) {
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
node.
|
|
16
|
-
this.
|
|
13
|
+
this.j = node;
|
|
14
|
+
this.b = node.b;
|
|
15
|
+
node.b = this;
|
|
16
|
+
this.b.j = this;
|
|
17
17
|
}
|
|
18
18
|
insertAfter(node) {
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
node.
|
|
22
|
-
this.
|
|
19
|
+
this.b = node;
|
|
20
|
+
this.j = node.j;
|
|
21
|
+
node.j = this;
|
|
22
|
+
this.j.b = this;
|
|
23
23
|
}
|
|
24
24
|
remove() {
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
25
|
+
this.b.j = this.j;
|
|
26
|
+
this.j.b = this.b;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
b;
|
|
29
|
+
j;
|
|
30
30
|
}
|
|
31
31
|
export class c {
|
|
32
32
|
constructor() {
|
|
33
|
-
this.
|
|
33
|
+
this.D = new ListNode();
|
|
34
34
|
}
|
|
35
|
-
get
|
|
36
|
-
return this.
|
|
35
|
+
get e() {
|
|
36
|
+
return this.D.getNext();
|
|
37
37
|
}
|
|
38
38
|
get a() {
|
|
39
|
-
return this.
|
|
39
|
+
return this.D.getPrev();
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
return node === this.
|
|
41
|
+
Y(node) {
|
|
42
|
+
return node === this.D;
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
node.insertAfter(this.
|
|
44
|
+
Z(node) {
|
|
45
|
+
node.insertAfter(this.D);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
node.insertBefore(this.
|
|
47
|
+
ar(node) {
|
|
48
|
+
node.insertBefore(this.D);
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
D;
|
|
51
51
|
}
|
|
52
52
|
//# sourceMappingURL=List.js.map
|
package/lib/common/utils.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export const
|
|
2
|
-
return new Promise((
|
|
1
|
+
export const i = (d) => {
|
|
2
|
+
return new Promise((f) => setTimeout(f, d));
|
|
3
3
|
};
|
|
4
4
|
export const l = () => { };
|
|
5
|
-
export const
|
|
6
|
-
return (Math.random() *
|
|
5
|
+
export const j = (e = 0x100000000) => {
|
|
6
|
+
return (Math.random() * e) >>> 0;
|
|
7
7
|
};
|
|
8
|
-
export const
|
|
9
|
-
let
|
|
10
|
-
while (a <
|
|
11
|
-
|
|
8
|
+
export const k = (c) => {
|
|
9
|
+
let hash = 5381, a = 0;
|
|
10
|
+
while (a < c.length) {
|
|
11
|
+
hash = ((hash << 5) + hash) + c.charCodeAt(a++);
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return hash >>> 0;
|
|
14
14
|
};
|
|
15
|
-
export const
|
|
15
|
+
export const z = (h) => {
|
|
16
16
|
let a = 0;
|
|
17
17
|
let b = 0;
|
|
18
18
|
while (a < h.length) {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { NetErrorString } from '../net/NetErrorString';
|
|
2
2
|
import { b } from './common';
|
|
3
|
-
const
|
|
4
|
-
export class
|
|
5
|
-
constructor(wrapperCtor,
|
|
6
|
-
this.
|
|
7
|
-
this.v =
|
|
8
|
-
this.w =
|
|
3
|
+
const d = new Error(NetErrorString.g);
|
|
4
|
+
export class i {
|
|
5
|
+
constructor(wrapperCtor, e, f = true) {
|
|
6
|
+
this.n = wrapperCtor;
|
|
7
|
+
this.v = e;
|
|
8
|
+
this.w = f;
|
|
9
9
|
}
|
|
10
10
|
get pkgType() {
|
|
11
|
-
return this.
|
|
11
|
+
return this.n.pkgType;
|
|
12
12
|
}
|
|
13
|
-
get
|
|
14
|
-
return this.
|
|
13
|
+
get k() {
|
|
14
|
+
return this.n.name;
|
|
15
15
|
}
|
|
16
|
-
async
|
|
16
|
+
async y(conn, a) {
|
|
17
17
|
const { buff, bodyOffset } = a;
|
|
18
|
-
const
|
|
19
|
-
const message = new this.
|
|
18
|
+
const body = buff.subarray(bodyOffset);
|
|
19
|
+
const message = new this.n(body, true);
|
|
20
20
|
if (conn.context !== undefined || !this.w) {
|
|
21
21
|
try {
|
|
22
22
|
await this.v(conn, message);
|
|
@@ -28,13 +28,13 @@ export class n {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
|
-
b(conn,
|
|
31
|
+
b(conn, d);
|
|
32
32
|
}
|
|
33
33
|
if (conn.context === undefined) {
|
|
34
34
|
await conn.close();
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
async
|
|
37
|
+
async q(conn, message) {
|
|
38
38
|
if (conn.context !== undefined || !this.w) {
|
|
39
39
|
try {
|
|
40
40
|
return await this.v(conn, message);
|
|
@@ -46,29 +46,29 @@ export class n {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
b(conn,
|
|
49
|
+
b(conn, d);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
n;
|
|
53
53
|
v;
|
|
54
54
|
w;
|
|
55
55
|
}
|
|
56
|
-
export class
|
|
57
|
-
constructor(wrapperCtor,
|
|
58
|
-
this.
|
|
59
|
-
this.v =
|
|
60
|
-
this.w =
|
|
56
|
+
export class j {
|
|
57
|
+
constructor(wrapperCtor, e, f = true) {
|
|
58
|
+
this.n = wrapperCtor;
|
|
59
|
+
this.v = e;
|
|
60
|
+
this.w = f;
|
|
61
61
|
}
|
|
62
62
|
get pkgType() {
|
|
63
|
-
return this.
|
|
63
|
+
return this.n.pkgType;
|
|
64
64
|
}
|
|
65
|
-
get
|
|
66
|
-
return this.
|
|
65
|
+
get k() {
|
|
66
|
+
return this.n.name;
|
|
67
67
|
}
|
|
68
|
-
async
|
|
68
|
+
async y(conn, a) {
|
|
69
69
|
const { buff, requestId, bodyOffset } = a;
|
|
70
|
-
const
|
|
71
|
-
const request = new this.
|
|
70
|
+
const body = buff.subarray(bodyOffset);
|
|
71
|
+
const request = new this.n(body, true);
|
|
72
72
|
let error;
|
|
73
73
|
if (conn.context !== undefined || !this.w) {
|
|
74
74
|
try {
|
|
@@ -84,7 +84,7 @@ export class o {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
error = b(conn,
|
|
87
|
+
error = b(conn, d);
|
|
88
88
|
}
|
|
89
89
|
try {
|
|
90
90
|
if (!error) {
|
|
@@ -101,7 +101,7 @@ export class o {
|
|
|
101
101
|
await conn.close(err);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async
|
|
104
|
+
async q(conn, request) {
|
|
105
105
|
if (conn.context !== undefined || !this.w) {
|
|
106
106
|
try {
|
|
107
107
|
return await this.v(conn, request);
|
|
@@ -115,9 +115,9 @@ export class o {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
throw b(conn,
|
|
118
|
+
throw b(conn, d);
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
n;
|
|
121
121
|
v;
|
|
122
122
|
w;
|
|
123
123
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
export interface ISocket {
|
|
4
|
+
readonly localAddress?: string;
|
|
5
|
+
readonly localPort?: number;
|
|
6
|
+
readonly remoteAddress?: string;
|
|
7
|
+
readonly remoteFamily?: string;
|
|
8
|
+
readonly remotePort?: number;
|
|
9
|
+
}
|
|
3
10
|
export interface IWrapper<DataT> {
|
|
4
11
|
get buff(): Uint8Array;
|
|
5
12
|
get data(): DataT;
|
|
@@ -46,11 +53,7 @@ export type RequestWrapperCtor<RequestT, ResponseT, WrapperT extends RequestWrap
|
|
|
46
53
|
export interface IConn<ConnContextT = void> {
|
|
47
54
|
context?: ConnContextT | undefined;
|
|
48
55
|
readonly id: number;
|
|
49
|
-
readonly
|
|
50
|
-
readonly localPort?: number;
|
|
51
|
-
readonly remoteAddress?: string;
|
|
52
|
-
readonly remoteFamily?: string;
|
|
53
|
-
readonly remotePort?: number;
|
|
56
|
+
readonly socket?: ISocket;
|
|
54
57
|
sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
|
|
55
58
|
sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<void>;
|
|
56
59
|
sendErrorResponse<ErrorT>(error: ErrorWrapper<ErrorT>, requestId: number): Promise<void>;
|
|
@@ -116,11 +119,6 @@ export declare class CommonError extends JsonError<string> {
|
|
|
116
119
|
export interface DoneResp<ResultT extends string | number | boolean = boolean> {
|
|
117
120
|
result: ResultT;
|
|
118
121
|
}
|
|
119
|
-
export interface IAuthResp {
|
|
120
|
-
cid: string;
|
|
121
|
-
token: string;
|
|
122
|
-
shard?: number;
|
|
123
|
-
}
|
|
124
122
|
export declare const handleUncaughtErrorWith: (handler: (conn: IConn<unknown>, err: Error) => ErrorWrapper<unknown>) => void;
|
|
125
123
|
export declare enum NetErrorString {
|
|
126
124
|
AuthTimeout = "AuthTimeout",
|
|
@@ -134,9 +132,14 @@ export declare enum NetErrorString {
|
|
|
134
132
|
Timeout = "Timeout",
|
|
135
133
|
UnknownError = "UnknownError"
|
|
136
134
|
}
|
|
137
|
-
export
|
|
135
|
+
export interface IAuthProvider {
|
|
136
|
+
init<PkgTypeT extends number | string>(proxyPrivatePkgType: PkgTypeT, client: WsClient<PkgTypeT>): Promise<void>;
|
|
137
|
+
preConnect(): Promise<string>;
|
|
138
|
+
}
|
|
139
|
+
export declare const createNumPkgTypeClient: (connUrl: string, timeoutMonitor?: TimeoutMonitor) => WsClient<number>;
|
|
138
140
|
export declare class WsClient<PkgTypeT extends number | string> {
|
|
139
|
-
constructor(
|
|
141
|
+
constructor(connUrl: string, opts: TypedPkgHubOpts<PkgTypeT>);
|
|
142
|
+
enableAuthenticate(proxyPrivatePkgType: PkgTypeT, authProvider: IAuthProvider): void;
|
|
140
143
|
registerError<ErrorT>(pkgType: PkgTypeT, wrapperCtor: ErrorWrapperCtor<ErrorT>): void;
|
|
141
144
|
registerMessage<MessageT>(pkgType: PkgTypeT, wrapperCtor: MessageWrapperCtor<MessageT>): void;
|
|
142
145
|
registerRequest<RequestT, ResponseT>(pkgType: PkgTypeT, wrapperCtor: RequestWrapperCtor<RequestT, ResponseT>): void;
|
|
@@ -144,22 +147,42 @@ export declare class WsClient<PkgTypeT extends number | string> {
|
|
|
144
147
|
handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(wrapperCtor: RequestWrapperCtor<RequestT, ResponseT, WrapperT>, handler: (request: RequestT) => ResponseT | Promise<ResponseT>): void;
|
|
145
148
|
sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
|
|
146
149
|
sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
enableAuthenticate(proxyAuthPkgType: PkgTypeT, authStatusCallback: (cid: string) => void, allowAnonymous?: true): void;
|
|
150
|
-
reconnect(delay?: number): void;
|
|
151
|
-
onConnectionStatus(listener: (isOpen: boolean, active: boolean, err?: Error) => void): void;
|
|
150
|
+
startConnect(delay?: number): Promise<void>;
|
|
151
|
+
onConnectionStatus(listener: (isOpen: boolean, conn: IConn<string>, active: boolean, err?: Error) => void): void;
|
|
152
152
|
private connect;
|
|
153
153
|
private onConnOpen;
|
|
154
154
|
private onConnClose;
|
|
155
|
+
private _connUrl;
|
|
155
156
|
private _pkgHub;
|
|
156
157
|
private _conn;
|
|
157
|
-
private _cid;
|
|
158
158
|
private _connState;
|
|
159
|
-
private
|
|
160
|
-
private _originConnect;
|
|
159
|
+
private _authProvider?;
|
|
161
160
|
private _connectDelay?;
|
|
162
161
|
private _listenerArr?;
|
|
163
162
|
}
|
|
163
|
+
export declare class JustrunAuthProvider implements IAuthProvider {
|
|
164
|
+
constructor(allowAnonymous: boolean, authUrl: string, getConnUrl: (address: string, sid: string, kick?: boolean) => string, authStateCb: (cid: string, sid: string) => void);
|
|
165
|
+
init<PkgTypeT extends number | string>(proxyPrivatePkgType: PkgTypeT, client: WsClient<PkgTypeT>): Promise<void>;
|
|
166
|
+
preConnect(): Promise<string>;
|
|
167
|
+
authWithCredential(type: "signin" | "signup", id: string, hash: string, extra: string): Promise<void>;
|
|
168
|
+
authWithOAuth2(returnTo: string, oauthUrl: string, clientId: string, scope: string): void;
|
|
169
|
+
resetAuthState(): Promise<void>;
|
|
170
|
+
resetKickedState(forceKick: boolean): void;
|
|
171
|
+
private onConnStatus;
|
|
172
|
+
private extendToken;
|
|
173
|
+
private onSysMessage;
|
|
174
|
+
private readAuthInfo;
|
|
175
|
+
private sendAuthRequest;
|
|
176
|
+
private _cid;
|
|
177
|
+
private _sid;
|
|
178
|
+
private _allowAnonymous;
|
|
179
|
+
private _authUrl;
|
|
180
|
+
private _kickedState;
|
|
181
|
+
private _currConnAddr;
|
|
182
|
+
private _conn?;
|
|
183
|
+
private _extendTokenTimer?;
|
|
184
|
+
private _getConnUrl;
|
|
185
|
+
private _authStateCb;
|
|
186
|
+
}
|
|
164
187
|
|
|
165
188
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -3,5 +3,6 @@ export { JsonError, JsonMessage, JsonRequest } from './net/JsonPackageWrapper';
|
|
|
3
3
|
export { NetErrorString } from './net/NetErrorString';
|
|
4
4
|
export { ErrorWrapper, EventWrapper, MessageWrapper, RequestWrapper } from './net/PackageWrapper';
|
|
5
5
|
export { TimeoutMonitor } from './net/TimeoutMonitor';
|
|
6
|
+
export { JustrunAuthProvider } from './JustRunAuthProvider';
|
|
6
7
|
export { createNumPkgTypeClient, WsClient } from './WsClient';
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/lib/net/BrowserWsNet.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from '../common/utils';
|
|
2
2
|
import { NetErrorString } from './NetErrorString';
|
|
3
|
-
export class
|
|
4
|
-
|
|
3
|
+
export class q {
|
|
4
|
+
b() {
|
|
5
5
|
return null;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
this.
|
|
7
|
+
I(H) {
|
|
8
|
+
this.H = H;
|
|
9
9
|
}
|
|
10
|
-
async
|
|
10
|
+
async J(t) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
13
|
+
async L() {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
async
|
|
17
|
-
const
|
|
18
|
-
return new Promise((
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
async d(e) {
|
|
17
|
+
const g = new WebSocket(e);
|
|
18
|
+
return new Promise((f, j) => {
|
|
19
|
+
g.onerror = (r) => {
|
|
20
|
+
j(new Error(NetErrorString.l));
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
g.onopen = () => {
|
|
23
|
+
f(this.am(g, true));
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
const { conn,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
am = (g, p) => {
|
|
28
|
+
const c = new s(g);
|
|
29
|
+
const { conn, A, o } = this.H(c, p);
|
|
30
|
+
g.onmessage = (k) => {
|
|
31
|
+
k.data.arrayBuffer().then((buff) => {
|
|
32
|
+
A(new Uint8Array(buff));
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
g.onerror = (r) => {
|
|
36
|
+
o(new Error(NetErrorString.l));
|
|
37
37
|
};
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
38
|
+
g.onclose = (k) => {
|
|
39
|
+
if (k.code === 1000) {
|
|
40
|
+
o();
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
|
|
43
|
+
o(new Error(k.reason));
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
return conn;
|
|
47
47
|
};
|
|
48
|
-
|
|
48
|
+
H(a, u) {
|
|
49
49
|
throw new Error('Need to call "setConnWrapperMaker" before using');
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
class s {
|
|
53
|
-
constructor(
|
|
54
|
-
this.
|
|
53
|
+
constructor(g) {
|
|
54
|
+
this.i = g;
|
|
55
55
|
}
|
|
56
56
|
get localAddress() {
|
|
57
57
|
return;
|
|
@@ -68,36 +68,36 @@ class s {
|
|
|
68
68
|
get remotePort() {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
async
|
|
72
|
-
if (this.
|
|
73
|
-
return this.
|
|
71
|
+
async D(buff) {
|
|
72
|
+
if (this.i) {
|
|
73
|
+
return this.i.send(buff);
|
|
74
74
|
}
|
|
75
|
-
throw new Error(NetErrorString.
|
|
75
|
+
throw new Error(NetErrorString.m);
|
|
76
76
|
}
|
|
77
|
-
async
|
|
78
|
-
if (this.
|
|
79
|
-
const buff =
|
|
80
|
-
return this.
|
|
77
|
+
async n(h) {
|
|
78
|
+
if (this.i) {
|
|
79
|
+
const buff = z(h);
|
|
80
|
+
return this.i.send(buff);
|
|
81
81
|
}
|
|
82
|
-
throw new Error(NetErrorString.
|
|
82
|
+
throw new Error(NetErrorString.m);
|
|
83
83
|
}
|
|
84
84
|
async close(err) {
|
|
85
|
-
const {
|
|
86
|
-
if (
|
|
87
|
-
this.
|
|
85
|
+
const { i } = this;
|
|
86
|
+
if (i) {
|
|
87
|
+
this.i = undefined;
|
|
88
88
|
if (!err) {
|
|
89
|
-
if (
|
|
90
|
-
|
|
89
|
+
if (i.readyState === WebSocket.OPEN) {
|
|
90
|
+
i.close(1000);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
|
-
|
|
94
|
+
i.close(3000, err.message);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
return !this.
|
|
98
|
+
G() {
|
|
99
|
+
return !this.i;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
i;
|
|
102
102
|
}
|
|
103
103
|
//# sourceMappingURL=BrowserWsNet.js.map
|
package/lib/net/LazyConn.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export class
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
1
|
+
export class h {
|
|
2
|
+
constructor(c) {
|
|
3
|
+
this.a9 = c;
|
|
4
4
|
}
|
|
5
5
|
get id() {
|
|
6
6
|
return this.a?.id ?? -1;
|
|
@@ -19,16 +19,16 @@ export class g {
|
|
|
19
19
|
remoteFamily;
|
|
20
20
|
remotePort;
|
|
21
21
|
async sendErrorResponse(error, requestId) {
|
|
22
|
-
return (this.a ?? await this.
|
|
22
|
+
return (this.a ?? await this.d()).sendErrorResponse(error, requestId);
|
|
23
23
|
}
|
|
24
24
|
async sendResponse(request, requestId) {
|
|
25
|
-
return (this.a ?? await this.
|
|
25
|
+
return (this.a ?? await this.d()).sendResponse(request, requestId);
|
|
26
26
|
}
|
|
27
27
|
async sendMessage(message) {
|
|
28
|
-
return (this.a ?? await this.
|
|
28
|
+
return (this.a ?? await this.d()).sendMessage(message);
|
|
29
29
|
}
|
|
30
30
|
async sendRequest(request) {
|
|
31
|
-
return (this.a ?? await this.
|
|
31
|
+
return (this.a ?? await this.d()).sendRequest(request);
|
|
32
32
|
}
|
|
33
33
|
async close(err) {
|
|
34
34
|
const { a } = this;
|
|
@@ -37,41 +37,41 @@ export class g {
|
|
|
37
37
|
await a.close(err);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
if (this.
|
|
41
|
-
await this.
|
|
40
|
+
if (this.q) {
|
|
41
|
+
await this.q.then((conn) => {
|
|
42
42
|
this.a = undefined;
|
|
43
43
|
conn.close(err);
|
|
44
44
|
}, () => this.a = undefined);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
async
|
|
47
|
+
async an() {
|
|
48
48
|
if (!this.a) {
|
|
49
|
-
await this.
|
|
49
|
+
await this.d();
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
ao() {
|
|
53
53
|
this.a = undefined;
|
|
54
54
|
}
|
|
55
|
-
async
|
|
56
|
-
let {
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
this.
|
|
55
|
+
async d() {
|
|
56
|
+
let { q } = this;
|
|
57
|
+
if (!q) {
|
|
58
|
+
q = this.q = new Promise((f, j) => {
|
|
59
|
+
this.a9().then((conn) => {
|
|
60
60
|
if (conn) {
|
|
61
|
-
|
|
61
|
+
f(conn);
|
|
62
62
|
this.a = conn;
|
|
63
|
-
this.
|
|
63
|
+
this.q = undefined;
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
|
|
66
|
+
j(new Error('Connect failed'));
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
return await
|
|
71
|
+
return await q;
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
a9;
|
|
74
74
|
a;
|
|
75
|
-
|
|
75
|
+
q;
|
|
76
76
|
}
|
|
77
77
|
//# sourceMappingURL=LazyConn.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export var NetErrorString;
|
|
2
2
|
(function (NetErrorString) {
|
|
3
|
-
NetErrorString["
|
|
3
|
+
NetErrorString["H"] = "AuthTimeout";
|
|
4
4
|
NetErrorString["a"] = "BadRequest";
|
|
5
|
-
NetErrorString["
|
|
6
|
-
NetErrorString["
|
|
5
|
+
NetErrorString["p"] = "ConnectFailed";
|
|
6
|
+
NetErrorString["Y"] = "ConnectionClosed";
|
|
7
7
|
NetErrorString["b"] = "InvalidConnString";
|
|
8
|
-
NetErrorString["
|
|
9
|
-
NetErrorString["
|
|
8
|
+
NetErrorString["m"] = "InvalidConnection";
|
|
9
|
+
NetErrorString["$"] = "InvalidPackage";
|
|
10
10
|
NetErrorString["g"] = "NotAuthenticated";
|
|
11
|
-
NetErrorString["
|
|
12
|
-
NetErrorString["
|
|
11
|
+
NetErrorString["Z"] = "Timeout";
|
|
12
|
+
NetErrorString["l"] = "UnknownError";
|
|
13
13
|
})(NetErrorString || (NetErrorString = {}));
|
|
14
14
|
//# sourceMappingURL=NetErrorString.js.map
|