fca-nx 7.5.0 → 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 +21 -15
- package/src/api/socket/core/connectMqtt.js +48 -14
package/package.json
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fca-nx",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.6",
|
|
4
4
|
"description": "Facebook Messenger API for Node.js — Fast, Secure, and Feature-Rich",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"facebook",
|
|
7
|
+
"chat",
|
|
8
|
+
"api",
|
|
9
|
+
"messenger",
|
|
10
|
+
"bot",
|
|
11
|
+
"unofficial",
|
|
12
|
+
"fca",
|
|
13
|
+
"fca-nx",
|
|
14
|
+
"xalman",
|
|
15
|
+
"messenger-bot",
|
|
16
|
+
"chatbot",
|
|
17
|
+
"facebook-api",
|
|
18
|
+
"messenger-chat",
|
|
19
|
+
"mqtt",
|
|
20
|
+
"e2ee",
|
|
21
|
+
"goatbot",
|
|
22
|
+
"unofficial-api",
|
|
23
|
+
"facebook-chat"
|
|
24
|
+
],
|
|
5
25
|
"main": "index.js",
|
|
6
26
|
"types": "index.d.ts",
|
|
7
27
|
"exports": {
|
|
@@ -27,20 +47,6 @@
|
|
|
27
47
|
"type": "git",
|
|
28
48
|
"url": "git+https://github.com/xalmandevv/fca-nx.git"
|
|
29
49
|
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"facebook",
|
|
32
|
-
"chat",
|
|
33
|
-
"api",
|
|
34
|
-
"messenger",
|
|
35
|
-
"bot",
|
|
36
|
-
"unofficial",
|
|
37
|
-
"fca",
|
|
38
|
-
"fca-nx",
|
|
39
|
-
"xalman",
|
|
40
|
-
"messenger-bot",
|
|
41
|
-
"chatbot",
|
|
42
|
-
"facebook-api"
|
|
43
|
-
],
|
|
44
50
|
"author": {
|
|
45
51
|
"name": "XALMAN",
|
|
46
52
|
"url": "https://github.com/xalmandevv"
|
|
@@ -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,
|
|
@@ -38,6 +63,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
38
63
|
}
|
|
39
64
|
|
|
40
65
|
function scheduleReconnect(delayMs) {
|
|
66
|
+
if (ctx._stoppedForLogin) return;
|
|
41
67
|
const base = (ctx._mqttOpt && ctx._mqttOpt.reconnectDelayMs) || DEFAULT_RECONNECT_DELAY_MS;
|
|
42
68
|
if (ctx._reconnectTimer) {
|
|
43
69
|
logger("mqtt reconnect already scheduled", "warn");
|
|
@@ -72,8 +98,25 @@ module.exports = function createListenMqtt(deps) {
|
|
|
72
98
|
ctx._forceFreshLogin = false;
|
|
73
99
|
}
|
|
74
100
|
if (ok && !ctx._ending) {
|
|
101
|
+
ctx._stoppedForLogin = false;
|
|
75
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);
|
|
76
111
|
} else {
|
|
112
|
+
ctx._stoppedForLogin = true;
|
|
113
|
+
ctx._ending = true;
|
|
114
|
+
clearTimeout(ctx._reconnectTimer);
|
|
115
|
+
ctx._reconnectTimer = null;
|
|
116
|
+
try {
|
|
117
|
+
if (ctx.mqttClient) ctx.mqttClient.end(true);
|
|
118
|
+
} catch (_) { }
|
|
119
|
+
logger("mqtt stopped: fresh login is not available for this cookie session (no credentials). Refresh appstate and restart the bot.", "error");
|
|
77
120
|
globalCallback({ type: "stop_listen", error: "Fresh login failed after reconnect checks" }, null);
|
|
78
121
|
}
|
|
79
122
|
}, 0);
|
|
@@ -147,12 +190,12 @@ module.exports = function createListenMqtt(deps) {
|
|
|
147
190
|
// session (src/utils/headers.js) - it previously hard-coded "vi,en;q=0.9"
|
|
148
191
|
// here while HTTP requests defaulted to "en-US,en;q=0.9,vi;q=0.8",
|
|
149
192
|
// which is a contradictory-client signal between the two channels.
|
|
150
|
-
"Accept-Language": identity.acceptLanguage
|
|
151
|
-
"Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits"
|
|
193
|
+
"Accept-Language": identity.acceptLanguage
|
|
152
194
|
},
|
|
153
195
|
origin: "https://www.facebook.com",
|
|
154
196
|
protocolVersion: 13,
|
|
155
|
-
binaryType: "arraybuffer"
|
|
197
|
+
binaryType: "arraybuffer",
|
|
198
|
+
perMessageDeflate: false
|
|
156
199
|
},
|
|
157
200
|
keepalive: 60,
|
|
158
201
|
reschedulePings: true,
|
|
@@ -178,18 +221,8 @@ module.exports = function createListenMqtt(deps) {
|
|
|
178
221
|
}
|
|
179
222
|
|
|
180
223
|
if (/Invalid header flag bits|must be 0x0 for puback/i.test(msg)) {
|
|
181
|
-
// A malformed puback means the byte stream is out of step. Each one is
|
|
182
|
-
// harmless alone, but a run of them means this connection is dead and
|
|
183
|
-
// the t_ms reply will never come. After 3 in a row, drop and reconnect.
|
|
184
224
|
ctx._badPuback = (ctx._badPuback || 0) + 1;
|
|
185
|
-
logger(`mqtt puback ignored (${ctx._badPuback}
|
|
186
|
-
if (ctx._badPuback >= 3) {
|
|
187
|
-
ctx._badPuback = 0;
|
|
188
|
-
try {
|
|
189
|
-
if (mqttClient) mqttClient.end(true);
|
|
190
|
-
} catch (_) { }
|
|
191
|
-
scheduleReconnect();
|
|
192
|
-
}
|
|
225
|
+
logger(`mqtt puback ignored (${ctx._badPuback}): ${msg}`, "warn");
|
|
193
226
|
return;
|
|
194
227
|
}
|
|
195
228
|
|
|
@@ -359,6 +392,7 @@ module.exports = function createListenMqtt(deps) {
|
|
|
359
392
|
});
|
|
360
393
|
|
|
361
394
|
mqttClient.on("close", function () {
|
|
395
|
+
clearSyncTimer(ctx);
|
|
362
396
|
if (ctx._ending || ctx._cycling) {
|
|
363
397
|
logger("mqtt close expected", "info");
|
|
364
398
|
return;
|