@ekhein/sekiro-node-client 1.0.1 → 1.0.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/dist/SekiroClient.cjs +101 -0
- package/dist/SekiroClient.d.cts +13 -0
- package/dist/SekiroClient.d.ts +13 -0
- package/dist/SekiroClient.js +76 -0
- package/package.json +19 -3
- package/SekiroClient.js +0 -106
- package/SekiroLogger.js +0 -12
- package/SekiroResult.js +0 -15
|
@@ -0,0 +1,101 @@
|
|
|
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/SekiroClient.ts
|
|
21
|
+
var SekiroClient_exports = {};
|
|
22
|
+
__export(SekiroClient_exports, {
|
|
23
|
+
SekiroClient: () => SekiroClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(SekiroClient_exports);
|
|
26
|
+
var import_util = require("util");
|
|
27
|
+
var import_crypto = require("crypto");
|
|
28
|
+
var import_partysocket = require("partysocket");
|
|
29
|
+
var import_ws = require("ws");
|
|
30
|
+
|
|
31
|
+
// src/SekiroResult.ts
|
|
32
|
+
var SekiroResult = 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/SekiroLogger.ts
|
|
42
|
+
var SekiroLogger = class {
|
|
43
|
+
static info(...args) {
|
|
44
|
+
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
45
|
+
}
|
|
46
|
+
static warn(...args) {
|
|
47
|
+
console.warn("[W] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/SekiroClient.ts
|
|
52
|
+
var SekiroClient = class extends import_partysocket.WebSocket {
|
|
53
|
+
handlers = /* @__PURE__ */ new Map([]);
|
|
54
|
+
constructor(scope, host = "192.168.2.102", prot = 5612, clientId = (0, import_crypto.randomUUID)().replace(/-/g, "")) {
|
|
55
|
+
super("wss://", [], {
|
|
56
|
+
debug: false,
|
|
57
|
+
maxEnqueuedMessages: -1,
|
|
58
|
+
WebSocket: class extends import_ws.WebSocket {
|
|
59
|
+
constructor() {
|
|
60
|
+
const site = (0, import_util.format)("ws://%s:%s", host, prot);
|
|
61
|
+
const wsURL = new URL("/business-demo/register", site);
|
|
62
|
+
wsURL.searchParams.append("group", scope);
|
|
63
|
+
wsURL.searchParams.append("clientId", clientId);
|
|
64
|
+
super(wsURL);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
super.addEventListener("open", () => this.onOpen.bind(this));
|
|
69
|
+
super.addEventListener("message", () => this.onData.bind(this));
|
|
70
|
+
super.addEventListener("close", () => this.onClose.bind(this));
|
|
71
|
+
super.addEventListener("error", () => this.onError.bind(this));
|
|
72
|
+
}
|
|
73
|
+
async onOpen() {
|
|
74
|
+
SekiroLogger.info("Connection established");
|
|
75
|
+
}
|
|
76
|
+
async onClose() {
|
|
77
|
+
SekiroLogger.warn("Connection closed");
|
|
78
|
+
}
|
|
79
|
+
async onError(error) {
|
|
80
|
+
SekiroLogger.warn("WebSocket error:", error);
|
|
81
|
+
}
|
|
82
|
+
async onData(event) {
|
|
83
|
+
SekiroLogger.info("Received request", event.data);
|
|
84
|
+
const request = JSON.parse(event.data);
|
|
85
|
+
try {
|
|
86
|
+
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
87
|
+
const pack = SekiroResult.success(request, data);
|
|
88
|
+
this.send(pack);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const pack = SekiroResult.unknown(request, error.message);
|
|
91
|
+
this.send(pack);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async registerAction(action, handler) {
|
|
95
|
+
this.handlers.set(action, handler);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
SekiroClient
|
|
101
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebSocket } from 'partysocket';
|
|
2
|
+
|
|
3
|
+
declare class SekiroClient extends WebSocket {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
6
|
+
private onOpen;
|
|
7
|
+
private onClose;
|
|
8
|
+
private onError;
|
|
9
|
+
private onData;
|
|
10
|
+
registerAction(action: string, handler: ISekiroHandler): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { SekiroClient };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebSocket } from 'partysocket';
|
|
2
|
+
|
|
3
|
+
declare class SekiroClient extends WebSocket {
|
|
4
|
+
private readonly handlers;
|
|
5
|
+
constructor(scope: string, host?: string, prot?: number, clientId?: string);
|
|
6
|
+
private onOpen;
|
|
7
|
+
private onClose;
|
|
8
|
+
private onError;
|
|
9
|
+
private onData;
|
|
10
|
+
registerAction(action: string, handler: ISekiroHandler): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { SekiroClient };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/SekiroClient.ts
|
|
2
|
+
import { format } from "util";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
import { WebSocket } from "partysocket";
|
|
5
|
+
import { WebSocket as Client } from "ws";
|
|
6
|
+
|
|
7
|
+
// src/SekiroResult.ts
|
|
8
|
+
var SekiroResult = class {
|
|
9
|
+
static success({ __sekiro_seq__ }, data) {
|
|
10
|
+
return JSON.stringify({ __sekiro_seq__, data, status: 0 });
|
|
11
|
+
}
|
|
12
|
+
static unknown({ __sekiro_seq__ }, message) {
|
|
13
|
+
return JSON.stringify({ __sekiro_seq__, message, status: -1 });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/SekiroLogger.ts
|
|
18
|
+
var SekiroLogger = class {
|
|
19
|
+
static info(...args) {
|
|
20
|
+
console.info("[I] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
21
|
+
}
|
|
22
|
+
static warn(...args) {
|
|
23
|
+
console.warn("[W] [" + (/* @__PURE__ */ new Date()).toLocaleString() + "]", ...args);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/SekiroClient.ts
|
|
28
|
+
var SekiroClient = class extends WebSocket {
|
|
29
|
+
handlers = /* @__PURE__ */ new Map([]);
|
|
30
|
+
constructor(scope, host = "192.168.2.102", prot = 5612, clientId = randomUUID().replace(/-/g, "")) {
|
|
31
|
+
super("wss://", [], {
|
|
32
|
+
debug: false,
|
|
33
|
+
maxEnqueuedMessages: -1,
|
|
34
|
+
WebSocket: class extends Client {
|
|
35
|
+
constructor() {
|
|
36
|
+
const site = format("ws://%s:%s", host, prot);
|
|
37
|
+
const wsURL = new URL("/business-demo/register", site);
|
|
38
|
+
wsURL.searchParams.append("group", scope);
|
|
39
|
+
wsURL.searchParams.append("clientId", clientId);
|
|
40
|
+
super(wsURL);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
super.addEventListener("open", () => this.onOpen.bind(this));
|
|
45
|
+
super.addEventListener("message", () => this.onData.bind(this));
|
|
46
|
+
super.addEventListener("close", () => this.onClose.bind(this));
|
|
47
|
+
super.addEventListener("error", () => this.onError.bind(this));
|
|
48
|
+
}
|
|
49
|
+
async onOpen() {
|
|
50
|
+
SekiroLogger.info("Connection established");
|
|
51
|
+
}
|
|
52
|
+
async onClose() {
|
|
53
|
+
SekiroLogger.warn("Connection closed");
|
|
54
|
+
}
|
|
55
|
+
async onError(error) {
|
|
56
|
+
SekiroLogger.warn("WebSocket error:", error);
|
|
57
|
+
}
|
|
58
|
+
async onData(event) {
|
|
59
|
+
SekiroLogger.info("Received request", event.data);
|
|
60
|
+
const request = JSON.parse(event.data);
|
|
61
|
+
try {
|
|
62
|
+
const data = await this.handlers.get(request.action)?.apply(this, [request]);
|
|
63
|
+
const pack = SekiroResult.success(request, data);
|
|
64
|
+
this.send(pack);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const pack = SekiroResult.unknown(request, error.message);
|
|
67
|
+
this.send(pack);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async registerAction(action, handler) {
|
|
71
|
+
this.handlers.set(action, handler);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
SekiroClient
|
|
76
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ekhein/sekiro-node-client",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "SekiroClient.js",
|
|
3
|
+
"version": "1.0.2",
|
|
5
4
|
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/SekiroClient.cjs",
|
|
7
|
+
"module": "./dist/SekiroClient.js",
|
|
8
|
+
"types": "./dist/SekiroClient.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup src/SekiroClient.ts --format cjs,esm --dts --clean",
|
|
14
|
+
"watch": "pnpm build --watch src",
|
|
15
|
+
"dev": "tsx example/index.ts"
|
|
16
|
+
},
|
|
6
17
|
"author": "ekhein",
|
|
7
|
-
"license": "ISC",
|
|
8
18
|
"description": "",
|
|
9
19
|
"engines": {
|
|
10
20
|
"node": ">=18.0.0"
|
|
@@ -12,5 +22,11 @@
|
|
|
12
22
|
"dependencies": {
|
|
13
23
|
"partysocket": "^1.1.4",
|
|
14
24
|
"ws": "^8.18.2"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.15.18",
|
|
28
|
+
"tsup": "^8.5.0",
|
|
29
|
+
"tsx": "^4.19.4",
|
|
30
|
+
"typescript": "^5.8.3"
|
|
15
31
|
}
|
|
16
32
|
}
|
package/SekiroClient.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'crypto';
|
|
2
|
-
import { WebSocket } from 'partysocket';
|
|
3
|
-
import { WebSocket as Client } from 'ws';
|
|
4
|
-
import { SekiroResult } from './SekiroResult.js';
|
|
5
|
-
import { SekiroLogger } from './SekiroLogger.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Sekiro Client for Node.js
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
12
|
-
export class SekiroClient extends WebSocket {
|
|
13
|
-
|
|
14
|
-
_handlers = new Map([])
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Create a SekiroClient instance
|
|
18
|
-
* @param {string} wsURL - WebSocket server URL
|
|
19
|
-
* @param {object} [options] - Configuration options
|
|
20
|
-
* @param {number} [options.reconnectInterval=2000] - Base reconnect interval in ms
|
|
21
|
-
* @param {number} [options.maxReconnectAttempts=10] - Maximum reconnect attempts
|
|
22
|
-
* @param {object} [options.wsOptions] - Additional WebSocket options
|
|
23
|
-
*/
|
|
24
|
-
constructor(
|
|
25
|
-
scope,
|
|
26
|
-
host = "192.168.2.102",
|
|
27
|
-
prot = 5612,
|
|
28
|
-
clientId = randomUUID().replace(/-/g, ""),
|
|
29
|
-
) {
|
|
30
|
-
super("wss://", [], {
|
|
31
|
-
debug: false,
|
|
32
|
-
maxEnqueuedMessages: -1,
|
|
33
|
-
WebSocket: class extends Client {
|
|
34
|
-
constructor() {
|
|
35
|
-
const site = String("ws://").concat(host, ":", prot)
|
|
36
|
-
const wsURL = new URL("/business-demo/register", site)
|
|
37
|
-
wsURL.searchParams.append("group", scope)
|
|
38
|
-
wsURL.searchParams.append("clientId", clientId)
|
|
39
|
-
super(wsURL)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
super.addEventListener("open", this.onOpen.bind(this))
|
|
45
|
-
super.addEventListener("message", this.onData.bind(this))
|
|
46
|
-
super.addEventListener("close", this.onClose.bind(this))
|
|
47
|
-
super.addEventListener("error", this.onError.bind(this))
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Handle WebSocket open event
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
async onOpen() {
|
|
55
|
-
SekiroLogger.info("Connection established");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Handle WebSocket message event
|
|
60
|
-
* @private
|
|
61
|
-
* @param {string|Buffer} data - Received data
|
|
62
|
-
*/
|
|
63
|
-
async onData(event) {
|
|
64
|
-
SekiroLogger.info("Received request", event.data)
|
|
65
|
-
const request = JSON.parse(event.data)
|
|
66
|
-
const handler = this._handlers.get(request.action)
|
|
67
|
-
try {
|
|
68
|
-
if (!request.action) throw new Error("Request parameter {action} is required")
|
|
69
|
-
if (!handler) throw new Error("No handler registered for action: " + request.action)
|
|
70
|
-
const data = await handler(request)
|
|
71
|
-
this.send(
|
|
72
|
-
SekiroResult.success(request, data)
|
|
73
|
-
)
|
|
74
|
-
} catch (error) {
|
|
75
|
-
this.send(
|
|
76
|
-
SekiroResult.unknown(request, error.message)
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Handle WebSocket close event
|
|
83
|
-
* @private
|
|
84
|
-
*/
|
|
85
|
-
async onClose() {
|
|
86
|
-
SekiroLogger.warn("Connection closed");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Handle WebSocket error event
|
|
91
|
-
* @private
|
|
92
|
-
* @param {Error} error - Error object
|
|
93
|
-
*/
|
|
94
|
-
async onError(error) {
|
|
95
|
-
SekiroLogger.warn("WebSocket error:", error);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Register action handler
|
|
100
|
-
* @param {string} action - Action name
|
|
101
|
-
* @param {function} handler - Handler function
|
|
102
|
-
*/
|
|
103
|
-
async registerAction(action, handler) {
|
|
104
|
-
this._handlers.set(action, handler)
|
|
105
|
-
}
|
|
106
|
-
}
|
package/SekiroLogger.js
DELETED
package/SekiroResult.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export class SekiroResult {
|
|
2
|
-
|
|
3
|
-
static success({__sekiro_seq__}, data) {
|
|
4
|
-
return (
|
|
5
|
-
JSON.stringify({__sekiro_seq__, data, status: 0})
|
|
6
|
-
)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
static unknown({__sekiro_seq__}, message) {
|
|
10
|
-
return (
|
|
11
|
-
JSON.stringify({__sekiro_seq__, message, status: -1})
|
|
12
|
-
)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}
|