cmd-control-client-lib 3.0.4 → 3.0.14

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.
@@ -335,6 +335,8 @@ export declare class CMDP_CHANNELSSUMMARY_RESPONSE extends CMDP_CHANNELSSUMMARY
335
335
  pinned: string;
336
336
  /** number of muted channels */
337
337
  muted: string;
338
+ /** number of banned channels */
339
+ banned: string;
338
340
  /** number of vip channels */
339
341
  vip: string;
340
342
  };
@@ -66,9 +66,7 @@ export declare class CMDP_TRACERT_REPLY_RESPONSE extends CMDP_TRACERT_REPLY impl
66
66
  }
67
67
  export declare class CMDP_KICK implements ICOMMAND {
68
68
  action: ACTION;
69
- params: baseParamsType & chatIdType & {
70
- time?: string;
71
- };
69
+ params: baseParamsType & chatIdType;
72
70
  }
73
71
  export declare class CMDP_KICK_RESPONSE extends CMDP_KICK implements IRESPONSE {
74
72
  result: RESULT;
@@ -1,14 +1,12 @@
1
1
  export declare enum EnumProductLinks {
2
- CHAT_MOTTO = "chatmotto",
3
- CHAT_SETTINGS = "chatsettings",
2
+ CHAT_MOTTO = "chatMotto",
3
+ CHAT_SETTINGS = "chatSettings",
4
4
  HELP = "help",
5
- HELP_TOY = "helplovense",
5
+ HELP_TOY = "helpToy",
6
6
  MESSAGING = "messaging",
7
- PICTURE_TOOL = "picturepool",
7
+ PICTURE_TOOL = "picturePool",
8
8
  PROFILE = "profile",
9
- /** @deprecated*/
10
- PASSWORDRESET = "passwordReset",
11
- PASSWORD_RESET = "passwordreset",
9
+ PASSWORD_RESET = "passwordReset",
12
10
  SERVICE0900 = "service0900"
13
11
  }
14
12
  export interface IProductConfig {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cmd-control-client-lib",
3
3
  "description": "Cmd-Client-Library",
4
- "version": "3.0.4",
4
+ "version": "3.0.14",
5
5
  "directories": {
6
6
  "lib": "./dist"
7
7
  },
@@ -64,7 +64,7 @@
64
64
  "build": "webpack --config webpack.prod.js",
65
65
  "build:dev": "webpack --config webpack.dev.js",
66
66
  "watch": "webpack --config webpack.dev.js --watch",
67
- "lint": "eslint src test --ext .ts",
67
+ "lint": "eslint src --ext .ts",
68
68
  "lint:teamcity": "yarn lint --format ./node_modules/eslint-teamcity/index.js",
69
69
  "style": "prettier --write \"{src,test}/**/*.ts\"",
70
70
  "test": "jest",
@@ -0,0 +1,117 @@
1
+ import { CmdConnection, ConnectionConfig } from "../src/cmd-connection";
2
+ import { logger } from "../src/logger";
3
+
4
+ describe("WebSocket connection", () => {
5
+ it("Should open webSocket successfully", () => {
6
+ // @ts-ignore
7
+ global.WebSocket = jest.fn().mockImplementation(() => ({ send: jest.fn() }));
8
+ const connectionConfig = new ConnectionConfig();
9
+ connectionConfig.https = true;
10
+ connectionConfig.host = "hostMock";
11
+ connectionConfig.wssport = "wssPortMock";
12
+ connectionConfig.useWS = true;
13
+
14
+ const CMDConnection = new CmdConnection(connectionConfig);
15
+ CMDConnection.connect();
16
+ expect(global.WebSocket).toHaveBeenCalledWith("wss://hostMock:wssPortMock");
17
+ //Socket was successfully opened and is able from the service
18
+ expect(CMDConnection["_socket"]).not.toBeUndefined();
19
+ });
20
+
21
+ it("Should make 5 attempts if webSocket open failed", () => {
22
+ logger.log = jest.fn();
23
+ jest.useFakeTimers();
24
+ // @ts-ignore
25
+ global.WebSocket = jest.fn().mockImplementation(() => {
26
+ return { readyState: 3 };
27
+ });
28
+
29
+ const connectionConfig = new ConnectionConfig();
30
+ connectionConfig.https = true;
31
+ connectionConfig.host = "hostMock";
32
+ connectionConfig.wssport = "wssPortMock";
33
+ connectionConfig.useWS = true;
34
+ connectionConfig.jsonp = false;
35
+ connectionConfig.connectionRetryInterval = 15000;
36
+ connectionConfig.onError = jest.fn();
37
+
38
+ const CMDConnection = new CmdConnection(connectionConfig);
39
+ CMDConnection.connect();
40
+ expect(global.WebSocket).toHaveBeenCalledWith("wss://hostMock:wssPortMock");
41
+ expect(global.WebSocket).toHaveBeenCalledTimes(1);
42
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(0);
43
+
44
+ CMDConnection._socket.onerror();
45
+ CMDConnection._socket.onclose();
46
+ //First attempt
47
+ expect(setTimeout).toHaveBeenCalledTimes(1);
48
+ expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 15000);
49
+
50
+ const firstError = new CustomEvent("connection-error", { detail: { reconnectionTimeout: 15000 } });
51
+ expect(connectionConfig.onError).toHaveBeenCalledWith(firstError);
52
+ jest.runOnlyPendingTimers();
53
+ expect(logger.log).toHaveBeenCalledWith("CMDP. retry connect in 15000 ms");
54
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(1);
55
+
56
+ //Second attempt
57
+ expect(global.WebSocket).toHaveBeenCalledTimes(2);
58
+ CMDConnection._socket.onerror();
59
+ CMDConnection._socket.onclose();
60
+
61
+ const secondError = new CustomEvent("connection-error", { detail: { reconnectionTimeout: 30000 } });
62
+ expect(setTimeout).toHaveBeenCalledTimes(2);
63
+ expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 30000);
64
+ expect(connectionConfig.onError).toHaveBeenCalledWith(secondError);
65
+ expect(logger.log).toHaveBeenCalledWith("CMDP. retry connect in 30000 ms");
66
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(2);
67
+
68
+ jest.runOnlyPendingTimers();
69
+ //Third attempt
70
+ expect(global.WebSocket).toHaveBeenCalledTimes(3);
71
+ CMDConnection._socket.onerror();
72
+ CMDConnection._socket.onclose();
73
+
74
+ const thirdError = new CustomEvent("connection-error", { detail: { reconnectionTimeout: 45000 } });
75
+ expect(setTimeout).toHaveBeenCalledTimes(3);
76
+ expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 45000);
77
+ expect(connectionConfig.onError).toHaveBeenCalledWith(thirdError);
78
+ expect(logger.log).toHaveBeenCalledWith("CMDP. retry connect in 45000 ms");
79
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(3);
80
+
81
+ jest.runOnlyPendingTimers();
82
+ //Fourth attempt
83
+ expect(global.WebSocket).toHaveBeenCalledTimes(4);
84
+ CMDConnection._socket.onerror();
85
+ CMDConnection._socket.onclose();
86
+
87
+ const fourthError = new CustomEvent("connection-error", { detail: { reconnectionTimeout: 60000 } });
88
+ expect(setTimeout).toHaveBeenCalledTimes(4);
89
+ expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 60000);
90
+ expect(connectionConfig.onError).toHaveBeenCalledWith(fourthError);
91
+ expect(logger.log).toHaveBeenCalledWith("CMDP. retry connect in 60000 ms");
92
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(4);
93
+
94
+ jest.runOnlyPendingTimers();
95
+ //Final attempt
96
+ expect(global.WebSocket).toHaveBeenCalledTimes(5);
97
+ CMDConnection._socket.onerror();
98
+ CMDConnection._socket.onclose();
99
+
100
+ const fifthError = new CustomEvent("connection-error", { detail: { reconnectionTimeout: 75000 } });
101
+ expect(setTimeout).toHaveBeenCalledTimes(5);
102
+ expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 75000);
103
+ expect(connectionConfig.onError).toHaveBeenCalledWith(fifthError);
104
+ expect(CMDConnection._reConnectAttemptsCount).toEqual(5);
105
+
106
+ jest.runOnlyPendingTimers();
107
+ expect(global.WebSocket).toHaveBeenCalledTimes(6);
108
+ CMDConnection._socket.onerror();
109
+ CMDConnection._socket.onclose();
110
+
111
+ const fatalError = new CustomEvent("connection-error", { detail: { isFatal: true } });
112
+ expect(connectionConfig.onError).toHaveBeenCalledWith(fatalError);
113
+ //No more setTimeout was called
114
+ expect(setTimeout).toHaveBeenCalledTimes(5);
115
+ expect(logger.log).toHaveBeenCalledWith("CMDP. maximum reconnect attempts count reached");
116
+ });
117
+ });
@@ -1,17 +1,17 @@
1
1
  import { RESULT } from "../src/protocol/command/icommand";
2
- import { CODE } from "../src/protocol/command/resultcode";
2
+ import { ResultCode } from "../src/protocol/command/resultcode";
3
3
 
4
4
  describe("RESULT", () => {
5
5
  it("Should accept ENUM OK value as result codes", () => {
6
6
  const result: RESULT = {
7
- code: CODE.OK,
7
+ code: ResultCode.OK,
8
8
  reason: "All good",
9
9
  };
10
10
  });
11
11
 
12
12
  it("Should accept ENUM ERROR value as result codes", () => {
13
13
  const result: RESULT = {
14
- code: CODE.SESSION_ERROR,
14
+ code: ResultCode.SESSION_ERROR,
15
15
  reason: "Unknown session",
16
16
  };
17
17
  });