@ekhein/sekiro-node-client 2.1.14 → 2.1.15

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 CHANGED
@@ -11,6 +11,9 @@ export declare class SekiroClient extends W3CWebSocket {
11
11
  onerror: (event: ErrorEvent) => Promise<void>;
12
12
  onmessage: (event: MessageEvent) => Promise<void>;
13
13
  constructor(group?: string, wsURL?: string, clientId?: string);
14
+ private success;
15
+ private unknown;
16
+ private post;
14
17
  registerAction(action: {
15
18
  name: string;
16
19
  handler: Function;
package/dist/main.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SekiroClient = void 0;
4
4
  const uuid_1 = require("uuid");
5
- const result_util_1 = require("./utils/result.util");
6
5
  const logger_util_1 = require("./utils/logger.util");
7
6
  const ws_util_1 = require("./utils/ws.util");
8
7
  class SekiroClient extends ws_util_1.W3CWebSocket {
@@ -23,25 +22,25 @@ class SekiroClient extends ws_util_1.W3CWebSocket {
23
22
  onmessage = async (event) => {
24
23
  this.logger.info("Request", event.data);
25
24
  const request = JSON.parse(event.data);
25
+ const handler = this.handlers.get(request.action);
26
26
  try {
27
- const handler = this.handlers.get(request.action);
28
- if (!handler)
29
- throw new Error("Handler Not Found");
30
- const body = await handler.call(this, request.params);
31
- if (body?.jsonrpc) {
32
- if (body.error)
33
- throw new Error(body.error.message);
34
- const pack = result_util_1.Result.success(request, body.result);
35
- this.send(pack);
27
+ if (handler) {
28
+ const body = await handler.call(this, request.params);
29
+ if (body?.jsonrpc) {
30
+ if (body.error)
31
+ throw new Error(body.error.message);
32
+ await this.success(request, body.result);
33
+ }
34
+ else {
35
+ await this.success(request, body);
36
+ }
36
37
  }
37
38
  else {
38
- const pack = result_util_1.Result.success(request, body);
39
- this.send(pack);
39
+ throw new Error(`action ${request.action} not definition`);
40
40
  }
41
41
  }
42
42
  catch (error) {
43
- const pack = result_util_1.Result.unknown(request, error.message);
44
- this.send(pack);
43
+ await this.unknown(request, error.message);
45
44
  }
46
45
  };
47
46
  constructor(group = process.env.namespace, wsURL = process.env.SEKIRO_WS, clientId = (0, uuid_1.v5)(process.env.pm_id, uuid_1.NIL).replace(/-/g, "")) {
@@ -53,6 +52,15 @@ class SekiroClient extends ws_util_1.W3CWebSocket {
53
52
  this.wsURL = wsURL;
54
53
  this.clientId = clientId;
55
54
  }
55
+ async success(request, data) {
56
+ await this.post({ __sekiro_seq__: request.__sekiro_seq__, status: 0, data });
57
+ }
58
+ async unknown(request, message) {
59
+ await this.post({ __sekiro_seq__: request.__sekiro_seq__, status: -1, message });
60
+ }
61
+ async post(payload) {
62
+ this.send(JSON.stringify(payload));
63
+ }
56
64
  async registerAction(action) {
57
65
  this.handlers.set(action.name, action.handler);
58
66
  return this;
@@ -7,6 +7,8 @@ class W3CWebSocket extends partysocket_1.WebSocket {
7
7
  constructor(options) {
8
8
  super(options.wsURL, [], {
9
9
  debug: false,
10
+ minReconnectionDelay: 30e3,
11
+ maxReconnectionDelay: 60e3,
10
12
  maxEnqueuedMessages: -1,
11
13
  WebSocket: class extends ws_1.WebSocket {
12
14
  constructor(wsURL) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/sekiro-node-client",
3
- "version": "2.1.14",
3
+ "version": "2.1.15",
4
4
  "license": "MIT",
5
5
  "author": "ekhein",
6
6
  "main": "./dist/main.js",
@@ -1,4 +0,0 @@
1
- export declare class Result {
2
- static success({ __sekiro_seq__ }: ISekiroRequest, data: any): string;
3
- static unknown({ __sekiro_seq__ }: ISekiroRequest, message: string): string;
4
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Result = void 0;
4
- class Result {
5
- static success({ __sekiro_seq__ }, data) {
6
- return (JSON.stringify({ __sekiro_seq__, data, status: 0 }));
7
- }
8
- static unknown({ __sekiro_seq__ }, message) {
9
- return (JSON.stringify({ __sekiro_seq__, message, status: -1 }));
10
- }
11
- }
12
- exports.Result = Result;