api_connect_nodejs 2.0.12 → 2.0.13

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/conf/settings.ini CHANGED
@@ -10,7 +10,7 @@ BasePathReport = https://nc.nuvamawealth.com/app-report/equity/
10
10
  EquityContractURL = https://nc.nuvamawealth.com/app/toccontracts/instruments.zip
11
11
  MFContractURL = https://nc.nuvamawealth.com/app/toccontracts/mfInstruments.zip
12
12
 
13
- ApiIdKey = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOjAsImZmIjoiVyIsImJkIjoid2ViLXBjIiwibmJmIjoxNzEwNzUzMjIzLCJzcmMiOiJlbXRtdyIsImF2IjoiMi4wLjEyIiwiYXBwaWQiOiI3MTI5YzEzOGFmZjk4NjMyZWRhMjU3ZDFhNjMzZTIwNCIsImlzcyI6ImVtdCIsImV4cCI6MTcxMDc4NjYwMCwiaWF0IjoxNzEwNzUzNTIzfQ.6qtvIewJcvfeKUJmFxRtz06x0xgSFAVW7qXvcgUfulo
13
+ ApiIdKey = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHAiOjAsImZmIjoiVyIsImJkIjoid2ViLXBjIiwibmJmIjoxNzE5NTU5MTcyLCJzcmMiOiJlbXRtdyIsImF2IjoiMi4wLjEzIiwiYXBwaWQiOiIyNGI0OTUyNmUwNjRjOWQwOTU3NmUyYjk1ZDg0M2M3NSIsImlzcyI6ImVtdCIsImV4cCI6MTcxOTU5OTQwMCwiaWF0IjoxNzE5NTU5NDcyfQ.cwtG6ceohsEmbpQNiqrS8IjV4lmA0KM8RvLuy1eDX4E
14
14
  TlsVersion = 1.2
15
15
  LogLevel = All
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api_connect_nodejs",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "description": "Command to run :",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/feed/feed.js CHANGED
@@ -15,6 +15,7 @@ class Feed {
15
15
  constructor() {
16
16
  this.sock = new net.Socket();
17
17
  this.status = false;
18
+ const heartBeatTimer = 0;
18
19
  this.init();
19
20
  this.requestsList = {};
20
21
  }
@@ -29,54 +30,9 @@ class Feed {
29
30
  try {
30
31
  this.sock.connect(port, hostName, () => {
31
32
  this.clearIntervalConnect();
32
- console.log("connected to server!");
33
33
  log4js.debug("connected to server!");
34
34
  });
35
- } catch (error) {
36
- console.log("connect error is " + error);
37
- log4js.debug("connect error is " + error);
38
- this.reconnect();
39
- }
40
- };
41
-
42
- clearIntervalConnect = () => {
43
- if (false === this.status) return;
44
- clearInterval(this.status);
45
- this.status = false;
46
- };
47
-
48
- reconnect = () => {
49
- console.log("reconnecting...");
50
- log4js.debug("reconnecting...");
51
-
52
- if (this.status) return;
53
- this.status = setInterval(() => {
54
- this.sock.removeAllListeners();
55
- this.connect();
56
- }, 3000);
57
- };
58
35
 
59
- subsribe = (streamingConstants, request, callBack) => {
60
- const requestObj = {
61
- request: request,
62
- callback: callBack,
63
- };
64
- this.requestsList[streamingConstants] = requestObj;
65
- this.readWriteStreamData(requestObj);
66
- };
67
-
68
- unsubsribe = (streamingConstants, request) => {
69
- const requestObj = {
70
- request: request,
71
- callback: this.requestsList[streamingConstants].callback,
72
- };
73
- this.readWriteStreamData(requestObj);
74
- delete this.requestsList[streamingConstants];
75
- };
76
-
77
- readWriteStreamData = (requestObj) => {
78
- try {
79
- this.sock.write(JSON.stringify(requestObj.request) + "\n");
80
36
  this.sock.on("data", (data) => {
81
37
  try {
82
38
  let result = data.toString();
@@ -131,13 +87,12 @@ class Feed {
131
87
  });
132
88
 
133
89
  this.sock.on("end", (val) => {
134
- console.log("Connection ended ");
135
90
  this.reconnect();
136
91
  });
137
92
 
138
93
  this.sock.on("error", (err) => {
139
94
  log4js.debug("connection error " + err);
140
- requestObj.callback(err, null, null);
95
+ // requestObj.callback(err, null, null);
141
96
  this.reconnect();
142
97
  });
143
98
 
@@ -145,9 +100,70 @@ class Feed {
145
100
  log4js.debug("connection closed " + val);
146
101
  this.reconnect();
147
102
  });
103
+
104
+ } catch (error) {
105
+ log4js.debug("connect error is " + error);
106
+ this.reconnect();
107
+ }
108
+ };
109
+
110
+ clearIntervalConnect = () => {
111
+ if (false === this.status) return;
112
+ clearInterval(this.status);
113
+ this.status = false;
114
+ };
115
+
116
+ reconnect = () => {
117
+ log4js.debug("reconnecting...");
118
+
119
+ if (this.status) return;
120
+ this.status = setInterval(() => {
121
+ this.sock.removeAllListeners();
122
+ this.connect();
123
+ }, 3000);
124
+ };
125
+
126
+ subsribe = (streamingConstants, request, callBack, heartBeatFeed = false) => {
127
+ const requestObj = {
128
+ request: request,
129
+ callback: callBack,
130
+ };
131
+ this.requestsList[streamingConstants] = requestObj;
132
+ this.readWriteStreamData(requestObj, heartBeatFeed);
133
+ this.checkAndStartHeartBeat()
134
+ };
135
+
136
+ unsubsribe = (streamingConstants, request, heartBeatFeed = false) => {
137
+ const requestObj = {
138
+ request: request,
139
+ callback: this.requestsList[streamingConstants].callback,
140
+ };
141
+ this.readWriteStreamData(requestObj, heartBeatFeed);
142
+ delete this.requestsList[streamingConstants];
143
+ };
144
+
145
+ readWriteStreamData = (requestObj, heartBeatFeed= false) => {
146
+
147
+ try {
148
+ if(heartBeatFeed) {
149
+ this.sock.write("{}" + "\n");
150
+ } else {
151
+ this.sock.write(JSON.stringify(requestObj.request) + "\n");
152
+ }
153
+
148
154
  } catch (error) {
149
155
  console.log({ error });
150
156
  }
157
+ }
158
+
159
+ checkAndStartHeartBeat = () => {
160
+
161
+ if(this.heartBeatTimer) {
162
+ // Clearing the interval timer
163
+ clearInterval(this.heartBeatTimer);
164
+ }
165
+
166
+ this.heartBeatTimer = setInterval(this.readWriteStreamData, 90000, undefined, true);
151
167
  };
152
168
  }
153
169