@ekhein/sekiro-node-client 2.1.0 → 2.1.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/dist/main.d.ts +5 -5
- package/dist/main.js +12 -11
- package/dist/utils/logger.util.d.ts +0 -1
- package/dist/utils/logger.util.js +1 -2
- package/package.json +1 -1
- package/dist/decorators/action.decorator.d.ts +0 -1
- package/dist/decorators/action.decorator.js +0 -10
- package/dist/decorators/fork.decorator.d.ts +0 -1
- package/dist/decorators/fork.decorator.js +0 -10
- package/dist/decorators/index.d.ts +0 -2
- package/dist/decorators/index.js +0 -7
package/dist/main.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { WebSocket } from 'partysocket';
|
|
2
2
|
export declare class SekiroClient extends WebSocket {
|
|
3
|
-
readonly scope: string;
|
|
4
|
-
readonly pid: number;
|
|
5
|
-
readonly host: string;
|
|
6
|
-
readonly prot: number;
|
|
7
3
|
readonly clientId: string;
|
|
4
|
+
readonly host: string;
|
|
5
|
+
readonly port: string;
|
|
6
|
+
readonly scope: string;
|
|
8
7
|
readonly handlers: Map<string, Function>;
|
|
9
8
|
private readonly logger;
|
|
10
|
-
constructor(
|
|
9
|
+
constructor(clientId?: string, host?: string, port?: string, scope?: string);
|
|
11
10
|
private onOpen;
|
|
12
11
|
private onClose;
|
|
13
12
|
private onError;
|
|
14
13
|
private onData;
|
|
14
|
+
registerAction(action: string, handler: Function): Promise<void>;
|
|
15
15
|
}
|
package/dist/main.js
CHANGED
|
@@ -7,31 +7,29 @@ const ws_1 = require("ws");
|
|
|
7
7
|
const result_util_1 = require("./utils/result.util");
|
|
8
8
|
const logger_util_1 = require("./utils/logger.util");
|
|
9
9
|
class SekiroClient extends partysocket_1.WebSocket {
|
|
10
|
-
scope;
|
|
11
|
-
pid;
|
|
12
|
-
host;
|
|
13
|
-
prot;
|
|
14
10
|
clientId;
|
|
11
|
+
host;
|
|
12
|
+
port;
|
|
13
|
+
scope;
|
|
15
14
|
logger = new logger_util_1.Logger(this);
|
|
16
|
-
constructor(
|
|
17
|
-
super("
|
|
15
|
+
constructor(clientId = (0, crypto_1.randomUUID)().replace(/-/g, ""), host = process.env.SEKIRO_HOST, port = process.env.SEKIRO_PORT, scope = process.env.SEKIRO_SCOPE) {
|
|
16
|
+
super("ws://", [], {
|
|
18
17
|
debug: false,
|
|
19
18
|
maxEnqueuedMessages: -1,
|
|
20
19
|
WebSocket: class extends ws_1.WebSocket {
|
|
21
20
|
constructor() {
|
|
22
21
|
const group = String(scope).toLowerCase();
|
|
23
|
-
const wsURL = new URL("/business-demo/register", "ws://" + host + ":" +
|
|
22
|
+
const wsURL = new URL("/business-demo/register", "ws://" + host + ":" + port);
|
|
24
23
|
wsURL.searchParams.append("group", group);
|
|
25
24
|
wsURL.searchParams.append("clientId", clientId);
|
|
26
25
|
super(wsURL);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
});
|
|
30
|
-
this.scope = scope;
|
|
31
|
-
this.pid = pid;
|
|
32
|
-
this.host = host;
|
|
33
|
-
this.prot = prot;
|
|
34
29
|
this.clientId = clientId;
|
|
30
|
+
this.host = host;
|
|
31
|
+
this.port = port;
|
|
32
|
+
this.scope = scope;
|
|
35
33
|
super.addEventListener("open", this.onOpen.bind(this));
|
|
36
34
|
super.addEventListener("message", this.onData.bind(this));
|
|
37
35
|
super.addEventListener("close", this.onClose.bind(this));
|
|
@@ -62,5 +60,8 @@ class SekiroClient extends partysocket_1.WebSocket {
|
|
|
62
60
|
this.send(pack);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
63
|
+
async registerAction(action, handler) {
|
|
64
|
+
this.handlers.set(action, handler);
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
exports.SekiroClient = SekiroClient;
|
|
@@ -9,10 +9,9 @@ class Logger {
|
|
|
9
9
|
}
|
|
10
10
|
log(level, message) {
|
|
11
11
|
const time = new Date().toLocaleString();
|
|
12
|
-
const pid = String(this.context.pid).padStart(2, "0");
|
|
13
12
|
const scope = String(this.context.scope);
|
|
14
13
|
const clientId = String(this.context.clientId);
|
|
15
|
-
const base = (0, util_1.format)("[%s] [%s] [%s] [%s] [%s]", level, time, scope,
|
|
14
|
+
const base = (0, util_1.format)("[%s] [%s] [%s] [%s] [%s]", level, time, scope, clientId);
|
|
16
15
|
switch (level) {
|
|
17
16
|
case "INFO":
|
|
18
17
|
console.info(base, ...message);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function Action(): (target: any, method: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Action = Action;
|
|
4
|
-
function Action() {
|
|
5
|
-
return function (target, method, descriptor) {
|
|
6
|
-
if (!target.handlers)
|
|
7
|
-
target.handlers = new Map();
|
|
8
|
-
target.handlers.set(method, descriptor.value);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function Fork(count?: number, host?: string, prot?: number, clientId?: string): <T extends new (...args: any[]) => any>(Client: T) => void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Fork = Fork;
|
|
4
|
-
function Fork(count = 1, host, prot, clientId) {
|
|
5
|
-
return function (Client) {
|
|
6
|
-
for (let pid = 1; pid <= count; pid++) {
|
|
7
|
-
new Client(Client.name, pid, host, prot, clientId);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
}
|
package/dist/decorators/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Action = exports.Fork = void 0;
|
|
4
|
-
var fork_decorator_1 = require("./fork.decorator");
|
|
5
|
-
Object.defineProperty(exports, "Fork", { enumerable: true, get: function () { return fork_decorator_1.Fork; } });
|
|
6
|
-
var action_decorator_1 = require("./action.decorator");
|
|
7
|
-
Object.defineProperty(exports, "Action", { enumerable: true, get: function () { return action_decorator_1.Action; } });
|