raza-fca-pkg 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "raza-fca-pkg",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A node.js package for automating Facebook Messenger bot, and is one of the most advanced next-generation Facebook Chat API By Kashif Raza",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/listenMqtt.js CHANGED
@@ -92,7 +92,7 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
92
92
  keepalive: 10,
93
93
  reschedulePings: true,
94
94
  connectTimeout: 10 * 1000,
95
- reconnectPeriod: 1 * 1000,
95
+ reconnectPeriod: 0,
96
96
  };
97
97
  if (typeof ctx.globalOptions.proxy != "undefined") {
98
98
  var agent = new HttpsProxyAgent(ctx.globalOptions.proxy);
@@ -114,12 +114,24 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
114
114
  }
115
115
  mqttClient.on('error', function(err) {
116
116
  utils.error("listenMqtt", err);
117
- mqttClient.end();
117
+
118
+ try { mqttClient.end(true); } catch (_) {}
119
+ ctx.mqttClient = null;
120
+
121
+ if (ctx._mqttReconnecting) return;
122
+
118
123
  if (ctx.globalOptions.autoReconnect) {
124
+ ctx._mqttReconnecting = true;
125
+ if (!ctx._mqttRetryCount) ctx._mqttRetryCount = 0;
126
+ ctx._mqttRetryCount++;
127
+
128
+ const delay = Math.min(5000 * ctx._mqttRetryCount, 60000);
129
+ utils.log("listenMqtt", "Attempting to reconnect in " + (delay / 1000) + "s... (attempt " + ctx._mqttRetryCount + ")");
130
+
119
131
  setTimeout(() => {
120
- utils.log("listenMqtt", "Attempting to reconnect...");
132
+ ctx._mqttReconnecting = false;
121
133
  listenMqtt(defaultFuncs, api, ctx, globalCallback);
122
- }, 5000);
134
+ }, delay);
123
135
  } else {
124
136
  globalCallback({ type: "stop_listen", error: "Connection refused: Server unavailable" }, null);
125
137
  }
@@ -127,6 +139,8 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
127
139
  });
128
140
 
129
141
  mqttClient.on('connect', () => {
142
+ ctx._mqttReconnecting = false;
143
+ ctx._mqttRetryCount = 0;
130
144
  topics.forEach(topicsub => mqttClient.subscribe(topicsub));
131
145
  var topic;
132
146
  var queue = {
package/.replit DELETED
@@ -1,3 +0,0 @@
1
- modules = ["nodejs-20"]
2
- [agent]
3
- expertMode = true