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