fca-nx 7.5.5 → 7.5.6

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": "fca-nx",
3
- "version": "7.5.5",
3
+ "version": "7.5.6",
4
4
  "description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
5
5
  "keywords": [
6
6
  "facebook",
@@ -15,6 +15,31 @@ const MAX_RECONNECT_ATTEMPTS = 5; // cap consecutive network-failure reconnects;
15
15
  const MAX_RECONNECT_COOLDOWN_MS = 20 * 60 * 1000; // after exhausting fast retries, wait this long before trying again (never give up permanently)
16
16
  const T_MS_WAIT_TIMEOUT_MS = 15000;
17
17
 
18
+ // Facebook's edge PUBACK/PUBREC/PUBCOMP uses non-zero reserved flag bits.
19
+ // mqtt-packet 9 treats that as a fatal protocol error and closes the socket
20
+ // within a second of connect, before /t_ms ever arrives.
21
+ function relaxFacebookAckFlags() {
22
+ const ids = ["mqtt-packet/constants", "mqtt/node_modules/mqtt-packet/constants"];
23
+ for (const id of ids) {
24
+ try {
25
+ const constants = require(id);
26
+ if (!constants || !constants.requiredHeaderFlags) continue;
27
+ constants.requiredHeaderFlags[4] = null;
28
+ constants.requiredHeaderFlags[5] = null;
29
+ constants.requiredHeaderFlags[7] = null;
30
+ return;
31
+ } catch (_) { }
32
+ }
33
+ }
34
+ relaxFacebookAckFlags();
35
+
36
+ function clearSyncTimer(ctx) {
37
+ if (ctx._rTimeout) {
38
+ clearTimeout(ctx._rTimeout);
39
+ ctx._rTimeout = null;
40
+ }
41
+ }
42
+
18
43
  // Exponential backoff with jitter, based on how many *consecutive* reconnect
19
44
  // attempts have happened for this session (reset to 0 on a successful
20
45
  // "connect" event). This replaces the old fixed 2s-every-time behavior,
@@ -75,6 +100,14 @@ module.exports = function createListenMqtt(deps) {
75
100
  if (ok && !ctx._ending) {
76
101
  ctx._stoppedForLogin = false;
77
102
  listenMqtt(defaultFuncs, api, ctx, globalCallback);
103
+ } else if (!ctx._ending) {
104
+ ctx._stoppedForLogin = false;
105
+ ctx._reconnectAttempts = 0;
106
+ logger("mqtt fresh login unavailable for this cookie session; reconnecting with the current appstate", "warn");
107
+ ctx._reconnectTimer = setTimeout(() => {
108
+ ctx._reconnectTimer = null;
109
+ if (!ctx._ending) listenMqtt(defaultFuncs, api, ctx, globalCallback);
110
+ }, 15000);
78
111
  } else {
79
112
  ctx._stoppedForLogin = true;
80
113
  ctx._ending = true;
@@ -157,12 +190,12 @@ module.exports = function createListenMqtt(deps) {
157
190
  // session (src/utils/headers.js) - it previously hard-coded "vi,en;q=0.9"
158
191
  // here while HTTP requests defaulted to "en-US,en;q=0.9,vi;q=0.8",
159
192
  // which is a contradictory-client signal between the two channels.
160
- "Accept-Language": identity.acceptLanguage,
161
- "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits"
193
+ "Accept-Language": identity.acceptLanguage
162
194
  },
163
195
  origin: "https://www.facebook.com",
164
196
  protocolVersion: 13,
165
- binaryType: "arraybuffer"
197
+ binaryType: "arraybuffer",
198
+ perMessageDeflate: false
166
199
  },
167
200
  keepalive: 60,
168
201
  reschedulePings: true,
@@ -188,18 +221,8 @@ module.exports = function createListenMqtt(deps) {
188
221
  }
189
222
 
190
223
  if (/Invalid header flag bits|must be 0x0 for puback/i.test(msg)) {
191
- // A malformed puback means the byte stream is out of step. Each one is
192
- // harmless alone, but a run of them means this connection is dead and
193
- // the t_ms reply will never come. After 3 in a row, drop and reconnect.
194
224
  ctx._badPuback = (ctx._badPuback || 0) + 1;
195
- logger(`mqtt puback ignored (${ctx._badPuback}/3): ${msg}`, "warn");
196
- if (ctx._badPuback >= 3) {
197
- ctx._badPuback = 0;
198
- try {
199
- if (mqttClient) mqttClient.end(true);
200
- } catch (_) { }
201
- scheduleReconnect();
202
- }
225
+ logger(`mqtt puback ignored (${ctx._badPuback}): ${msg}`, "warn");
203
226
  return;
204
227
  }
205
228
 
@@ -369,6 +392,7 @@ module.exports = function createListenMqtt(deps) {
369
392
  });
370
393
 
371
394
  mqttClient.on("close", function () {
395
+ clearSyncTimer(ctx);
372
396
  if (ctx._ending || ctx._cycling) {
373
397
  logger("mqtt close expected", "info");
374
398
  return;