shadowx-fca 2.6.0 → 2.8.0

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": "shadowx-fca",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "Unofficial Facebook Chat API for Node.js with Auto-Update System - modify by Mueid Mursalin Rifat",
5
5
  "main": "index.js",
6
6
  "files": [
package/src/listenMqtt.js CHANGED
@@ -10,6 +10,9 @@ const debugSeq = false;
10
10
  var identity = function () { };
11
11
  var form = {};
12
12
  var getSeqID = function () { };
13
+ var seqIdRetryCount = 0;
14
+ var MAX_SEQID_RETRIES = 3;
15
+
13
16
  var topics = [
14
17
  "/legacy_web",
15
18
  "/webrtc",
@@ -105,20 +108,27 @@ function listenMqtt(defaultFuncs, api, ctx, globalCallback) {
105
108
  mqttClient.on('error', function (err) {
106
109
  log.error("listenMqtt", err);
107
110
  mqttClient.end();
108
- if (ctx.globalOptions.autoReconnect) getSeqID();
109
- else globalCallback({ type: "stop_listen", error: "Connection refused: Server unavailable" }, null);
111
+ if (ctx.globalOptions.autoReconnect) {
112
+ seqIdRetryCount = 0;
113
+ getSeqID();
114
+ } else {
115
+ globalCallback({ type: "stop_listen", error: "Connection refused: Server unavailable" }, null);
116
+ }
110
117
  });
111
118
 
112
119
  mqttClient.on('connect', function () {
113
120
  topics.forEach(topicsub => mqttClient.subscribe(topicsub));
114
121
 
122
+ // Reset retry count on successful connection
123
+ seqIdRetryCount = 0;
124
+
115
125
  // Display connection success message with branding and loading animation
116
126
  const messages = [
117
- '\n🖤 SHADOWX-FCA MQTT Connected',
127
+ '🖤 SHADOWX-FCA MQTT Connected',
118
128
  `🔰 Region: ${ctx.region || 'PNB'}`,
119
129
  `🔄 Auto-reconnect: ${ctx.globalOptions.autoReconnect ? 'Enabled' : 'Disabled'}${ctx.globalOptions.autoReconnect ? ' (reconnects every 3s on disconnect)' : ''}`,
120
130
  `🧬 MQTT Restart Interval: ${(ctx.globalOptions.restartListenMqtt && ctx.globalOptions.restartListenMqtt.enable) ? `${ctx.globalOptions.restartListenMqtt.timeRestart / 1000}s` : 'Disabled'}`,
121
- '🔖Author: Mueid Mursalin Rifat\n'
131
+ '🔖Author: Mueid Mursalin Rifat'
122
132
  ];
123
133
 
124
134
  let index = 0;
@@ -787,6 +797,9 @@ module.exports = function (defaultFuncs, api, ctx) {
787
797
  .post("https://www.facebook.com/api/graphqlbatch/", ctx.jar, form)
788
798
  .then(utils.parseAndCheckLogin(ctx, defaultFuncs))
789
799
  .then((resData) => {
800
+ // Reset retry count on success
801
+ seqIdRetryCount = 0;
802
+
790
803
  if (utils.getType(resData) != "Array") throw { error: "Not logged in", res: resData };
791
804
  if (resData && resData[resData.length - 1].error_results > 0) throw resData[0].o0.errors;
792
805
  if (resData[resData.length - 1].successful_results === 0) throw { error: "getSeqId: there was no successful_results", res: resData };
@@ -796,8 +809,37 @@ module.exports = function (defaultFuncs, api, ctx) {
796
809
  } else throw { error: "getSeqId: no sync_sequence_id found.", res: resData };
797
810
  })
798
811
  .catch((err) => {
812
+ // Check for binary response / JSON parse error
813
+ if (err.error && err.error.includes && err.error.includes("JSON.parse error")) {
814
+ seqIdRetryCount++;
815
+
816
+ if (seqIdRetryCount <= MAX_SEQID_RETRIES) {
817
+ log.warn("getSeqId", "Binary/JSON parse error (attempt " + seqIdRetryCount + "/" + MAX_SEQID_RETRIES + "). Retrying in " + (seqIdRetryCount * 3) + "s...");
818
+
819
+ setTimeout(() => {
820
+ api.getFreshDtsg().then(newDtsg => {
821
+ if (newDtsg) ctx.fb_dtsg = newDtsg;
822
+ }).catch(() => {}).finally(() => {
823
+ getSeqID();
824
+ });
825
+ }, seqIdRetryCount * 3000);
826
+ return;
827
+ }
828
+
829
+ log.warn("getSeqId", "MQTT sync failed after " + MAX_SEQID_RETRIES + " retries. Falling back to HTTP mode (bot will still work).");
830
+
831
+ // Emit ready so bot continues working
832
+ ctx.loggedIn = true;
833
+ if (ctx.globalOptions.emitReady) {
834
+ globalCallback({ type: "ready", error: null });
835
+ }
836
+ return;
837
+ }
838
+
799
839
  log.error("getSeqId", err);
800
- if (utils.getType(err) == "Object" && err.error === "Not logged in") ctx.loggedIn = false;
840
+ if (utils.getType(err) == "Object" && err.error === "Not logged in") {
841
+ ctx.loggedIn = false;
842
+ }
801
843
  return globalCallback(err);
802
844
  });
803
845
  };