@ekhein/sekiro-node-client 1.0.8 → 2.0.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/decorators/action.decorator.d.ts +1 -3
- package/dist/decorators/action.decorator.js +6 -10
- package/dist/decorators/fork.decorator.d.ts +1 -0
- package/dist/decorators/fork.decorator.js +7 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +2 -0
- package/dist/main.d.ts +3 -5
- package/dist/main.js +58 -60
- package/dist/utils/logger.util.d.ts +2 -3
- package/dist/utils/logger.util.js +28 -6
- package/dist/utils/result.util.d.ts +1 -3
- package/dist/utils/result.util.js +8 -6
- package/package.json +16 -11
- package/types/sekiro.d.ts +8 -0
- package/dist/chunk-4IXLXWNL.js +0 -29
- package/dist/chunk-JB43IB4T.js +0 -13
- package/dist/decorators/action.decorator.cjs +0 -36
- package/dist/decorators/action.decorator.d.cts +0 -3
- package/dist/decorators/bootstrap.decorator.cjs +0 -37
- package/dist/decorators/bootstrap.decorator.d.cts +0 -3
- package/dist/decorators/bootstrap.decorator.d.ts +0 -3
- package/dist/decorators/bootstrap.decorator.js +0 -12
- package/dist/main.cjs +0 -118
- package/dist/main.d.cts +0 -17
- package/dist/utils/logger.util.cjs +0 -53
- package/dist/utils/logger.util.d.cts +0 -12
- package/dist/utils/result.util.cjs +0 -37
- package/dist/utils/result.util.d.cts +0 -6
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
1
|
+
export function Action() {
|
|
2
|
+
return function (target, method, descriptor) {
|
|
3
|
+
if (!target.handlers)
|
|
4
|
+
target.handlers = new Map();
|
|
5
|
+
target.handlers.set(method, descriptor.value);
|
|
6
|
+
};
|
|
8
7
|
}
|
|
9
|
-
export {
|
|
10
|
-
Action
|
|
11
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Fork(count?: number, host?: string, prot?: number, clientId?: string): <T extends new (...args: any[]) => any>(Client: T) => void;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { WebSocket } from 'partysocket';
|
|
2
|
-
|
|
3
|
-
declare class SekiroClient extends WebSocket {
|
|
2
|
+
export declare class SekiroClient extends WebSocket {
|
|
4
3
|
readonly scope: string;
|
|
4
|
+
readonly pid: number;
|
|
5
5
|
readonly host: string;
|
|
6
6
|
readonly prot: number;
|
|
7
7
|
readonly clientId: string;
|
|
8
8
|
readonly handlers: Map<string, Function>;
|
|
9
9
|
private readonly logger;
|
|
10
|
-
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
10
|
+
constructor(scope: string, pid: number, host?: string, prot?: number, clientId?: string);
|
|
11
11
|
private onOpen;
|
|
12
12
|
private onClose;
|
|
13
13
|
private onError;
|
|
14
14
|
private onData;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
export { SekiroClient };
|
package/dist/main.js
CHANGED
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { format } from 'util';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
import { WebSocket } from 'partysocket';
|
|
4
|
+
import { WebSocket as Client } from 'ws';
|
|
5
|
+
import { Result } from './utils/result.util';
|
|
6
|
+
import { Logger } from './utils/logger.util';
|
|
7
|
+
export class SekiroClient extends WebSocket {
|
|
8
|
+
scope;
|
|
9
|
+
pid;
|
|
10
|
+
host;
|
|
11
|
+
prot;
|
|
12
|
+
clientId;
|
|
13
|
+
logger = new Logger(this);
|
|
14
|
+
constructor(scope, pid, host = "192.168.2.102", prot = 5612, clientId = randomUUID().replace(/-/g, "")) {
|
|
15
|
+
super("wss://", [], {
|
|
16
|
+
debug: false,
|
|
17
|
+
maxEnqueuedMessages: -1,
|
|
18
|
+
WebSocket: class extends Client {
|
|
19
|
+
constructor() {
|
|
20
|
+
const site = format("ws://%s:%s", host, prot);
|
|
21
|
+
const wsURL = new URL("/business-demo/register", site);
|
|
22
|
+
wsURL.searchParams.append("group", scope);
|
|
23
|
+
wsURL.searchParams.append("clientId", clientId);
|
|
24
|
+
super(wsURL);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
this.scope = scope;
|
|
29
|
+
this.pid = pid;
|
|
30
|
+
this.host = host;
|
|
31
|
+
this.prot = prot;
|
|
32
|
+
this.clientId = clientId;
|
|
33
|
+
super.addEventListener("open", this.onOpen.bind(this));
|
|
34
|
+
super.addEventListener("message", this.onData.bind(this));
|
|
35
|
+
super.addEventListener("close", this.onClose.bind(this));
|
|
36
|
+
super.addEventListener("error", this.onError.bind(this));
|
|
37
|
+
}
|
|
38
|
+
async onOpen(event) {
|
|
39
|
+
this.logger.info("Connection established");
|
|
40
|
+
}
|
|
41
|
+
async onClose(event) {
|
|
42
|
+
this.logger.warn("Connection closed");
|
|
43
|
+
}
|
|
44
|
+
async onError(event) {
|
|
45
|
+
this.logger.warn("WebSocket error:", event.message);
|
|
46
|
+
}
|
|
47
|
+
async onData(event) {
|
|
48
|
+
this.logger.info("Received request", event.data);
|
|
49
|
+
const request = JSON.parse(event.data);
|
|
50
|
+
try {
|
|
51
|
+
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
52
|
+
const pack = Result.success(request, data);
|
|
53
|
+
this.send(pack);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
const pack = Result.unknown(request, error.message);
|
|
57
|
+
this.send(pack);
|
|
25
58
|
}
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
this.scope = scope;
|
|
29
|
-
this.host = host;
|
|
30
|
-
this.prot = prot;
|
|
31
|
-
this.clientId = clientId;
|
|
32
|
-
super.addEventListener("open", this.onOpen.bind(this));
|
|
33
|
-
super.addEventListener("message", this.onData.bind(this));
|
|
34
|
-
super.addEventListener("close", this.onClose.bind(this));
|
|
35
|
-
super.addEventListener("error", this.onError.bind(this));
|
|
36
|
-
}
|
|
37
|
-
logger = new Logger(this);
|
|
38
|
-
async onOpen(event) {
|
|
39
|
-
this.logger.info("Connection established");
|
|
40
|
-
}
|
|
41
|
-
async onClose(event) {
|
|
42
|
-
this.logger.warn("Connection closed");
|
|
43
|
-
}
|
|
44
|
-
async onError(event) {
|
|
45
|
-
this.logger.warn("WebSocket error:", event.message);
|
|
46
|
-
}
|
|
47
|
-
async onData(event) {
|
|
48
|
-
this.logger.info("Received request", event.data);
|
|
49
|
-
const request = JSON.parse(event.data);
|
|
50
|
-
try {
|
|
51
|
-
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
52
|
-
const pack = Result.success(request, data);
|
|
53
|
-
this.send(pack);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
const pack = Result.unknown(request, error.message);
|
|
56
|
-
this.send(pack);
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
export {
|
|
61
|
-
SekiroClient
|
|
62
|
-
};
|
|
60
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
declare class Logger {
|
|
1
|
+
export declare class Logger {
|
|
2
2
|
private readonly context;
|
|
3
3
|
constructor(context: {
|
|
4
|
+
pid: number;
|
|
4
5
|
scope: string;
|
|
5
6
|
clientId: string;
|
|
6
7
|
});
|
|
@@ -8,5 +9,3 @@ declare class Logger {
|
|
|
8
9
|
info(...message: any[]): void;
|
|
9
10
|
warn(...message: any[]): void;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
export { Logger };
|
|
@@ -1,6 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
import { format } from "util";
|
|
2
|
+
export class Logger {
|
|
3
|
+
context;
|
|
4
|
+
constructor(context) {
|
|
5
|
+
this.context = context;
|
|
6
|
+
}
|
|
7
|
+
log(level, message) {
|
|
8
|
+
const time = new Date().toLocaleString();
|
|
9
|
+
const pid = String(this.context.pid).padStart(2, "0");
|
|
10
|
+
const scope = String(this.context.scope);
|
|
11
|
+
const clientId = String(this.context.clientId);
|
|
12
|
+
const base = format("[%s] [%s] [%s] [%s] [%s]", level, time, scope, pid, clientId);
|
|
13
|
+
switch (level) {
|
|
14
|
+
case "INFO":
|
|
15
|
+
console.info(base, ...message);
|
|
16
|
+
break;
|
|
17
|
+
case "WARN":
|
|
18
|
+
console.warn(base, ...message);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
info(...message) {
|
|
23
|
+
this.log("INFO", message);
|
|
24
|
+
}
|
|
25
|
+
warn(...message) {
|
|
26
|
+
this.log("WARN", message);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
export class Result {
|
|
2
|
+
static success({ __sekiro_seq__ }, data) {
|
|
3
|
+
return (JSON.stringify({ __sekiro_seq__, data, status: 0 }));
|
|
4
|
+
}
|
|
5
|
+
static unknown({ __sekiro_seq__ }, message) {
|
|
6
|
+
return (JSON.stringify({ __sekiro_seq__, message, status: -1 }));
|
|
7
|
+
}
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekhein/sekiro-node-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"types": "./dist/main.d.ts",
|
|
6
|
+
"author": "ekhein",
|
|
7
|
+
"main": "./dist/main.js",
|
|
9
8
|
"files": [
|
|
10
|
-
"dist
|
|
9
|
+
"dist",
|
|
10
|
+
"types"
|
|
11
11
|
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./decorators": {
|
|
18
|
+
"import": "./dist/decorators/index.js",
|
|
19
|
+
"types": "./dist/decorators/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
12
22
|
"scripts": {
|
|
13
|
-
"build": "
|
|
14
|
-
"watch": "pnpm build --watch src",
|
|
15
|
-
"dev": "tsx example/index.ts"
|
|
23
|
+
"build": "tsc"
|
|
16
24
|
},
|
|
17
|
-
"author": "ekhein",
|
|
18
|
-
"description": "",
|
|
19
25
|
"engines": {
|
|
20
26
|
"node": ">=18.0.0"
|
|
21
27
|
},
|
|
@@ -25,7 +31,6 @@
|
|
|
25
31
|
},
|
|
26
32
|
"devDependencies": {
|
|
27
33
|
"@types/node": "^22.15.18",
|
|
28
|
-
"tsup": "^8.5.0",
|
|
29
34
|
"tsx": "^4.19.4",
|
|
30
35
|
"typescript": "^5.8.3"
|
|
31
36
|
}
|
package/dist/chunk-4IXLXWNL.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// src/utils/logger.util.ts
|
|
2
|
-
import { format } from "util";
|
|
3
|
-
var Logger = class {
|
|
4
|
-
constructor(context) {
|
|
5
|
-
this.context = context;
|
|
6
|
-
}
|
|
7
|
-
log(level, message) {
|
|
8
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
9
|
-
const base = format("[%s] [%s] [%s] [%s]", level, time, this.context.scope, this.context.clientId);
|
|
10
|
-
switch (level) {
|
|
11
|
-
case "INFO":
|
|
12
|
-
console.info(base, ...message);
|
|
13
|
-
break;
|
|
14
|
-
case "WARN":
|
|
15
|
-
console.warn(base, ...message);
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
info(...message) {
|
|
20
|
-
this.log("INFO", message);
|
|
21
|
-
}
|
|
22
|
-
warn(...message) {
|
|
23
|
-
this.log("WARN", message);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
Logger
|
|
29
|
-
};
|
package/dist/chunk-JB43IB4T.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/utils/result.util.ts
|
|
2
|
-
var Result = class {
|
|
3
|
-
static success({ __sekiro_seq__ }, data) {
|
|
4
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
5
|
-
}
|
|
6
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
7
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
Result
|
|
13
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/decorators/action.decorator.ts
|
|
21
|
-
var action_decorator_exports = {};
|
|
22
|
-
__export(action_decorator_exports, {
|
|
23
|
-
Action: () => Action
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(action_decorator_exports);
|
|
26
|
-
function Action() {
|
|
27
|
-
return function(target, method, descriptor) {
|
|
28
|
-
if (!target.handlers)
|
|
29
|
-
target.handlers = /* @__PURE__ */ new Map();
|
|
30
|
-
target.handlers.set(method, descriptor.value);
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
-
0 && (module.exports = {
|
|
35
|
-
Action
|
|
36
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/decorators/bootstrap.decorator.ts
|
|
21
|
-
var bootstrap_decorator_exports = {};
|
|
22
|
-
__export(bootstrap_decorator_exports, {
|
|
23
|
-
Fork: () => Fork
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(bootstrap_decorator_exports);
|
|
26
|
-
function Fork(count = 1, host, prot, clientId) {
|
|
27
|
-
return function(Client) {
|
|
28
|
-
for (let i = 1; i <= count; i++) {
|
|
29
|
-
const group = Array(Client.name, i).join("::");
|
|
30
|
-
new Client(group, host, prot, clientId);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {
|
|
36
|
-
Fork
|
|
37
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/decorators/bootstrap.decorator.ts
|
|
2
|
-
function Fork(count = 1, host, prot, clientId) {
|
|
3
|
-
return function(Client) {
|
|
4
|
-
for (let i = 1; i <= count; i++) {
|
|
5
|
-
const group = Array(Client.name, i).join("::");
|
|
6
|
-
new Client(group, host, prot, clientId);
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
Fork
|
|
12
|
-
};
|
package/dist/main.cjs
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/main.ts
|
|
21
|
-
var main_exports = {};
|
|
22
|
-
__export(main_exports, {
|
|
23
|
-
SekiroClient: () => SekiroClient
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(main_exports);
|
|
26
|
-
var import_util2 = require("util");
|
|
27
|
-
var import_crypto = require("crypto");
|
|
28
|
-
var import_partysocket = require("partysocket");
|
|
29
|
-
var import_ws = require("ws");
|
|
30
|
-
|
|
31
|
-
// src/utils/result.util.ts
|
|
32
|
-
var Result = class {
|
|
33
|
-
static success({ __sekiro_seq__ }, data) {
|
|
34
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
35
|
-
}
|
|
36
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
37
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/utils/logger.util.ts
|
|
42
|
-
var import_util = require("util");
|
|
43
|
-
var Logger = class {
|
|
44
|
-
constructor(context) {
|
|
45
|
-
this.context = context;
|
|
46
|
-
}
|
|
47
|
-
log(level, message) {
|
|
48
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
49
|
-
const base = (0, import_util.format)("[%s] [%s] [%s] [%s]", level, time, this.context.scope, this.context.clientId);
|
|
50
|
-
switch (level) {
|
|
51
|
-
case "INFO":
|
|
52
|
-
console.info(base, ...message);
|
|
53
|
-
break;
|
|
54
|
-
case "WARN":
|
|
55
|
-
console.warn(base, ...message);
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
info(...message) {
|
|
60
|
-
this.log("INFO", message);
|
|
61
|
-
}
|
|
62
|
-
warn(...message) {
|
|
63
|
-
this.log("WARN", message);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/main.ts
|
|
68
|
-
var SekiroClient = class extends import_partysocket.WebSocket {
|
|
69
|
-
constructor(scope, host = "192.168.2.102", prot = 5612, clientId = (0, import_crypto.randomUUID)().replace(/-/g, "")) {
|
|
70
|
-
super("wss://", [], {
|
|
71
|
-
debug: false,
|
|
72
|
-
maxEnqueuedMessages: -1,
|
|
73
|
-
WebSocket: class extends import_ws.WebSocket {
|
|
74
|
-
constructor() {
|
|
75
|
-
const site = (0, import_util2.format)("ws://%s:%s", host, prot);
|
|
76
|
-
const wsURL = new URL("/business-demo/register", site);
|
|
77
|
-
wsURL.searchParams.append("group", scope);
|
|
78
|
-
wsURL.searchParams.append("clientId", clientId);
|
|
79
|
-
super(wsURL);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
this.scope = scope;
|
|
84
|
-
this.host = host;
|
|
85
|
-
this.prot = prot;
|
|
86
|
-
this.clientId = clientId;
|
|
87
|
-
super.addEventListener("open", this.onOpen.bind(this));
|
|
88
|
-
super.addEventListener("message", this.onData.bind(this));
|
|
89
|
-
super.addEventListener("close", this.onClose.bind(this));
|
|
90
|
-
super.addEventListener("error", this.onError.bind(this));
|
|
91
|
-
}
|
|
92
|
-
logger = new Logger(this);
|
|
93
|
-
async onOpen(event) {
|
|
94
|
-
this.logger.info("Connection established");
|
|
95
|
-
}
|
|
96
|
-
async onClose(event) {
|
|
97
|
-
this.logger.warn("Connection closed");
|
|
98
|
-
}
|
|
99
|
-
async onError(event) {
|
|
100
|
-
this.logger.warn("WebSocket error:", event.message);
|
|
101
|
-
}
|
|
102
|
-
async onData(event) {
|
|
103
|
-
this.logger.info("Received request", event.data);
|
|
104
|
-
const request = JSON.parse(event.data);
|
|
105
|
-
try {
|
|
106
|
-
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
107
|
-
const pack = Result.success(request, data);
|
|
108
|
-
this.send(pack);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
const pack = Result.unknown(request, error.message);
|
|
111
|
-
this.send(pack);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 && (module.exports = {
|
|
117
|
-
SekiroClient
|
|
118
|
-
});
|
package/dist/main.d.cts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'partysocket';
|
|
2
|
-
|
|
3
|
-
declare class SekiroClient extends WebSocket {
|
|
4
|
-
readonly scope: string;
|
|
5
|
-
readonly host: string;
|
|
6
|
-
readonly prot: number;
|
|
7
|
-
readonly clientId: string;
|
|
8
|
-
readonly handlers: Map<string, Function>;
|
|
9
|
-
private readonly logger;
|
|
10
|
-
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
11
|
-
private onOpen;
|
|
12
|
-
private onClose;
|
|
13
|
-
private onError;
|
|
14
|
-
private onData;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { SekiroClient };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/logger.util.ts
|
|
21
|
-
var logger_util_exports = {};
|
|
22
|
-
__export(logger_util_exports, {
|
|
23
|
-
Logger: () => Logger
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(logger_util_exports);
|
|
26
|
-
var import_util = require("util");
|
|
27
|
-
var Logger = class {
|
|
28
|
-
constructor(context) {
|
|
29
|
-
this.context = context;
|
|
30
|
-
}
|
|
31
|
-
log(level, message) {
|
|
32
|
-
const time = (/* @__PURE__ */ new Date()).toLocaleString();
|
|
33
|
-
const base = (0, import_util.format)("[%s] [%s] [%s] [%s]", level, time, this.context.scope, this.context.clientId);
|
|
34
|
-
switch (level) {
|
|
35
|
-
case "INFO":
|
|
36
|
-
console.info(base, ...message);
|
|
37
|
-
break;
|
|
38
|
-
case "WARN":
|
|
39
|
-
console.warn(base, ...message);
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
info(...message) {
|
|
44
|
-
this.log("INFO", message);
|
|
45
|
-
}
|
|
46
|
-
warn(...message) {
|
|
47
|
-
this.log("WARN", message);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
-
0 && (module.exports = {
|
|
52
|
-
Logger
|
|
53
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/result.util.ts
|
|
21
|
-
var result_util_exports = {};
|
|
22
|
-
__export(result_util_exports, {
|
|
23
|
-
Result: () => Result
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(result_util_exports);
|
|
26
|
-
var Result = class {
|
|
27
|
-
static success({ __sekiro_seq__ }, data) {
|
|
28
|
-
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
29
|
-
}
|
|
30
|
-
static unknown({ __sekiro_seq__ }, message) {
|
|
31
|
-
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {
|
|
36
|
-
Result
|
|
37
|
-
});
|