justrun-ws 0.1.3 → 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 +211 -0
- package/lib/bundle.min.js +1 -1
- package/lib/common/AdjustableTimer.js +42 -0
- package/lib/common/DataWrapper.js +14 -16
- package/lib/common/List.js +21 -21
- package/lib/common/utils.js +20 -20
- package/lib/common/varUintOps.js +51 -51
- package/lib/handler/SimpleHandler.js +49 -47
- package/lib/handler/common.js +2 -3
- package/lib/index.d.ts +60 -142
- package/lib/index.js +2 -5
- package/lib/net/BrowserWsNet.js +51 -47
- package/lib/net/LazyConn.js +42 -31
- package/lib/net/NetErrorString.js +14 -0
- package/lib/net/PackageWrapper.js +16 -16
- package/lib/net/TimeoutMonitor.js +39 -39
- package/lib/net/TypedPkgHub.js +173 -175
- package/lib/net/hubPkgSerializer.js +2 -2
- package/package.json +1 -1
package/lib/net/LazyConn.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export class
|
|
2
|
-
constructor(
|
|
3
|
-
this.
|
|
1
|
+
export class g {
|
|
2
|
+
constructor(e) {
|
|
3
|
+
this.a1 = e;
|
|
4
4
|
}
|
|
5
5
|
get id() {
|
|
6
|
-
return this.
|
|
6
|
+
return this.a?.id ?? -1;
|
|
7
7
|
}
|
|
8
8
|
get context() {
|
|
9
|
-
return this.
|
|
9
|
+
return this.a?.context;
|
|
10
10
|
}
|
|
11
|
-
set context(
|
|
12
|
-
if (this.
|
|
13
|
-
this.
|
|
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.
|
|
22
|
+
return (this.a ?? await this.c()).sendErrorResponse(error, requestId);
|
|
23
23
|
}
|
|
24
24
|
async sendResponse(request, requestId) {
|
|
25
|
-
return (this.
|
|
25
|
+
return (this.a ?? await this.c()).sendResponse(request, requestId);
|
|
26
26
|
}
|
|
27
27
|
async sendMessage(message) {
|
|
28
|
-
return (this.
|
|
28
|
+
return (this.a ?? await this.c()).sendMessage(message);
|
|
29
29
|
}
|
|
30
30
|
async sendRequest(request) {
|
|
31
|
-
return (this.
|
|
31
|
+
return (this.a ?? await this.c()).sendRequest(request);
|
|
32
32
|
}
|
|
33
33
|
async close(err) {
|
|
34
|
-
const {
|
|
35
|
-
if (
|
|
36
|
-
this.
|
|
37
|
-
await
|
|
34
|
+
const { a } = this;
|
|
35
|
+
if (a) {
|
|
36
|
+
this.a = undefined;
|
|
37
|
+
await a.close(err);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
if (this.
|
|
41
|
-
await this.
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
async reconnect() {
|
|
48
|
+
if (!this.a) {
|
|
49
|
+
await this.c();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
a5() {
|
|
53
|
+
this.a = undefined;
|
|
54
|
+
}
|
|
55
|
+
async c() {
|
|
56
|
+
let { p } = this;
|
|
57
|
+
if (!p) {
|
|
58
|
+
p = this.p = new Promise((d, i) => {
|
|
59
|
+
this.a1().then((conn) => {
|
|
49
60
|
if (conn) {
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
61
|
+
d(conn);
|
|
62
|
+
this.a = conn;
|
|
63
|
+
this.p = undefined;
|
|
53
64
|
}
|
|
54
65
|
else {
|
|
55
|
-
|
|
66
|
+
i(new Error('Connect failed'));
|
|
56
67
|
}
|
|
57
68
|
});
|
|
58
69
|
});
|
|
59
70
|
}
|
|
60
|
-
return await
|
|
71
|
+
return await p;
|
|
61
72
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
a1;
|
|
74
|
+
a;
|
|
75
|
+
p;
|
|
65
76
|
}
|
|
66
77
|
//# sourceMappingURL=LazyConn.js.map
|
|
@@ -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
|
|
@@ -39,33 +39,33 @@ class EventWrapper extends PkgWrapper {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
class RequestWrapper extends PkgWrapper {
|
|
42
|
-
constructor(
|
|
43
|
-
super(
|
|
42
|
+
constructor(a, needParse) {
|
|
43
|
+
super(a, needParse);
|
|
44
44
|
}
|
|
45
45
|
isRequest() {
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
get resp() {
|
|
49
|
-
if (!this.
|
|
50
|
-
this.
|
|
49
|
+
if (!this.z) {
|
|
50
|
+
this.z = this.decodeResponse(this.$);
|
|
51
51
|
}
|
|
52
|
-
return this.
|
|
52
|
+
return this.z;
|
|
53
53
|
}
|
|
54
|
-
set resp(
|
|
55
|
-
this.
|
|
56
|
-
this
|
|
54
|
+
set resp(b) {
|
|
55
|
+
this.z = b;
|
|
56
|
+
this.$ = undefined;
|
|
57
57
|
}
|
|
58
58
|
get respBuff() {
|
|
59
|
-
if (!this
|
|
60
|
-
this
|
|
59
|
+
if (!this.$) {
|
|
60
|
+
this.$ = this.encodeResponse(this.z);
|
|
61
61
|
}
|
|
62
|
-
return this
|
|
62
|
+
return this.$;
|
|
63
63
|
}
|
|
64
|
-
set respBuff(
|
|
65
|
-
this.
|
|
66
|
-
this
|
|
64
|
+
set respBuff(b) {
|
|
65
|
+
this.z = undefined;
|
|
66
|
+
this.$ = b;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
z;
|
|
69
|
+
$;
|
|
70
70
|
}
|
|
71
71
|
//# sourceMappingURL=PackageWrapper.js.map
|
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
import { ListNode, c } from '../common/List';
|
|
2
|
-
import {
|
|
2
|
+
import { l } from '../common/utils';
|
|
3
3
|
export class MonitorConn extends ListNode {
|
|
4
4
|
}
|
|
5
5
|
export class TimeoutMonitor {
|
|
6
|
-
constructor(e, h,
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
6
|
+
constructor(e, h, g) {
|
|
7
|
+
this.R = e;
|
|
8
|
+
this.I = h;
|
|
9
|
+
this.E = g;
|
|
10
|
+
this.o = 0;
|
|
11
|
+
this.F = 0;
|
|
12
|
+
this.r = [];
|
|
13
13
|
if (e === 0) {
|
|
14
|
-
this.insert =
|
|
15
|
-
this.update =
|
|
16
|
-
this.remove =
|
|
14
|
+
this.insert = l;
|
|
15
|
+
this.update = l;
|
|
16
|
+
this.remove = l;
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
for (let
|
|
20
|
-
this.
|
|
19
|
+
for (let a = 0; a < g; a++) {
|
|
20
|
+
this.r.push(new c());
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
insert(conn) {
|
|
24
|
-
if (!this.
|
|
25
|
-
this.
|
|
24
|
+
if (!this.F) {
|
|
25
|
+
this.S = setInterval(this.a2, this.R);
|
|
26
26
|
}
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
27
|
+
this.F++;
|
|
28
|
+
this.r[this.o].Q(conn);
|
|
29
29
|
}
|
|
30
30
|
update(conn) {
|
|
31
31
|
conn.remove();
|
|
32
|
-
this.
|
|
32
|
+
this.r[this.o].Q(conn);
|
|
33
33
|
}
|
|
34
34
|
remove(conn) {
|
|
35
35
|
conn.remove();
|
|
36
|
-
this.
|
|
37
|
-
if (!this.
|
|
38
|
-
clearInterval(this.
|
|
36
|
+
this.F--;
|
|
37
|
+
if (!this.F) {
|
|
38
|
+
clearInterval(this.S);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
this.
|
|
44
|
-
if (this.
|
|
45
|
-
this.
|
|
41
|
+
a2 = () => {
|
|
42
|
+
const { I, E, r } = this;
|
|
43
|
+
this.o++;
|
|
44
|
+
if (this.o === E) {
|
|
45
|
+
this.o = 0;
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
48
|
-
let d = this.
|
|
49
|
-
if (d >=
|
|
50
|
-
d -=
|
|
47
|
+
if (I) {
|
|
48
|
+
let d = this.o + I;
|
|
49
|
+
if (d >= E) {
|
|
50
|
+
d -= E;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
for (let node =
|
|
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
|
|
58
|
-
for (let node =
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
w;
|
|
65
|
-
j;
|
|
66
|
-
x;
|
|
62
|
+
R;
|
|
63
|
+
I;
|
|
67
64
|
E;
|
|
68
65
|
o;
|
|
66
|
+
F;
|
|
67
|
+
S;
|
|
68
|
+
r;
|
|
69
69
|
}
|
|
70
70
|
//# sourceMappingURL=TimeoutMonitor.js.map
|