justrun-ws 0.3.0 → 0.3.2
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/index.d.ts +60 -55
- package/lib/index.min.mjs +1 -0
- package/package.json +5 -6
- package/lib/JustRunAuthProvider.js +0 -242
- package/lib/WsClient.js +0 -124
- package/lib/bundle.min.js +0 -1
- package/lib/common/AdjustableTimer.js +0 -42
- package/lib/common/DataWrapper.js +0 -29
- package/lib/common/List.js +0 -52
- package/lib/common/utils.js +0 -30
- package/lib/common/varUintOps.js +0 -103
- package/lib/handler/SimpleHandler.js +0 -124
- package/lib/handler/common.js +0 -10
- package/lib/index.js +0 -8
- package/lib/net/BrowserWsNet.js +0 -103
- package/lib/net/JsonPackageWrapper.js +0 -43
- package/lib/net/LazyConn.js +0 -77
- package/lib/net/NetErrorString.js +0 -14
- package/lib/net/PackageWrapper.js +0 -71
- package/lib/net/TimeoutMonitor.js +0 -70
- package/lib/net/TypedPkgHub.js +0 -307
- package/lib/net/hubPkgSerializer.js +0 -14
- package/lib/net/interfaces.js +0 -2
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { DataWrapper } from '../common/DataWrapper';
|
|
2
|
-
export { ErrorWrapper, MessageWrapper, EventWrapper, RequestWrapper, };
|
|
3
|
-
class PkgWrapper extends DataWrapper {
|
|
4
|
-
static context;
|
|
5
|
-
static registerPkgType(pkgType) {
|
|
6
|
-
let c;
|
|
7
|
-
try {
|
|
8
|
-
c = this.pkgType;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
Object.defineProperty(this, 'pkgType', {
|
|
12
|
-
value: pkgType,
|
|
13
|
-
writable: false,
|
|
14
|
-
enumerable: false,
|
|
15
|
-
});
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (c !== pkgType) {
|
|
19
|
-
throw new Error(`Wrapper ${this.name} is already registered with type ${c}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
static get pkgType() {
|
|
23
|
-
throw new Error(`Wrapper ${this.name} need to be registered`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
class ErrorWrapper extends PkgWrapper {
|
|
27
|
-
isError() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
class MessageWrapper extends PkgWrapper {
|
|
32
|
-
isMessage() {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class EventWrapper extends PkgWrapper {
|
|
37
|
-
isEvent() {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
class RequestWrapper extends PkgWrapper {
|
|
42
|
-
constructor(a, needParse) {
|
|
43
|
-
super(a, needParse);
|
|
44
|
-
}
|
|
45
|
-
isRequest() {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
get resp() {
|
|
49
|
-
if (!this.B) {
|
|
50
|
-
this.B = this.decodeResponse(this.C);
|
|
51
|
-
}
|
|
52
|
-
return this.B;
|
|
53
|
-
}
|
|
54
|
-
set resp(b) {
|
|
55
|
-
this.B = b;
|
|
56
|
-
this.C = undefined;
|
|
57
|
-
}
|
|
58
|
-
get respBuff() {
|
|
59
|
-
if (!this.C) {
|
|
60
|
-
this.C = this.encodeResponse(this.B);
|
|
61
|
-
}
|
|
62
|
-
return this.C;
|
|
63
|
-
}
|
|
64
|
-
set respBuff(b) {
|
|
65
|
-
this.B = undefined;
|
|
66
|
-
this.C = b;
|
|
67
|
-
}
|
|
68
|
-
B;
|
|
69
|
-
C;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=PackageWrapper.js.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ListNode, c } from '../common/List';
|
|
2
|
-
import { l } from '../common/utils';
|
|
3
|
-
export class MonitorConn extends ListNode {
|
|
4
|
-
}
|
|
5
|
-
export class TimeoutMonitor {
|
|
6
|
-
constructor(f, h, g) {
|
|
7
|
-
this.a0 = f;
|
|
8
|
-
this.O = h;
|
|
9
|
-
this.I = g;
|
|
10
|
-
this.p = 0;
|
|
11
|
-
this.J = 0;
|
|
12
|
-
this.r = [];
|
|
13
|
-
if (f === 0) {
|
|
14
|
-
this.insert = l;
|
|
15
|
-
this.update = l;
|
|
16
|
-
this.remove = l;
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
for (let a = 0; a < g; a++) {
|
|
20
|
-
this.r.push(new c());
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
insert(conn) {
|
|
24
|
-
if (!this.J) {
|
|
25
|
-
this.a1 = setInterval(this.ab, this.a0);
|
|
26
|
-
}
|
|
27
|
-
this.J++;
|
|
28
|
-
this.r[this.p].Z(conn);
|
|
29
|
-
}
|
|
30
|
-
update(conn) {
|
|
31
|
-
conn.remove();
|
|
32
|
-
this.r[this.p].Z(conn);
|
|
33
|
-
}
|
|
34
|
-
remove(conn) {
|
|
35
|
-
conn.remove();
|
|
36
|
-
this.J--;
|
|
37
|
-
if (!this.J) {
|
|
38
|
-
clearInterval(this.a1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
ab = () => {
|
|
42
|
-
const { O, I, r } = this;
|
|
43
|
-
this.p++;
|
|
44
|
-
if (this.p === I) {
|
|
45
|
-
this.p = 0;
|
|
46
|
-
}
|
|
47
|
-
if (O) {
|
|
48
|
-
let d = this.p + O;
|
|
49
|
-
if (d >= I) {
|
|
50
|
-
d -= I;
|
|
51
|
-
}
|
|
52
|
-
const b = r[d];
|
|
53
|
-
for (let node = b.e; !b.Y(node); node = node.getNext()) {
|
|
54
|
-
node.keepAlive();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const b = r[this.p];
|
|
58
|
-
for (let node = b.e; !b.Y(node); node = node.getNext()) {
|
|
59
|
-
node.timeout();
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
a0;
|
|
63
|
-
O;
|
|
64
|
-
I;
|
|
65
|
-
p;
|
|
66
|
-
J;
|
|
67
|
-
a1;
|
|
68
|
-
r;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=TimeoutMonitor.js.map
|
package/lib/net/TypedPkgHub.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import { z, l } from '../common/utils';
|
|
2
|
-
import { NetErrorString } from './NetErrorString';
|
|
3
|
-
import { MonitorConn } from './TimeoutMonitor';
|
|
4
|
-
export class u {
|
|
5
|
-
constructor(B, v) {
|
|
6
|
-
const { responsePkgType, timeoutMonitor, makePkgBuff, parsePkgBuff } = v;
|
|
7
|
-
this.responsePkgType = responsePkgType;
|
|
8
|
-
this.s = 0;
|
|
9
|
-
this.t = new Map();
|
|
10
|
-
this.h = new Map();
|
|
11
|
-
this.T = new Map();
|
|
12
|
-
this.a2 = makePkgBuff;
|
|
13
|
-
this.a3 = parsePkgBuff;
|
|
14
|
-
this.E = B;
|
|
15
|
-
this.P = timeoutMonitor;
|
|
16
|
-
const M = this;
|
|
17
|
-
M.y = this.ac;
|
|
18
|
-
const r = [];
|
|
19
|
-
this.a2(responsePkgType, 0x200000, r);
|
|
20
|
-
this.a4 = {
|
|
21
|
-
makePkgBuff: makePkgBuff,
|
|
22
|
-
responsePkgType: responsePkgType,
|
|
23
|
-
r: z(r),
|
|
24
|
-
};
|
|
25
|
-
this.h.set(responsePkgType, M);
|
|
26
|
-
this.E.I((c, p) => {
|
|
27
|
-
do {
|
|
28
|
-
this.s++;
|
|
29
|
-
} while (this.t.has(this.s & 0x1fffff));
|
|
30
|
-
const conn = new w(this.a4, c, this.s & 0x1fffff);
|
|
31
|
-
this.t.set(conn.id, conn);
|
|
32
|
-
this.P?.insert(conn);
|
|
33
|
-
const g = {
|
|
34
|
-
conn,
|
|
35
|
-
A: (buff) => this.ad(conn, buff),
|
|
36
|
-
o: (err) => this.ae(conn, err),
|
|
37
|
-
};
|
|
38
|
-
this.Q?.(this, conn, !!p);
|
|
39
|
-
return g;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
responsePkgType;
|
|
43
|
-
context;
|
|
44
|
-
Q;
|
|
45
|
-
K;
|
|
46
|
-
b() {
|
|
47
|
-
return this.E.b();
|
|
48
|
-
}
|
|
49
|
-
S(x) {
|
|
50
|
-
return this.t.get(x);
|
|
51
|
-
}
|
|
52
|
-
d(e) {
|
|
53
|
-
return this.E.d(e);
|
|
54
|
-
}
|
|
55
|
-
async V() {
|
|
56
|
-
do {
|
|
57
|
-
this.s++;
|
|
58
|
-
} while (this.t.has(this.s & 0x1fffff));
|
|
59
|
-
const conn = new a0(this.s & 0x1fffff, this);
|
|
60
|
-
this.t.set(conn.id, conn);
|
|
61
|
-
return conn;
|
|
62
|
-
}
|
|
63
|
-
async W(e) {
|
|
64
|
-
return this.E.J(e);
|
|
65
|
-
}
|
|
66
|
-
async X() {
|
|
67
|
-
return this.E.L();
|
|
68
|
-
}
|
|
69
|
-
af(conn, message) {
|
|
70
|
-
const pkgType = message.constructor.pkgType;
|
|
71
|
-
const handler = this.h.get(pkgType);
|
|
72
|
-
if (handler) {
|
|
73
|
-
return handler?.q(conn, message);
|
|
74
|
-
}
|
|
75
|
-
throw new Error(NetErrorString.$);
|
|
76
|
-
}
|
|
77
|
-
ag(conn, request) {
|
|
78
|
-
const pkgType = request.constructor.pkgType;
|
|
79
|
-
const handler = this.h.get(pkgType);
|
|
80
|
-
if (handler) {
|
|
81
|
-
return handler?.q(conn, request);
|
|
82
|
-
}
|
|
83
|
-
throw new Error(NetErrorString.$);
|
|
84
|
-
}
|
|
85
|
-
registerError(pkgType, wrapperCtor) {
|
|
86
|
-
wrapperCtor.registerPkgType(pkgType);
|
|
87
|
-
this.T.set(pkgType, wrapperCtor);
|
|
88
|
-
const a1 = this.h.get(this.responsePkgType);
|
|
89
|
-
this.h.set(pkgType, a1);
|
|
90
|
-
}
|
|
91
|
-
registerMessage(pkgType, wrapperCtor) {
|
|
92
|
-
wrapperCtor.registerPkgType(pkgType);
|
|
93
|
-
}
|
|
94
|
-
registerRequest(pkgType, wrapperCtor) {
|
|
95
|
-
wrapperCtor.registerPkgType(pkgType);
|
|
96
|
-
}
|
|
97
|
-
handleMessageWith(handler) {
|
|
98
|
-
const pkgType = handler.pkgType;
|
|
99
|
-
if (typeof pkgType !== typeof this.responsePkgType) {
|
|
100
|
-
throw new Error(`Wrapper ${handler.k} has an incompatible pkgType ${typeof pkgType}`);
|
|
101
|
-
}
|
|
102
|
-
if (this.h.has(pkgType)) {
|
|
103
|
-
throw new Error(`Wrapper ${handler.k} is already handled by another handler`);
|
|
104
|
-
}
|
|
105
|
-
this.h.set(pkgType, handler);
|
|
106
|
-
return handler;
|
|
107
|
-
}
|
|
108
|
-
handleRequestWith(handler) {
|
|
109
|
-
const pkgType = handler.pkgType;
|
|
110
|
-
if (typeof pkgType !== typeof this.responsePkgType) {
|
|
111
|
-
throw new Error(`Wrapper ${handler.k} has an incompatible pkgType ${typeof pkgType}`);
|
|
112
|
-
}
|
|
113
|
-
if (this.h.has(pkgType)) {
|
|
114
|
-
throw new Error(`Wrapper ${handler.k} is already handled by another handler`);
|
|
115
|
-
}
|
|
116
|
-
this.h.set(pkgType, handler);
|
|
117
|
-
return handler;
|
|
118
|
-
}
|
|
119
|
-
at(handler) {
|
|
120
|
-
const pkgType = handler.pkgType;
|
|
121
|
-
const a8 = this.h.get(pkgType);
|
|
122
|
-
if (a8 === handler) {
|
|
123
|
-
this.h.delete(pkgType);
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
ad(conn, buff) {
|
|
129
|
-
this.P?.update(conn);
|
|
130
|
-
const a = this.a3(buff);
|
|
131
|
-
const handler = this.h.get(a.pkgType);
|
|
132
|
-
if (handler) {
|
|
133
|
-
handler.y(conn, a);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
conn.close(new Error(NetErrorString.$));
|
|
137
|
-
}
|
|
138
|
-
ae(conn, err) {
|
|
139
|
-
const x = conn.id;
|
|
140
|
-
this.t.delete(x);
|
|
141
|
-
this.P?.remove(conn);
|
|
142
|
-
conn.o(err);
|
|
143
|
-
this.K?.(this, conn, conn.c.G(), err);
|
|
144
|
-
}
|
|
145
|
-
ac(conn, a) {
|
|
146
|
-
try {
|
|
147
|
-
const { buff, pkgType, requestId, bodyOffset } = a;
|
|
148
|
-
if (pkgType === this.responsePkgType) {
|
|
149
|
-
const body = buff.subarray(bodyOffset);
|
|
150
|
-
conn.a5(requestId, body);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
const R = this.T.get(pkgType);
|
|
154
|
-
if (R) {
|
|
155
|
-
const body = buff.subarray(bodyOffset);
|
|
156
|
-
const a9 = new R(body, true);
|
|
157
|
-
conn.ah(requestId, a9);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
conn.close(new Error(NetErrorString.$));
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
a4;
|
|
166
|
-
s;
|
|
167
|
-
a2;
|
|
168
|
-
a3;
|
|
169
|
-
E;
|
|
170
|
-
t;
|
|
171
|
-
h;
|
|
172
|
-
T;
|
|
173
|
-
P;
|
|
174
|
-
}
|
|
175
|
-
class w extends MonitorConn {
|
|
176
|
-
constructor(v, c, id) {
|
|
177
|
-
super();
|
|
178
|
-
this.id = id;
|
|
179
|
-
this.c = c;
|
|
180
|
-
this.F = v;
|
|
181
|
-
this.a6 = 0;
|
|
182
|
-
}
|
|
183
|
-
context;
|
|
184
|
-
id;
|
|
185
|
-
c;
|
|
186
|
-
get socket() {
|
|
187
|
-
return this.c.socket;
|
|
188
|
-
}
|
|
189
|
-
sendMessage(message) {
|
|
190
|
-
const pkgType = message.constructor.pkgType;
|
|
191
|
-
const encoded = [message.buff];
|
|
192
|
-
this.F.makePkgBuff(pkgType, 0, encoded);
|
|
193
|
-
return this.c.n(encoded);
|
|
194
|
-
}
|
|
195
|
-
sendRequest(request) {
|
|
196
|
-
this.m = new Map();
|
|
197
|
-
this.sendRequest = this.a7;
|
|
198
|
-
this.a5 = this.ai;
|
|
199
|
-
this.o = this.aj;
|
|
200
|
-
return this.a7(request);
|
|
201
|
-
}
|
|
202
|
-
sendErrorResponse(error, requestId) {
|
|
203
|
-
const pkgType = error.constructor.pkgType;
|
|
204
|
-
const encoded = [error.buff];
|
|
205
|
-
this.F.makePkgBuff(pkgType, requestId, encoded);
|
|
206
|
-
return this.c.n(encoded);
|
|
207
|
-
}
|
|
208
|
-
sendResponse(request, requestId) {
|
|
209
|
-
const encoded = [request.respBuff];
|
|
210
|
-
const { makePkgBuff, responsePkgType } = this.F;
|
|
211
|
-
makePkgBuff(responsePkgType, requestId, encoded);
|
|
212
|
-
return this.c.n(encoded);
|
|
213
|
-
}
|
|
214
|
-
async close(err) {
|
|
215
|
-
await this.c.close(err);
|
|
216
|
-
}
|
|
217
|
-
a5(requestId, an) {
|
|
218
|
-
if (requestId === 0x200000 && this.context === undefined) {
|
|
219
|
-
this.close(new Error(NetErrorString.H));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
ah(requestId, error) {
|
|
223
|
-
const i = this.m.get(requestId);
|
|
224
|
-
if (i) {
|
|
225
|
-
this.m.delete(requestId);
|
|
226
|
-
return i.j(error);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
keepAlive() {
|
|
230
|
-
this.c.D(this.F.r).catch(l);
|
|
231
|
-
}
|
|
232
|
-
timeout() {
|
|
233
|
-
this.close(new Error(NetErrorString.Z));
|
|
234
|
-
}
|
|
235
|
-
o(aa) {
|
|
236
|
-
}
|
|
237
|
-
async a7(request) {
|
|
238
|
-
const requestId = (this.a6++) & 0x1fffff;
|
|
239
|
-
const pkgType = request.constructor.pkgType;
|
|
240
|
-
const encoded = [request.buff];
|
|
241
|
-
this.F.makePkgBuff(pkgType, requestId, encoded);
|
|
242
|
-
const ab = new Promise((f, j) => {
|
|
243
|
-
const ak = { f, j };
|
|
244
|
-
this.m.set(requestId, ak);
|
|
245
|
-
this.c.n(encoded).catch((err) => {
|
|
246
|
-
this.m.delete(requestId);
|
|
247
|
-
j(err);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
request.respBuff = await ab;
|
|
251
|
-
}
|
|
252
|
-
ai(requestId, body) {
|
|
253
|
-
const i = this.m.get(requestId);
|
|
254
|
-
if (i) {
|
|
255
|
-
this.m.delete(requestId);
|
|
256
|
-
i.f(body);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
if (requestId === 0x200000 && this.context === undefined) {
|
|
260
|
-
this.close(new Error(NetErrorString.H));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
aj(err) {
|
|
264
|
-
const C = this.m;
|
|
265
|
-
if (C.size > 0) {
|
|
266
|
-
if (!err) {
|
|
267
|
-
err = new Error(NetErrorString.Y);
|
|
268
|
-
}
|
|
269
|
-
for (const [requestId, i] of C) {
|
|
270
|
-
C.delete(requestId);
|
|
271
|
-
i.j(err);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
this.m = undefined;
|
|
275
|
-
}
|
|
276
|
-
F;
|
|
277
|
-
m;
|
|
278
|
-
a6;
|
|
279
|
-
}
|
|
280
|
-
class a0 {
|
|
281
|
-
constructor(id, al) {
|
|
282
|
-
this.id = id;
|
|
283
|
-
this.U = al;
|
|
284
|
-
}
|
|
285
|
-
context;
|
|
286
|
-
id;
|
|
287
|
-
socket;
|
|
288
|
-
get remoteFamily() {
|
|
289
|
-
return 'Local';
|
|
290
|
-
}
|
|
291
|
-
async sendMessage(message) {
|
|
292
|
-
return this.U.af(this, message);
|
|
293
|
-
}
|
|
294
|
-
async sendRequest(request) {
|
|
295
|
-
return this.U.ag(this, request);
|
|
296
|
-
}
|
|
297
|
-
sendErrorResponse(ao, am) {
|
|
298
|
-
throw null;
|
|
299
|
-
}
|
|
300
|
-
sendResponse(ap, am) {
|
|
301
|
-
throw null;
|
|
302
|
-
}
|
|
303
|
-
async close(aa) {
|
|
304
|
-
}
|
|
305
|
-
U;
|
|
306
|
-
}
|
|
307
|
-
//# sourceMappingURL=TypedPkgHub.js.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { j, l, m } from '../common/varUintOps';
|
|
2
|
-
export const n = (pkgType, requestId, encoded) => {
|
|
3
|
-
const i = [requestId, pkgType];
|
|
4
|
-
const b = j(i);
|
|
5
|
-
const a = new Uint8Array(b);
|
|
6
|
-
m(i, a);
|
|
7
|
-
encoded.push(a);
|
|
8
|
-
};
|
|
9
|
-
export const o = (buff) => {
|
|
10
|
-
const { h: [requestId, pkgType], k: bodyOffset } = l(2, buff);
|
|
11
|
-
const result = { buff, pkgType, requestId, bodyOffset };
|
|
12
|
-
return result;
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=hubPkgSerializer.js.map
|
package/lib/net/interfaces.js
DELETED