@welshman/net 0.0.32 → 0.0.34
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/build/src/Connection.cjs +32 -84
- package/build/src/Connection.cjs.map +1 -1
- package/build/src/Connection.d.ts +19 -21
- package/build/src/Connection.mjs +34 -86
- package/build/src/Connection.mjs.map +1 -1
- package/build/src/ConnectionAuth.cjs +28 -38
- package/build/src/ConnectionAuth.cjs.map +1 -1
- package/build/src/ConnectionAuth.d.ts +7 -11
- package/build/src/ConnectionAuth.mjs +28 -38
- package/build/src/ConnectionAuth.mjs.map +1 -1
- package/build/src/ConnectionEvent.cjs +16 -0
- package/build/src/ConnectionEvent.cjs.map +1 -0
- package/build/src/ConnectionEvent.d.ts +11 -0
- package/build/src/ConnectionEvent.mjs +13 -0
- package/build/src/ConnectionEvent.mjs.map +1 -0
- package/build/src/ConnectionSender.cjs +50 -0
- package/build/src/ConnectionSender.cjs.map +1 -0
- package/build/src/ConnectionSender.d.ts +10 -0
- package/build/src/ConnectionSender.mjs +46 -0
- package/build/src/ConnectionSender.mjs.map +1 -0
- package/build/src/ConnectionState.cjs +68 -0
- package/build/src/ConnectionState.cjs.map +1 -0
- package/build/src/ConnectionState.d.ts +17 -0
- package/build/src/ConnectionState.mjs +64 -0
- package/build/src/ConnectionState.mjs.map +1 -0
- package/build/src/ConnectionStats.cjs +86 -0
- package/build/src/ConnectionStats.cjs.map +1 -0
- package/build/src/ConnectionStats.d.ts +26 -0
- package/build/src/ConnectionStats.mjs +82 -0
- package/build/src/ConnectionStats.mjs.map +1 -0
- package/build/src/Pool.cjs +9 -15
- package/build/src/Pool.cjs.map +1 -1
- package/build/src/Pool.d.ts +1 -4
- package/build/src/Pool.mjs +9 -15
- package/build/src/Pool.mjs.map +1 -1
- package/build/src/Socket.cjs +94 -53
- package/build/src/Socket.cjs.map +1 -1
- package/build/src/Socket.d.ts +21 -28
- package/build/src/Socket.mjs +94 -51
- package/build/src/Socket.mjs.map +1 -1
- package/build/src/Subscribe.cjs +16 -4
- package/build/src/Subscribe.cjs.map +1 -1
- package/build/src/Subscribe.mjs +17 -5
- package/build/src/Subscribe.mjs.map +1 -1
- package/build/src/index.cjs +4 -2
- package/build/src/index.cjs.map +1 -1
- package/build/src/index.d.ts +4 -2
- package/build/src/index.mjs +4 -2
- package/build/src/target/Relay.cjs +3 -2
- package/build/src/target/Relay.cjs.map +1 -1
- package/build/src/target/Relay.mjs +3 -2
- package/build/src/target/Relay.mjs.map +1 -1
- package/build/src/target/Relays.cjs +2 -1
- package/build/src/target/Relays.cjs.map +1 -1
- package/build/src/target/Relays.mjs +2 -1
- package/build/src/target/Relays.mjs.map +1 -1
- package/package.json +3 -3
- package/build/src/ConnectionMeta.cjs +0 -139
- package/build/src/ConnectionMeta.cjs.map +0 -1
- package/build/src/ConnectionMeta.d.ts +0 -48
- package/build/src/ConnectionMeta.mjs +0 -135
- package/build/src/ConnectionMeta.mjs.map +0 -1
- package/build/src/target/Plex.cjs +0 -27
- package/build/src/target/Plex.cjs.map +0 -1
- package/build/src/target/Plex.d.ts +0 -12
- package/build/src/target/Plex.mjs +0 -23
- package/build/src/target/Plex.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionAuth.mjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;;OAAO,EAAC,GAAG,EAAE,KAAK,EAAC,MAAM,eAAe;OACjC,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,gBAAgB;
|
|
1
|
+
{"version":3,"file":"ConnectionAuth.mjs","sourceRoot":"","sources":["../../src/ConnectionAuth.ts"],"names":[],"mappings":";;;;;;OAAO,EAAC,GAAG,EAAE,KAAK,EAAC,MAAM,eAAe;OACjC,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,gBAAgB;OAChD,EAAC,eAAe,EAAC;AAIxB,MAAM,CAAN,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB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AAK,EAAE,uBAAA,IAAI,+BAAS,CAAC,CAAA;QACjD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,OAAO,EAAE,uBAAA,IAAI,iCAAW,CAAC,CAAA;IACvD,CAAC;CA2FF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionEvent = void 0;
|
|
4
|
+
var ConnectionEvent;
|
|
5
|
+
(function (ConnectionEvent) {
|
|
6
|
+
ConnectionEvent["InvalidUrl"] = "invalid:url";
|
|
7
|
+
ConnectionEvent["InvalidMessage"] = "invalid:message:receive";
|
|
8
|
+
ConnectionEvent["Open"] = "socket:open";
|
|
9
|
+
ConnectionEvent["Reset"] = "socket:reset";
|
|
10
|
+
ConnectionEvent["Close"] = "socket:close";
|
|
11
|
+
ConnectionEvent["Error"] = "socket:error";
|
|
12
|
+
ConnectionEvent["Receive"] = "receive:message";
|
|
13
|
+
ConnectionEvent["Notice"] = "receive:notice";
|
|
14
|
+
ConnectionEvent["Send"] = "send:message";
|
|
15
|
+
})(ConnectionEvent || (exports.ConnectionEvent = ConnectionEvent = {}));
|
|
16
|
+
//# sourceMappingURL=ConnectionEvent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionEvent.cjs","sourceRoot":"","sources":["../../src/ConnectionEvent.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAUX;AAVD,WAAY,eAAe;IACzB,6CAA0B,CAAA;IAC1B,6DAA0C,CAAA;IAC1C,uCAAoB,CAAA;IACpB,yCAAsB,CAAA;IACtB,yCAAsB,CAAA;IACtB,yCAAsB,CAAA;IACtB,8CAA2B,CAAA;IAC3B,4CAAyB,CAAA;IACzB,wCAAqB,CAAA;AACvB,CAAC,EAVW,eAAe,+BAAf,eAAe,QAU1B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare enum ConnectionEvent {
|
|
2
|
+
InvalidUrl = "invalid:url",
|
|
3
|
+
InvalidMessage = "invalid:message:receive",
|
|
4
|
+
Open = "socket:open",
|
|
5
|
+
Reset = "socket:reset",
|
|
6
|
+
Close = "socket:close",
|
|
7
|
+
Error = "socket:error",
|
|
8
|
+
Receive = "receive:message",
|
|
9
|
+
Notice = "receive:notice",
|
|
10
|
+
Send = "send:message"
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export var ConnectionEvent;
|
|
2
|
+
(function (ConnectionEvent) {
|
|
3
|
+
ConnectionEvent["InvalidUrl"] = "invalid:url";
|
|
4
|
+
ConnectionEvent["InvalidMessage"] = "invalid:message:receive";
|
|
5
|
+
ConnectionEvent["Open"] = "socket:open";
|
|
6
|
+
ConnectionEvent["Reset"] = "socket:reset";
|
|
7
|
+
ConnectionEvent["Close"] = "socket:close";
|
|
8
|
+
ConnectionEvent["Error"] = "socket:error";
|
|
9
|
+
ConnectionEvent["Receive"] = "receive:message";
|
|
10
|
+
ConnectionEvent["Notice"] = "receive:notice";
|
|
11
|
+
ConnectionEvent["Send"] = "send:message";
|
|
12
|
+
})(ConnectionEvent || (ConnectionEvent = {}));
|
|
13
|
+
//# sourceMappingURL=ConnectionEvent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionEvent.mjs","sourceRoot":"","sources":["../../src/ConnectionEvent.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,eAUX;AAVD,WAAY,eAAe;IACzB,6CAA0B,CAAA;IAC1B,6DAA0C,CAAA;IAC1C,uCAAoB,CAAA;IACpB,yCAAsB,CAAA;IACtB,yCAAsB,CAAA;IACtB,yCAAsB,CAAA;IACtB,8CAA2B,CAAA;IAC3B,4CAAyB,CAAA;IACzB,wCAAqB,CAAA;AACvB,CAAC,EAVW,eAAe,KAAf,eAAe,QAU1B"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionSender = void 0;
|
|
4
|
+
const lib_1 = require("@welshman/lib");
|
|
5
|
+
const util_1 = require("@welshman/util");
|
|
6
|
+
const Socket_1 = require("./Socket.cjs");
|
|
7
|
+
const ConnectionAuth_1 = require("./ConnectionAuth.cjs");
|
|
8
|
+
class ConnectionSender {
|
|
9
|
+
constructor(cxn) {
|
|
10
|
+
this.cxn = cxn;
|
|
11
|
+
this.push = (message) => {
|
|
12
|
+
this.worker.push(message);
|
|
13
|
+
};
|
|
14
|
+
this.close = async () => {
|
|
15
|
+
this.worker.pause();
|
|
16
|
+
};
|
|
17
|
+
this.worker = new lib_1.Worker({
|
|
18
|
+
shouldDefer: ([verb, ...extra]) => {
|
|
19
|
+
// If we're not connected, nothing we can do
|
|
20
|
+
if (this.cxn.socket.status !== Socket_1.SocketStatus.Open)
|
|
21
|
+
return true;
|
|
22
|
+
// Always allow sending AUTH
|
|
23
|
+
if (verb === 'AUTH')
|
|
24
|
+
return false;
|
|
25
|
+
// Only close reqs that have been sent
|
|
26
|
+
if (verb === 'CLOSE')
|
|
27
|
+
return !this.cxn.state.pendingRequests.has(extra[0]);
|
|
28
|
+
// Always allow sending join requests
|
|
29
|
+
if (verb === 'EVENT' && extra[0].kind === util_1.AUTH_JOIN)
|
|
30
|
+
return false;
|
|
31
|
+
// Wait for auth
|
|
32
|
+
if (![ConnectionAuth_1.AuthStatus.None, ConnectionAuth_1.AuthStatus.Ok].includes(this.cxn.auth.status))
|
|
33
|
+
return true;
|
|
34
|
+
// Limit concurrent requests
|
|
35
|
+
if (verb === 'REQ')
|
|
36
|
+
return this.cxn.state.pendingRequests.size >= 8;
|
|
37
|
+
return false;
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this.worker.addGlobalHandler(([verb, ...extra]) => {
|
|
41
|
+
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
|
|
42
|
+
if (verb === 'CLOSE') {
|
|
43
|
+
this.worker.buffer = this.worker.buffer.filter(m => !(m[0] === 'REQ' && m[1] === extra[0]));
|
|
44
|
+
}
|
|
45
|
+
this.cxn.socket.send([verb, ...extra]);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ConnectionSender = ConnectionSender;
|
|
50
|
+
//# sourceMappingURL=ConnectionSender.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionSender.cjs","sourceRoot":"","sources":["../../src/ConnectionSender.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AACpC,yCAAwC;AACxC,yCAAqC;AAGrC,yDAA2C;AAE3C,MAAa,gBAAgB;IAG3B,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAmCpC,SAAI,GAAG,CAAC,OAAgB,EAAE,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3B,CAAC,CAAA;QAED,UAAK,GAAG,KAAK,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC,CAAA;QAxCC,IAAI,CAAC,MAAM,GAAG,IAAI,YAAM,CAAC;YACvB,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;gBACzC,4CAA4C;gBAC5C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,qBAAY,CAAC,IAAI;oBAAE,OAAO,IAAI,CAAA;gBAE7D,4BAA4B;gBAC5B,IAAI,IAAI,KAAK,MAAM;oBAAE,OAAO,KAAK,CAAA;gBAEjC,sCAAsC;gBACtC,IAAI,IAAI,KAAK,OAAO;oBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE1E,qCAAqC;gBACrC,IAAI,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,gBAAS;oBAAE,OAAO,KAAK,CAAA;gBAEjE,gBAAgB;gBAChB,IAAI,CAAC,CAAC,2BAAU,CAAC,IAAI,EAAE,2BAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAEjF,4BAA4B;gBAC5B,IAAI,IAAI,KAAK,KAAK;oBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAA;gBAEnE,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;YACzD,gFAAgF;YAChF,IAAI,IAAI,KAAK,OAAO,EAAE;gBACpB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;aAC5F;YAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC;CASF;AA7CD,4CA6CC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Worker } from '@welshman/lib';
|
|
2
|
+
import type { Message } from './Socket';
|
|
3
|
+
import type { Connection } from './Connection';
|
|
4
|
+
export declare class ConnectionSender {
|
|
5
|
+
readonly cxn: Connection;
|
|
6
|
+
worker: Worker<Message>;
|
|
7
|
+
constructor(cxn: Connection);
|
|
8
|
+
push: (message: Message) => void;
|
|
9
|
+
close: () => Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Worker } from '@welshman/lib';
|
|
2
|
+
import { AUTH_JOIN } from '@welshman/util';
|
|
3
|
+
import { SocketStatus } from "./Socket.mjs";
|
|
4
|
+
import { AuthStatus } from "./ConnectionAuth.mjs";
|
|
5
|
+
export class ConnectionSender {
|
|
6
|
+
constructor(cxn) {
|
|
7
|
+
this.cxn = cxn;
|
|
8
|
+
this.push = (message) => {
|
|
9
|
+
this.worker.push(message);
|
|
10
|
+
};
|
|
11
|
+
this.close = async () => {
|
|
12
|
+
this.worker.pause();
|
|
13
|
+
};
|
|
14
|
+
this.worker = new Worker({
|
|
15
|
+
shouldDefer: ([verb, ...extra]) => {
|
|
16
|
+
// If we're not connected, nothing we can do
|
|
17
|
+
if (this.cxn.socket.status !== SocketStatus.Open)
|
|
18
|
+
return true;
|
|
19
|
+
// Always allow sending AUTH
|
|
20
|
+
if (verb === 'AUTH')
|
|
21
|
+
return false;
|
|
22
|
+
// Only close reqs that have been sent
|
|
23
|
+
if (verb === 'CLOSE')
|
|
24
|
+
return !this.cxn.state.pendingRequests.has(extra[0]);
|
|
25
|
+
// Always allow sending join requests
|
|
26
|
+
if (verb === 'EVENT' && extra[0].kind === AUTH_JOIN)
|
|
27
|
+
return false;
|
|
28
|
+
// Wait for auth
|
|
29
|
+
if (![AuthStatus.None, AuthStatus.Ok].includes(this.cxn.auth.status))
|
|
30
|
+
return true;
|
|
31
|
+
// Limit concurrent requests
|
|
32
|
+
if (verb === 'REQ')
|
|
33
|
+
return this.cxn.state.pendingRequests.size >= 8;
|
|
34
|
+
return false;
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
this.worker.addGlobalHandler(([verb, ...extra]) => {
|
|
38
|
+
// If we ended up handling a CLOSE before we handled the REQ, don't send the REQ
|
|
39
|
+
if (verb === 'CLOSE') {
|
|
40
|
+
this.worker.buffer = this.worker.buffer.filter(m => !(m[0] === 'REQ' && m[1] === extra[0]));
|
|
41
|
+
}
|
|
42
|
+
this.cxn.socket.send([verb, ...extra]);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=ConnectionSender.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionSender.mjs","sourceRoot":"","sources":["../../src/ConnectionSender.ts"],"names":[],"mappings":"OAAO,EAAC,MAAM,EAAC,MAAM,eAAe;OAC7B,EAAC,SAAS,EAAC,MAAM,gBAAgB;OACjC,EAAC,YAAY,EAAC;OAGd,EAAC,UAAU,EAAC;AAEnB,MAAM,OAAO,gBAAgB;IAG3B,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAmCpC,SAAI,GAAG,CAAC,OAAgB,EAAE,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3B,CAAC,CAAA;QAED,UAAK,GAAG,KAAK,IAAI,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC,CAAA;QAxCC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC;YACvB,WAAW,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;gBACzC,4CAA4C;gBAC5C,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,YAAY,CAAC,IAAI;oBAAE,OAAO,IAAI,CAAA;gBAE7D,4BAA4B;gBAC5B,IAAI,IAAI,KAAK,MAAM;oBAAE,OAAO,KAAK,CAAA;gBAEjC,sCAAsC;gBACtC,IAAI,IAAI,KAAK,OAAO;oBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE1E,qCAAqC;gBACrC,IAAI,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS;oBAAE,OAAO,KAAK,CAAA;gBAEjE,gBAAgB;gBAChB,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAEjF,4BAA4B;gBAC5B,IAAI,IAAI,KAAK,KAAK;oBAAE,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,CAAA;gBAEnE,OAAO,KAAK,CAAA;YACd,CAAC;SACF,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;YACzD,gFAAgF;YAChF,IAAI,IAAI,KAAK,OAAO,EAAE;gBACpB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;aAC5F;YAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC;CASF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionState = void 0;
|
|
4
|
+
const util_1 = require("@welshman/util");
|
|
5
|
+
const ConnectionEvent_1 = require("./ConnectionEvent.cjs");
|
|
6
|
+
class ConnectionState {
|
|
7
|
+
constructor(cxn) {
|
|
8
|
+
this.cxn = cxn;
|
|
9
|
+
this.pendingPublishes = new Map();
|
|
10
|
+
this.pendingRequests = new Map();
|
|
11
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Send, (cxn, [verb, ...extra]) => {
|
|
12
|
+
if (verb === 'REQ') {
|
|
13
|
+
const [reqId, ...filters] = extra;
|
|
14
|
+
this.pendingRequests.set(reqId, { filters, sent: Date.now() });
|
|
15
|
+
}
|
|
16
|
+
if (verb === 'CLOSE') {
|
|
17
|
+
const [reqId] = extra;
|
|
18
|
+
this.pendingRequests.delete(reqId);
|
|
19
|
+
}
|
|
20
|
+
if (verb === 'EVENT') {
|
|
21
|
+
const [event] = extra;
|
|
22
|
+
this.pendingPublishes.set(event.id, { sent: Date.now(), event: event.id });
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Receive, (cxn, [verb, ...extra]) => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (verb === 'OK') {
|
|
28
|
+
const [eventId, _ok, notice] = extra;
|
|
29
|
+
const pub = this.pendingPublishes.get(eventId);
|
|
30
|
+
if (!pub)
|
|
31
|
+
return;
|
|
32
|
+
// Re-enqueue pending events when auth challenge is received
|
|
33
|
+
if ((notice === null || notice === void 0 ? void 0 : notice.startsWith('auth-required:')) && pub.event.kind !== util_1.AUTH_JOIN) {
|
|
34
|
+
this.cxn.send(['EVENT', pub.event]);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.pendingPublishes.delete(eventId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (verb === 'EOSE') {
|
|
41
|
+
const [reqId] = extra;
|
|
42
|
+
const req = this.pendingRequests.get(reqId);
|
|
43
|
+
if (req) {
|
|
44
|
+
req.eose = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (verb === 'CLOSED') {
|
|
48
|
+
const [reqId] = extra;
|
|
49
|
+
// Re-enqueue pending reqs when auth challenge is received
|
|
50
|
+
if ((_a = extra[1]) === null || _a === void 0 ? void 0 : _a.startsWith('auth-required:')) {
|
|
51
|
+
const req = this.pendingRequests.get(reqId);
|
|
52
|
+
if (req) {
|
|
53
|
+
this.cxn.send(['REQ', reqId, ...req.filters]);
|
|
54
|
+
}
|
|
55
|
+
if (extra[1]) {
|
|
56
|
+
this.cxn.emit(ConnectionEvent_1.ConnectionEvent.Notice, extra[1]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (verb === 'NOTICE') {
|
|
61
|
+
const [notice] = extra;
|
|
62
|
+
this.cxn.emit(ConnectionEvent_1.ConnectionEvent.Notice, notice);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ConnectionState = ConnectionState;
|
|
68
|
+
//# sourceMappingURL=ConnectionState.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionState.cjs","sourceRoot":"","sources":["../../src/ConnectionState.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAIxC,2DAAiD;AAajD,MAAa,eAAe;IAI1B,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAHpC,qBAAgB,GAAG,IAAI,GAAG,EAAwB,CAAA;QAClD,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAA;QAG/C,GAAG,CAAC,EAAE,CAAC,iCAAe,CAAC,IAAI,EAAE,CAAC,GAAe,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,CAAU,EAAE,EAAE;YAC1E,IAAI,IAAI,KAAK,KAAK,EAAE;gBAClB,MAAM,CAAC,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,KAAK,CAAA;gBAEjC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GA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AG,KAAK,CAAA;gBACrB,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;gBAE3C,IAAI,GAAG,EAAE;oBACP,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;iBAChB;aACF;YAED,IAAI,IAAI,KAAK,QAAQ,EAAE;gBACrB,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAA;gBAErB,0DAA0D;gBAC1D,IAAI,MAAA,KAAK,CAAC,CAAC,CAAC,0CAAE,UAAU,CAAC,gBAAgB,CAAC,EAAE;oBAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBAE3C,IAAI,GAAG,EAAE;wBACP,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;qBAC9C;oBAED,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;wBACZ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iCAAe,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;qBAChD;iBACF;aACF;YAED,IAAI,IAAI,KAAK,QAAQ,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAA;gBAEtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iCAAe,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;aAC9C;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAzED,0CAyEC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SignedEvent, Filter } from '@welshman/util';
|
|
2
|
+
import type { Connection } from './Connection';
|
|
3
|
+
export type PublishState = {
|
|
4
|
+
sent: number;
|
|
5
|
+
event: SignedEvent;
|
|
6
|
+
};
|
|
7
|
+
export type RequestState = {
|
|
8
|
+
sent: number;
|
|
9
|
+
filters: Filter[];
|
|
10
|
+
eose?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare class ConnectionState {
|
|
13
|
+
readonly cxn: Connection;
|
|
14
|
+
pendingPublishes: Map<string, PublishState>;
|
|
15
|
+
pendingRequests: Map<string, RequestState>;
|
|
16
|
+
constructor(cxn: Connection);
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { AUTH_JOIN } from '@welshman/util';
|
|
2
|
+
import { ConnectionEvent } from "./ConnectionEvent.mjs";
|
|
3
|
+
export class ConnectionState {
|
|
4
|
+
constructor(cxn) {
|
|
5
|
+
this.cxn = cxn;
|
|
6
|
+
this.pendingPublishes = new Map();
|
|
7
|
+
this.pendingRequests = new Map();
|
|
8
|
+
cxn.on(ConnectionEvent.Send, (cxn, [verb, ...extra]) => {
|
|
9
|
+
if (verb === 'REQ') {
|
|
10
|
+
const [reqId, ...filters] = extra;
|
|
11
|
+
this.pendingRequests.set(reqId, { filters, sent: Date.now() });
|
|
12
|
+
}
|
|
13
|
+
if (verb === 'CLOSE') {
|
|
14
|
+
const [reqId] = extra;
|
|
15
|
+
this.pendingRequests.delete(reqId);
|
|
16
|
+
}
|
|
17
|
+
if (verb === 'EVENT') {
|
|
18
|
+
const [event] = extra;
|
|
19
|
+
this.pendingPublishes.set(event.id, { sent: Date.now(), event: event.id });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
cxn.on(ConnectionEvent.Receive, (cxn, [verb, ...extra]) => {
|
|
23
|
+
var _a;
|
|
24
|
+
if (verb === 'OK') {
|
|
25
|
+
const [eventId, _ok, notice] = extra;
|
|
26
|
+
const pub = this.pendingPublishes.get(eventId);
|
|
27
|
+
if (!pub)
|
|
28
|
+
return;
|
|
29
|
+
// Re-enqueue pending events when auth challenge is received
|
|
30
|
+
if ((notice === null || notice === void 0 ? void 0 : notice.startsWith('auth-required:')) && pub.event.kind !== AUTH_JOIN) {
|
|
31
|
+
this.cxn.send(['EVENT', pub.event]);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.pendingPublishes.delete(eventId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (verb === 'EOSE') {
|
|
38
|
+
const [reqId] = extra;
|
|
39
|
+
const req = this.pendingRequests.get(reqId);
|
|
40
|
+
if (req) {
|
|
41
|
+
req.eose = true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (verb === 'CLOSED') {
|
|
45
|
+
const [reqId] = extra;
|
|
46
|
+
// Re-enqueue pending reqs when auth challenge is received
|
|
47
|
+
if ((_a = extra[1]) === null || _a === void 0 ? void 0 : _a.startsWith('auth-required:')) {
|
|
48
|
+
const req = this.pendingRequests.get(reqId);
|
|
49
|
+
if (req) {
|
|
50
|
+
this.cxn.send(['REQ', reqId, ...req.filters]);
|
|
51
|
+
}
|
|
52
|
+
if (extra[1]) {
|
|
53
|
+
this.cxn.emit(ConnectionEvent.Notice, extra[1]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (verb === 'NOTICE') {
|
|
58
|
+
const [notice] = extra;
|
|
59
|
+
this.cxn.emit(ConnectionEvent.Notice, notice);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=ConnectionState.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionState.mjs","sourceRoot":"","sources":["../../src/ConnectionState.ts"],"names":[],"mappings":"OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB;OAIjC,EAAC,eAAe,EAAC;AAaxB,MAAM,OAAO,eAAe;IAI1B,YAAqB,GAAe;QAAf,QAAG,GAAH,GAAG,CAAY;QAHpC,qBAAgB,GAAG,IAAI,GAAG,EAAwB,CAAA;QAClD,oBAAe,GAAG,IAAI,GAAG,EAAwB,CAAA;QAG/C,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,GAAe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}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectionStats = void 0;
|
|
4
|
+
const ConnectionEvent_1 = require("./ConnectionEvent.cjs");
|
|
5
|
+
class ConnectionStats {
|
|
6
|
+
constructor(cxn) {
|
|
7
|
+
this.cxn = cxn;
|
|
8
|
+
this.openCount = 0;
|
|
9
|
+
this.closeCount = 0;
|
|
10
|
+
this.errorCount = 0;
|
|
11
|
+
this.publishCount = 0;
|
|
12
|
+
this.requestCount = 0;
|
|
13
|
+
this.eventCount = 0;
|
|
14
|
+
this.lastOpen = 0;
|
|
15
|
+
this.lastClose = 0;
|
|
16
|
+
this.lastError = 0;
|
|
17
|
+
this.lastPublish = 0;
|
|
18
|
+
this.lastRequest = 0;
|
|
19
|
+
this.lastEvent = 0;
|
|
20
|
+
this.lastAuth = 0;
|
|
21
|
+
this.publishTimer = 0;
|
|
22
|
+
this.publishSuccessCount = 0;
|
|
23
|
+
this.publishFailureCount = 0;
|
|
24
|
+
this.eoseCount = 0;
|
|
25
|
+
this.eoseTimer = 0;
|
|
26
|
+
this.noticeCount = 0;
|
|
27
|
+
this.getRequestSpeed = () => this.eoseCount ? this.eoseTimer / this.eoseCount : 0;
|
|
28
|
+
this.getPublishSpeed = () => this.publishSuccessCount ? this.publishTimer / this.publishSuccessCount : 0;
|
|
29
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Open, (cxn) => {
|
|
30
|
+
this.openCount++;
|
|
31
|
+
this.lastOpen = Date.now();
|
|
32
|
+
});
|
|
33
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Close, (cxn) => {
|
|
34
|
+
this.closeCount++;
|
|
35
|
+
this.lastClose = Date.now();
|
|
36
|
+
});
|
|
37
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Error, (cxn) => {
|
|
38
|
+
this.errorCount++;
|
|
39
|
+
this.lastError = Date.now();
|
|
40
|
+
});
|
|
41
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Send, (cxn, [verb]) => {
|
|
42
|
+
if (verb === 'REQ') {
|
|
43
|
+
this.requestCount++;
|
|
44
|
+
this.lastRequest = Date.now();
|
|
45
|
+
}
|
|
46
|
+
if (verb === 'EVENT') {
|
|
47
|
+
this.publishCount++;
|
|
48
|
+
this.lastPublish = Date.now();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
cxn.on(ConnectionEvent_1.ConnectionEvent.Receive, (cxn, [verb, ...extra]) => {
|
|
52
|
+
if (verb === 'OK') {
|
|
53
|
+
const pub = this.cxn.state.pendingPublishes.get(extra[0]);
|
|
54
|
+
if (pub) {
|
|
55
|
+
this.publishTimer += Date.now() - pub.sent;
|
|
56
|
+
}
|
|
57
|
+
if (extra[1]) {
|
|
58
|
+
this.publishSuccessCount++;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.publishFailureCount++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (verb === 'AUTH') {
|
|
65
|
+
this.lastAuth = Date.now();
|
|
66
|
+
}
|
|
67
|
+
if (verb === 'EVENT') {
|
|
68
|
+
this.eventCount++;
|
|
69
|
+
this.lastEvent = Date.now();
|
|
70
|
+
}
|
|
71
|
+
if (verb === 'EOSE') {
|
|
72
|
+
const request = this.cxn.state.pendingRequests.get(extra[0]);
|
|
73
|
+
// Only count the first eose
|
|
74
|
+
if (request && !request.eose) {
|
|
75
|
+
this.eoseCount++;
|
|
76
|
+
this.eoseTimer += Date.now() - request.sent;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (verb === 'NOTICE') {
|
|
80
|
+
this.noticeCount++;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ConnectionStats = ConnectionStats;
|
|
86
|
+
//# sourceMappingURL=ConnectionStats.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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AK,CAAC,CAAC,CAAC,EAAE;oBACZ,IAAI,CAAC,mBAAmB,EAAE,CAAA;iBAC3B;qBAAM;oBACL,IAAI,CAAC,mBAAmB,EAAE,CAAA;iBAC3B;aACF;YAED,IAAI,IAAI,KAAK,MAAM,EAAE;gBACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;aAC3B;YAED,IAAI,IAAI,KAAK,OAAO,EAAE;gBACpB,IAAI,CAAC,UAAU,EAAE,CAAA;gBACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;aAC5B;YAED,IAAI,IAAI,KAAK,MAAM,EAAE;gBACnB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE5D,4BAA4B;gBAC5B,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;oBAC5B,IAAI,CAAC,SAAS,EAAE,CAAA;oBAChB,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAA;iBAC5C;aACF;YAED,IAAI,IAAI,KAAK,QAAQ,EAAE;gBACrB,IAAI,CAAC,WAAW,EAAE,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CAKF;AA5FD,0CA4FC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Connection } from './Connection';
|
|
2
|
+
export declare class ConnectionStats {
|
|
3
|
+
readonly cxn: Connection;
|
|
4
|
+
openCount: number;
|
|
5
|
+
closeCount: number;
|
|
6
|
+
errorCount: number;
|
|
7
|
+
publishCount: number;
|
|
8
|
+
requestCount: number;
|
|
9
|
+
eventCount: number;
|
|
10
|
+
lastOpen: number;
|
|
11
|
+
lastClose: number;
|
|
12
|
+
lastError: number;
|
|
13
|
+
lastPublish: number;
|
|
14
|
+
lastRequest: number;
|
|
15
|
+
lastEvent: number;
|
|
16
|
+
lastAuth: number;
|
|
17
|
+
publishTimer: number;
|
|
18
|
+
publishSuccessCount: number;
|
|
19
|
+
publishFailureCount: number;
|
|
20
|
+
eoseCount: number;
|
|
21
|
+
eoseTimer: number;
|
|
22
|
+
noticeCount: number;
|
|
23
|
+
constructor(cxn: Connection);
|
|
24
|
+
getRequestSpeed: () => number;
|
|
25
|
+
getPublishSpeed: () => number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ConnectionEvent } from "./ConnectionEvent.mjs";
|
|
2
|
+
export class ConnectionStats {
|
|
3
|
+
constructor(cxn) {
|
|
4
|
+
this.cxn = cxn;
|
|
5
|
+
this.openCount = 0;
|
|
6
|
+
this.closeCount = 0;
|
|
7
|
+
this.errorCount = 0;
|
|
8
|
+
this.publishCount = 0;
|
|
9
|
+
this.requestCount = 0;
|
|
10
|
+
this.eventCount = 0;
|
|
11
|
+
this.lastOpen = 0;
|
|
12
|
+
this.lastClose = 0;
|
|
13
|
+
this.lastError = 0;
|
|
14
|
+
this.lastPublish = 0;
|
|
15
|
+
this.lastRequest = 0;
|
|
16
|
+
this.lastEvent = 0;
|
|
17
|
+
this.lastAuth = 0;
|
|
18
|
+
this.publishTimer = 0;
|
|
19
|
+
this.publishSuccessCount = 0;
|
|
20
|
+
this.publishFailureCount = 0;
|
|
21
|
+
this.eoseCount = 0;
|
|
22
|
+
this.eoseTimer = 0;
|
|
23
|
+
this.noticeCount = 0;
|
|
24
|
+
this.getRequestSpeed = () => this.eoseCount ? this.eoseTimer / this.eoseCount : 0;
|
|
25
|
+
this.getPublishSpeed = () => this.publishSuccessCount ? this.publishTimer / this.publishSuccessCount : 0;
|
|
26
|
+
cxn.on(ConnectionEvent.Open, (cxn) => {
|
|
27
|
+
this.openCount++;
|
|
28
|
+
this.lastOpen = Date.now();
|
|
29
|
+
});
|
|
30
|
+
cxn.on(ConnectionEvent.Close, (cxn) => {
|
|
31
|
+
this.closeCount++;
|
|
32
|
+
this.lastClose = Date.now();
|
|
33
|
+
});
|
|
34
|
+
cxn.on(ConnectionEvent.Error, (cxn) => {
|
|
35
|
+
this.errorCount++;
|
|
36
|
+
this.lastError = Date.now();
|
|
37
|
+
});
|
|
38
|
+
cxn.on(ConnectionEvent.Send, (cxn, [verb]) => {
|
|
39
|
+
if (verb === 'REQ') {
|
|
40
|
+
this.requestCount++;
|
|
41
|
+
this.lastRequest = Date.now();
|
|
42
|
+
}
|
|
43
|
+
if (verb === 'EVENT') {
|
|
44
|
+
this.publishCount++;
|
|
45
|
+
this.lastPublish = Date.now();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
cxn.on(ConnectionEvent.Receive, (cxn, [verb, ...extra]) => {
|
|
49
|
+
if (verb === 'OK') {
|
|
50
|
+
const pub = this.cxn.state.pendingPublishes.get(extra[0]);
|
|
51
|
+
if (pub) {
|
|
52
|
+
this.publishTimer += Date.now() - pub.sent;
|
|
53
|
+
}
|
|
54
|
+
if (extra[1]) {
|
|
55
|
+
this.publishSuccessCount++;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.publishFailureCount++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (verb === 'AUTH') {
|
|
62
|
+
this.lastAuth = Date.now();
|
|
63
|
+
}
|
|
64
|
+
if (verb === 'EVENT') {
|
|
65
|
+
this.eventCount++;
|
|
66
|
+
this.lastEvent = Date.now();
|
|
67
|
+
}
|
|
68
|
+
if (verb === 'EOSE') {
|
|
69
|
+
const request = this.cxn.state.pendingRequests.get(extra[0]);
|
|
70
|
+
// Only count the first eose
|
|
71
|
+
if (request && !request.eose) {
|
|
72
|
+
this.eoseCount++;
|
|
73
|
+
this.eoseTimer += Date.now() - request.sent;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (verb === 'NOTICE') {
|
|
77
|
+
this.noticeCount++;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
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IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAA;iBAC3C;gBAED,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;oBACZ,IAAI,CAAC,mBAAmB,EAAE,CAAA;iBAC3B;qBAAM;oBACL,IAAI,CAAC,mBAAmB,EAAE,CAAA;iBAC3B;aACF;YAED,IAAI,IAAI,KAAK,MAAM,EAAE;gBACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;aAC3B;YAED,IAAI,IAAI,KAAK,OAAO,EAAE;gBACpB,IAAI,CAAC,UAAU,EAAE,CAAA;gBACjB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;aAC5B;YAED,IAAI,IAAI,KAAK,MAAM,EAAE;gBACnB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE5D,4BAA4B;gBAC5B,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;oBAC5B,IAAI,CAAC,SAAS,EAAE,CAAA;oBAChB,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAA;iBAC5C;aACF;YAED,IAAI,IAAI,KAAK,QAAQ,EAAE;gBACrB,IAAI,CAAC,WAAW,EAAE,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;CAKF"}
|
package/build/src/Pool.cjs
CHANGED
|
@@ -11,26 +11,20 @@ class Pool extends lib_1.Emitter {
|
|
|
11
11
|
has(url) {
|
|
12
12
|
return this.data.has(url);
|
|
13
13
|
}
|
|
14
|
-
get(url
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
connection = new Connection_1.Connection(url);
|
|
19
|
-
this.data.set(url, connection);
|
|
20
|
-
this.emit('init', connection);
|
|
21
|
-
connection.on('open', () => this.emit('open', connection));
|
|
22
|
-
connection.on('close', () => this.emit('close', connection));
|
|
23
|
-
}
|
|
24
|
-
connection.ensureConnected({
|
|
25
|
-
shouldReconnect: connection.meta.lastClose < Date.now() - reconnectAfter,
|
|
26
|
-
});
|
|
14
|
+
get(url) {
|
|
15
|
+
const oldConnection = this.data.get(url);
|
|
16
|
+
if (oldConnection) {
|
|
17
|
+
return oldConnection;
|
|
27
18
|
}
|
|
28
|
-
|
|
19
|
+
const newConnection = new Connection_1.Connection(url);
|
|
20
|
+
this.data.set(url, newConnection);
|
|
21
|
+
this.emit('init', newConnection);
|
|
22
|
+
return newConnection;
|
|
29
23
|
}
|
|
30
24
|
remove(url) {
|
|
31
25
|
const connection = this.data.get(url);
|
|
32
26
|
if (connection) {
|
|
33
|
-
connection.
|
|
27
|
+
connection.close();
|
|
34
28
|
this.data.delete(url);
|
|
35
29
|
}
|
|
36
30
|
}
|
package/build/src/Pool.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pool.cjs","sourceRoot":"","sources":["../../src/Pool.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,iDAAuC;AAEvC,MAAa,IAAK,SAAQ,aAAO;IAE/B;QACE,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACvB,CAAC;IACD,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IACD,GAAG,CAAC,GAAW
|
|
1
|
+
{"version":3,"file":"Pool.cjs","sourceRoot":"","sources":["../../src/Pool.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,iDAAuC;AAEvC,MAAa,IAAK,SAAQ,aAAO;IAE/B;QACE,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACvB,CAAC;IACD,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IACD,GAAG,CAAC,GAAW;QACb,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAExC,IAAI,aAAa,EAAE;YACjB,OAAO,aAAa,CAAA;SACrB;QAED,MAAM,aAAa,GAAG,IAAI,uBAAU,CAAC,GAAG,CAAC,CAAA;QAEzC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAA;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;QAEhC,OAAO,aAAa,CAAA;IACtB,CAAC;IACD,MAAM,CAAC,GAAW;QAChB,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAErC,IAAI,UAAU,EAAE;YACd,UAAU,CAAC,KAAK,EAAE,CAAA;YAElB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACtB;IACH,CAAC;IACD,KAAK;QACH,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACjB;IACH,CAAC;CACF;AAtCD,oBAsCC"}
|
package/build/src/Pool.d.ts
CHANGED
|
@@ -4,10 +4,7 @@ export declare class Pool extends Emitter {
|
|
|
4
4
|
data: Map<string, Connection>;
|
|
5
5
|
constructor();
|
|
6
6
|
has(url: string): boolean;
|
|
7
|
-
get(url: string
|
|
8
|
-
autoConnect?: boolean | undefined;
|
|
9
|
-
reconnectAfter?: number | undefined;
|
|
10
|
-
}): Connection;
|
|
7
|
+
get(url: string): Connection;
|
|
11
8
|
remove(url: string): void;
|
|
12
9
|
clear(): void;
|
|
13
10
|
}
|