@lazyneoaz/metachat 6.0.0 → 6.0.2
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/dist/index.cjs +70 -107
- package/dist/index.mjs +70 -107
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -84866,6 +84866,48 @@ function parseMentions(prng) {
|
|
|
84866
84866
|
return [];
|
|
84867
84867
|
}
|
|
84868
84868
|
}
|
|
84869
|
+
function getMentionsFromDeltaMessage(m) {
|
|
84870
|
+
const body = m?.body || "";
|
|
84871
|
+
const mentions = {};
|
|
84872
|
+
const prngCandidates = [m?.data?.prng, m?.messageMetadata?.data?.prng];
|
|
84873
|
+
for (const prng of prngCandidates) {
|
|
84874
|
+
const mdata = parseMentions(prng);
|
|
84875
|
+
if (mdata.length > 0) {
|
|
84876
|
+
for (const row of mdata) {
|
|
84877
|
+
const o = parseInt(String(row?.o ?? ""), 10) || 0;
|
|
84878
|
+
const l = parseInt(String(row?.l ?? ""), 10) || 0;
|
|
84879
|
+
mentions[String(row?.i)] = body.substring(o, o + l);
|
|
84880
|
+
}
|
|
84881
|
+
return mentions;
|
|
84882
|
+
}
|
|
84883
|
+
}
|
|
84884
|
+
const collectFromRangeMap = (rangeMap) => {
|
|
84885
|
+
const mapData = rangeMap?.asMap?.data;
|
|
84886
|
+
if (!mapData || typeof mapData !== "object") return;
|
|
84887
|
+
for (const key of Object.keys(mapData)) {
|
|
84888
|
+
const d = mapData[key]?.asMap?.data;
|
|
84889
|
+
if (!d) continue;
|
|
84890
|
+
const rawId = d.id?.asLong != null ? d.id.asLong : d.id;
|
|
84891
|
+
if (rawId == null) continue;
|
|
84892
|
+
const offset = parseInt(String(d.offset?.asLong ?? d.offset ?? 0), 10) || 0;
|
|
84893
|
+
const length = parseInt(String(d.length?.asLong ?? d.length ?? 0), 10) || 0;
|
|
84894
|
+
mentions[String(rawId)] = body.substring(offset, offset + length);
|
|
84895
|
+
}
|
|
84896
|
+
};
|
|
84897
|
+
for (const root2 of [m?.data?.data, m?.messageMetadata?.data?.data]) {
|
|
84898
|
+
if (!root2 || typeof root2 !== "object") continue;
|
|
84899
|
+
collectFromRangeMap(root2.Gb);
|
|
84900
|
+
if (Object.keys(mentions).length > 0) break;
|
|
84901
|
+
for (const key of Object.keys(root2)) {
|
|
84902
|
+
const candidate = root2[key];
|
|
84903
|
+
if (candidate && candidate.asMap && candidate.asMap.data) {
|
|
84904
|
+
collectFromRangeMap(candidate);
|
|
84905
|
+
}
|
|
84906
|
+
}
|
|
84907
|
+
if (Object.keys(mentions).length > 0) break;
|
|
84908
|
+
}
|
|
84909
|
+
return mentions;
|
|
84910
|
+
}
|
|
84869
84911
|
function getAdminTextMessageType(type) {
|
|
84870
84912
|
switch (type) {
|
|
84871
84913
|
case "unpin_messages_v2":
|
|
@@ -84894,12 +84936,12 @@ function getAdminTextMessageType(type) {
|
|
|
84894
84936
|
}
|
|
84895
84937
|
function formatDeltaMessage(m) {
|
|
84896
84938
|
const md = m.delta.messageMetadata || {};
|
|
84897
|
-
const mdata = parseMentions(m.delta.data?.prng);
|
|
84898
84939
|
const body = m.delta.body || "";
|
|
84899
|
-
const mentions = {
|
|
84900
|
-
|
|
84901
|
-
|
|
84902
|
-
|
|
84940
|
+
const mentions = getMentionsFromDeltaMessage({
|
|
84941
|
+
body,
|
|
84942
|
+
data: m.delta.data,
|
|
84943
|
+
messageMetadata: md
|
|
84944
|
+
});
|
|
84903
84945
|
const messageReply = m.delta.messageReply ? {
|
|
84904
84946
|
messageID: m.delta.messageReply.messageID,
|
|
84905
84947
|
senderID: formatID(m.delta.messageReply.senderID),
|
|
@@ -84935,11 +84977,11 @@ function formatDeltaNewMessage(m) {
|
|
|
84935
84977
|
const threadID = formatID((threadKey.threadFbId || threadKey.otherUserFbId || "").toString());
|
|
84936
84978
|
const senderID = md.actorFbId ? formatID(md.actorFbId.toString()) : "";
|
|
84937
84979
|
const body = m.body || "";
|
|
84938
|
-
const
|
|
84939
|
-
|
|
84940
|
-
|
|
84941
|
-
|
|
84942
|
-
}
|
|
84980
|
+
const mentions = getMentionsFromDeltaMessage({
|
|
84981
|
+
body,
|
|
84982
|
+
data: m.data,
|
|
84983
|
+
messageMetadata: md
|
|
84984
|
+
});
|
|
84943
84985
|
const rawAttachments = Array.isArray(m.attachments) ? m.attachments : [];
|
|
84944
84986
|
const attachments = rawAttachments.map((att) => {
|
|
84945
84987
|
try {
|
|
@@ -93854,10 +93896,11 @@ var MQTT_TOPICS = [
|
|
|
93854
93896
|
];
|
|
93855
93897
|
var getJitter = (range) => Math.floor(Math.random() * (range * 2 + 1)) - range;
|
|
93856
93898
|
var MQTT_CONFIG = {
|
|
93857
|
-
|
|
93858
|
-
|
|
93859
|
-
|
|
93860
|
-
|
|
93899
|
+
// The broker expects a ping every 30s. A longer keepalive lets the socket
|
|
93900
|
+
// sit past the broker's own idle window and get reaped, so match the value
|
|
93901
|
+
// the web client uses exactly.
|
|
93902
|
+
KEEPALIVE_INTERVAL: 30,
|
|
93903
|
+
CONNECT_TIMEOUT: 12e3,
|
|
93861
93904
|
get RECONNECT_PERIOD() {
|
|
93862
93905
|
return 5e3 + Math.floor(Math.random() * 2e3);
|
|
93863
93906
|
},
|
|
@@ -93865,13 +93908,15 @@ var MQTT_CONFIG = {
|
|
|
93865
93908
|
QOS_LEVEL: 1,
|
|
93866
93909
|
// A dropped socket deserves a quick retry; only a refused handshake
|
|
93867
93910
|
// (explicit throttle) gets the long backoff. Both ramps are jittered.
|
|
93868
|
-
INITIAL_RETRY_DELAY:
|
|
93911
|
+
INITIAL_RETRY_DELAY: 2e3,
|
|
93869
93912
|
MAX_RETRY_DELAY: 3e5,
|
|
93870
93913
|
RETRY_MULTIPLIER: 2,
|
|
93871
|
-
// A refused handshake (connack returnCode != 0)
|
|
93872
|
-
//
|
|
93873
|
-
|
|
93874
|
-
|
|
93914
|
+
// A refused handshake (connack returnCode != 0) is usually a transient
|
|
93915
|
+
// limiter blip: the web client simply retries its socket on the normal
|
|
93916
|
+
// short cadence and recovers. Start from the same delay as a drop and only
|
|
93917
|
+
// grow if refusals keep coming, so a one-off refusal never parks the bot.
|
|
93918
|
+
THROTTLE_DELAY: 2e3,
|
|
93919
|
+
MAX_THROTTLE_DELAY: 12e4
|
|
93875
93920
|
};
|
|
93876
93921
|
var SYNC_CONFIG = {
|
|
93877
93922
|
API_VERSION: 11,
|
|
@@ -93880,15 +93925,15 @@ var SYNC_CONFIG = {
|
|
|
93880
93925
|
ENCODING: "JSON"
|
|
93881
93926
|
};
|
|
93882
93927
|
function buildMqttUsername(ctx, sessionID) {
|
|
93883
|
-
const profile = resolveProfile(ctx.globalOptions);
|
|
93884
93928
|
return {
|
|
93885
93929
|
u: ctx.userID,
|
|
93886
|
-
s:
|
|
93930
|
+
s: sessionID,
|
|
93887
93931
|
chat_on: !!ctx.globalOptions.online,
|
|
93888
93932
|
fg: false,
|
|
93889
93933
|
d: ctx.clientID,
|
|
93890
93934
|
ct: "websocket",
|
|
93891
|
-
aid: ctx.mqttAppID || ctx.appID || "
|
|
93935
|
+
aid: ctx.mqttAppID || ctx.appID || "219994525426954",
|
|
93936
|
+
aids: null,
|
|
93892
93937
|
mqtt_sid: "",
|
|
93893
93938
|
cp: 3,
|
|
93894
93939
|
ecp: 10,
|
|
@@ -93898,9 +93943,8 @@ function buildMqttUsername(ctx, sessionID) {
|
|
|
93898
93943
|
no_auto_fg: true,
|
|
93899
93944
|
gas: null,
|
|
93900
93945
|
pack: [],
|
|
93901
|
-
|
|
93902
|
-
|
|
93903
|
-
lc: (profile.language || "en-US").replace("-", "_")
|
|
93946
|
+
p: null,
|
|
93947
|
+
php_override: ""
|
|
93904
93948
|
};
|
|
93905
93949
|
}
|
|
93906
93950
|
function buildMqttOptions(ctx, host, username) {
|
|
@@ -93948,8 +93992,7 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
93948
93992
|
delay: MQTT_CONFIG.INITIAL_RETRY_DELAY,
|
|
93949
93993
|
throttleDelay: MQTT_CONFIG.THROTTLE_DELAY,
|
|
93950
93994
|
generation: 0,
|
|
93951
|
-
health: null
|
|
93952
|
-
healthSupervisor: null
|
|
93995
|
+
health: null
|
|
93953
93996
|
};
|
|
93954
93997
|
const log2 = (...args) => log(...args);
|
|
93955
93998
|
function clearReconnectTimer() {
|
|
@@ -93963,13 +94006,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
93963
94006
|
clearInterval(lifecycle.presenceInterval);
|
|
93964
94007
|
lifecycle.presenceInterval = null;
|
|
93965
94008
|
}
|
|
93966
|
-
if (lifecycle.healthSupervisor) {
|
|
93967
|
-
try {
|
|
93968
|
-
lifecycle.healthSupervisor.stop();
|
|
93969
|
-
} catch (_) {
|
|
93970
|
-
}
|
|
93971
|
-
lifecycle.healthSupervisor = null;
|
|
93972
|
-
}
|
|
93973
94009
|
clearReconnectTimer();
|
|
93974
94010
|
}
|
|
93975
94011
|
function destroyClient() {
|
|
@@ -94206,79 +94242,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
94206
94242
|
ctx.mqttConnected = true;
|
|
94207
94243
|
ctx.lastMqttError = null;
|
|
94208
94244
|
resetBackoff();
|
|
94209
|
-
if (lifecycle.healthSupervisor) {
|
|
94210
|
-
try {
|
|
94211
|
-
lifecycle.healthSupervisor.stop();
|
|
94212
|
-
} catch (_) {
|
|
94213
|
-
}
|
|
94214
|
-
}
|
|
94215
|
-
lifecycle.healthSupervisor = startRealtimeSupervisor({
|
|
94216
|
-
isConnected: () => generation === lifecycle.generation && client2.connected,
|
|
94217
|
-
// Share the per-connection tracker so this supervisor sees
|
|
94218
|
-
// every inbound frame the listener records.
|
|
94219
|
-
health,
|
|
94220
|
-
reconnect: (reason) => {
|
|
94221
|
-
if (generation !== lifecycle.generation) return;
|
|
94222
|
-
if (lifecycle.stopped || ctx.loggedIn === false) return;
|
|
94223
|
-
log2(`MQTT ${reason}; recycling the socket`);
|
|
94224
|
-
try {
|
|
94225
|
-
client2.end(true);
|
|
94226
|
-
} catch (_) {
|
|
94227
|
-
}
|
|
94228
|
-
const gen = generation;
|
|
94229
|
-
setTimeout(() => {
|
|
94230
|
-
if (gen !== lifecycle.generation) return;
|
|
94231
|
-
if (lifecycle.stopped || ctx.loggedIn === false) return;
|
|
94232
|
-
if (lifecycle.client && lifecycle.client.connected) return;
|
|
94233
|
-
if (lifecycle.reconnectTimer) return;
|
|
94234
|
-
scheduleReconnect("realtime socket recycled");
|
|
94235
|
-
}, 5e3).unref?.();
|
|
94236
|
-
},
|
|
94237
|
-
ping: () => {
|
|
94238
|
-
return new Promise((resolve) => {
|
|
94239
|
-
if (generation !== lifecycle.generation || !client2.connected) {
|
|
94240
|
-
resolve(false);
|
|
94241
|
-
return;
|
|
94242
|
-
}
|
|
94243
|
-
const before2 = lifecycle.health ? lifecycle.health.frames : 0;
|
|
94244
|
-
let settled = false;
|
|
94245
|
-
const done = (alive) => {
|
|
94246
|
-
if (settled) return;
|
|
94247
|
-
settled = true;
|
|
94248
|
-
resolve(alive);
|
|
94249
|
-
};
|
|
94250
|
-
const timer = setTimeout(() => {
|
|
94251
|
-
if (generation !== lifecycle.generation) return done(false);
|
|
94252
|
-
if (!client2.connected) return done(false);
|
|
94253
|
-
done(false);
|
|
94254
|
-
}, 8e3);
|
|
94255
|
-
const watcher = () => {
|
|
94256
|
-
const after2 = lifecycle.health ? lifecycle.health.frames : 0;
|
|
94257
|
-
if (after2 > before2) {
|
|
94258
|
-
clearTimeout(timer);
|
|
94259
|
-
client2.removeListener("packetreceive", watcher);
|
|
94260
|
-
done(true);
|
|
94261
|
-
}
|
|
94262
|
-
};
|
|
94263
|
-
client2.on("packetreceive", watcher);
|
|
94264
|
-
try {
|
|
94265
|
-
client2.ping();
|
|
94266
|
-
} catch {
|
|
94267
|
-
clearTimeout(timer);
|
|
94268
|
-
client2.removeListener("packetreceive", watcher);
|
|
94269
|
-
done(false);
|
|
94270
|
-
}
|
|
94271
|
-
});
|
|
94272
|
-
},
|
|
94273
|
-
onVerdict: (state) => {
|
|
94274
|
-
if (state.verdict === "dead") {
|
|
94275
|
-
warn(
|
|
94276
|
-
"MQTT health",
|
|
94277
|
-
`silent for ${Math.round(state.sinceLastFrameMs / 1e3)}s; probing`
|
|
94278
|
-
);
|
|
94279
|
-
}
|
|
94280
|
-
}
|
|
94281
|
-
});
|
|
94282
94245
|
ctx.__mqttHealth = () => lifecycle.health ? lifecycle.health.state(generation === lifecycle.generation && !!client2.connected) : null;
|
|
94283
94246
|
api.getBotInitialData().then((botData) => {
|
|
94284
94247
|
if (botData) {
|
package/dist/index.mjs
CHANGED
|
@@ -84834,6 +84834,48 @@ function parseMentions(prng) {
|
|
|
84834
84834
|
return [];
|
|
84835
84835
|
}
|
|
84836
84836
|
}
|
|
84837
|
+
function getMentionsFromDeltaMessage(m) {
|
|
84838
|
+
const body = m?.body || "";
|
|
84839
|
+
const mentions = {};
|
|
84840
|
+
const prngCandidates = [m?.data?.prng, m?.messageMetadata?.data?.prng];
|
|
84841
|
+
for (const prng of prngCandidates) {
|
|
84842
|
+
const mdata = parseMentions(prng);
|
|
84843
|
+
if (mdata.length > 0) {
|
|
84844
|
+
for (const row of mdata) {
|
|
84845
|
+
const o = parseInt(String(row?.o ?? ""), 10) || 0;
|
|
84846
|
+
const l = parseInt(String(row?.l ?? ""), 10) || 0;
|
|
84847
|
+
mentions[String(row?.i)] = body.substring(o, o + l);
|
|
84848
|
+
}
|
|
84849
|
+
return mentions;
|
|
84850
|
+
}
|
|
84851
|
+
}
|
|
84852
|
+
const collectFromRangeMap = (rangeMap) => {
|
|
84853
|
+
const mapData = rangeMap?.asMap?.data;
|
|
84854
|
+
if (!mapData || typeof mapData !== "object") return;
|
|
84855
|
+
for (const key of Object.keys(mapData)) {
|
|
84856
|
+
const d = mapData[key]?.asMap?.data;
|
|
84857
|
+
if (!d) continue;
|
|
84858
|
+
const rawId = d.id?.asLong != null ? d.id.asLong : d.id;
|
|
84859
|
+
if (rawId == null) continue;
|
|
84860
|
+
const offset = parseInt(String(d.offset?.asLong ?? d.offset ?? 0), 10) || 0;
|
|
84861
|
+
const length = parseInt(String(d.length?.asLong ?? d.length ?? 0), 10) || 0;
|
|
84862
|
+
mentions[String(rawId)] = body.substring(offset, offset + length);
|
|
84863
|
+
}
|
|
84864
|
+
};
|
|
84865
|
+
for (const root2 of [m?.data?.data, m?.messageMetadata?.data?.data]) {
|
|
84866
|
+
if (!root2 || typeof root2 !== "object") continue;
|
|
84867
|
+
collectFromRangeMap(root2.Gb);
|
|
84868
|
+
if (Object.keys(mentions).length > 0) break;
|
|
84869
|
+
for (const key of Object.keys(root2)) {
|
|
84870
|
+
const candidate = root2[key];
|
|
84871
|
+
if (candidate && candidate.asMap && candidate.asMap.data) {
|
|
84872
|
+
collectFromRangeMap(candidate);
|
|
84873
|
+
}
|
|
84874
|
+
}
|
|
84875
|
+
if (Object.keys(mentions).length > 0) break;
|
|
84876
|
+
}
|
|
84877
|
+
return mentions;
|
|
84878
|
+
}
|
|
84837
84879
|
function getAdminTextMessageType(type) {
|
|
84838
84880
|
switch (type) {
|
|
84839
84881
|
case "unpin_messages_v2":
|
|
@@ -84862,12 +84904,12 @@ function getAdminTextMessageType(type) {
|
|
|
84862
84904
|
}
|
|
84863
84905
|
function formatDeltaMessage(m) {
|
|
84864
84906
|
const md = m.delta.messageMetadata || {};
|
|
84865
|
-
const mdata = parseMentions(m.delta.data?.prng);
|
|
84866
84907
|
const body = m.delta.body || "";
|
|
84867
|
-
const mentions = {
|
|
84868
|
-
|
|
84869
|
-
|
|
84870
|
-
|
|
84908
|
+
const mentions = getMentionsFromDeltaMessage({
|
|
84909
|
+
body,
|
|
84910
|
+
data: m.delta.data,
|
|
84911
|
+
messageMetadata: md
|
|
84912
|
+
});
|
|
84871
84913
|
const messageReply = m.delta.messageReply ? {
|
|
84872
84914
|
messageID: m.delta.messageReply.messageID,
|
|
84873
84915
|
senderID: formatID(m.delta.messageReply.senderID),
|
|
@@ -84903,11 +84945,11 @@ function formatDeltaNewMessage(m) {
|
|
|
84903
84945
|
const threadID = formatID((threadKey.threadFbId || threadKey.otherUserFbId || "").toString());
|
|
84904
84946
|
const senderID = md.actorFbId ? formatID(md.actorFbId.toString()) : "";
|
|
84905
84947
|
const body = m.body || "";
|
|
84906
|
-
const
|
|
84907
|
-
|
|
84908
|
-
|
|
84909
|
-
|
|
84910
|
-
}
|
|
84948
|
+
const mentions = getMentionsFromDeltaMessage({
|
|
84949
|
+
body,
|
|
84950
|
+
data: m.data,
|
|
84951
|
+
messageMetadata: md
|
|
84952
|
+
});
|
|
84911
84953
|
const rawAttachments = Array.isArray(m.attachments) ? m.attachments : [];
|
|
84912
84954
|
const attachments = rawAttachments.map((att) => {
|
|
84913
84955
|
try {
|
|
@@ -93822,10 +93864,11 @@ var MQTT_TOPICS = [
|
|
|
93822
93864
|
];
|
|
93823
93865
|
var getJitter = (range) => Math.floor(Math.random() * (range * 2 + 1)) - range;
|
|
93824
93866
|
var MQTT_CONFIG = {
|
|
93825
|
-
|
|
93826
|
-
|
|
93827
|
-
|
|
93828
|
-
|
|
93867
|
+
// The broker expects a ping every 30s. A longer keepalive lets the socket
|
|
93868
|
+
// sit past the broker's own idle window and get reaped, so match the value
|
|
93869
|
+
// the web client uses exactly.
|
|
93870
|
+
KEEPALIVE_INTERVAL: 30,
|
|
93871
|
+
CONNECT_TIMEOUT: 12e3,
|
|
93829
93872
|
get RECONNECT_PERIOD() {
|
|
93830
93873
|
return 5e3 + Math.floor(Math.random() * 2e3);
|
|
93831
93874
|
},
|
|
@@ -93833,13 +93876,15 @@ var MQTT_CONFIG = {
|
|
|
93833
93876
|
QOS_LEVEL: 1,
|
|
93834
93877
|
// A dropped socket deserves a quick retry; only a refused handshake
|
|
93835
93878
|
// (explicit throttle) gets the long backoff. Both ramps are jittered.
|
|
93836
|
-
INITIAL_RETRY_DELAY:
|
|
93879
|
+
INITIAL_RETRY_DELAY: 2e3,
|
|
93837
93880
|
MAX_RETRY_DELAY: 3e5,
|
|
93838
93881
|
RETRY_MULTIPLIER: 2,
|
|
93839
|
-
// A refused handshake (connack returnCode != 0)
|
|
93840
|
-
//
|
|
93841
|
-
|
|
93842
|
-
|
|
93882
|
+
// A refused handshake (connack returnCode != 0) is usually a transient
|
|
93883
|
+
// limiter blip: the web client simply retries its socket on the normal
|
|
93884
|
+
// short cadence and recovers. Start from the same delay as a drop and only
|
|
93885
|
+
// grow if refusals keep coming, so a one-off refusal never parks the bot.
|
|
93886
|
+
THROTTLE_DELAY: 2e3,
|
|
93887
|
+
MAX_THROTTLE_DELAY: 12e4
|
|
93843
93888
|
};
|
|
93844
93889
|
var SYNC_CONFIG = {
|
|
93845
93890
|
API_VERSION: 11,
|
|
@@ -93848,15 +93893,15 @@ var SYNC_CONFIG = {
|
|
|
93848
93893
|
ENCODING: "JSON"
|
|
93849
93894
|
};
|
|
93850
93895
|
function buildMqttUsername(ctx, sessionID) {
|
|
93851
|
-
const profile = resolveProfile(ctx.globalOptions);
|
|
93852
93896
|
return {
|
|
93853
93897
|
u: ctx.userID,
|
|
93854
|
-
s:
|
|
93898
|
+
s: sessionID,
|
|
93855
93899
|
chat_on: !!ctx.globalOptions.online,
|
|
93856
93900
|
fg: false,
|
|
93857
93901
|
d: ctx.clientID,
|
|
93858
93902
|
ct: "websocket",
|
|
93859
|
-
aid: ctx.mqttAppID || ctx.appID || "
|
|
93903
|
+
aid: ctx.mqttAppID || ctx.appID || "219994525426954",
|
|
93904
|
+
aids: null,
|
|
93860
93905
|
mqtt_sid: "",
|
|
93861
93906
|
cp: 3,
|
|
93862
93907
|
ecp: 10,
|
|
@@ -93866,9 +93911,8 @@ function buildMqttUsername(ctx, sessionID) {
|
|
|
93866
93911
|
no_auto_fg: true,
|
|
93867
93912
|
gas: null,
|
|
93868
93913
|
pack: [],
|
|
93869
|
-
|
|
93870
|
-
|
|
93871
|
-
lc: (profile.language || "en-US").replace("-", "_")
|
|
93914
|
+
p: null,
|
|
93915
|
+
php_override: ""
|
|
93872
93916
|
};
|
|
93873
93917
|
}
|
|
93874
93918
|
function buildMqttOptions(ctx, host, username) {
|
|
@@ -93916,8 +93960,7 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
93916
93960
|
delay: MQTT_CONFIG.INITIAL_RETRY_DELAY,
|
|
93917
93961
|
throttleDelay: MQTT_CONFIG.THROTTLE_DELAY,
|
|
93918
93962
|
generation: 0,
|
|
93919
|
-
health: null
|
|
93920
|
-
healthSupervisor: null
|
|
93963
|
+
health: null
|
|
93921
93964
|
};
|
|
93922
93965
|
const log2 = (...args) => log(...args);
|
|
93923
93966
|
function clearReconnectTimer() {
|
|
@@ -93931,13 +93974,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
93931
93974
|
clearInterval(lifecycle.presenceInterval);
|
|
93932
93975
|
lifecycle.presenceInterval = null;
|
|
93933
93976
|
}
|
|
93934
|
-
if (lifecycle.healthSupervisor) {
|
|
93935
|
-
try {
|
|
93936
|
-
lifecycle.healthSupervisor.stop();
|
|
93937
|
-
} catch (_) {
|
|
93938
|
-
}
|
|
93939
|
-
lifecycle.healthSupervisor = null;
|
|
93940
|
-
}
|
|
93941
93977
|
clearReconnectTimer();
|
|
93942
93978
|
}
|
|
93943
93979
|
function destroyClient() {
|
|
@@ -94174,79 +94210,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
|
|
|
94174
94210
|
ctx.mqttConnected = true;
|
|
94175
94211
|
ctx.lastMqttError = null;
|
|
94176
94212
|
resetBackoff();
|
|
94177
|
-
if (lifecycle.healthSupervisor) {
|
|
94178
|
-
try {
|
|
94179
|
-
lifecycle.healthSupervisor.stop();
|
|
94180
|
-
} catch (_) {
|
|
94181
|
-
}
|
|
94182
|
-
}
|
|
94183
|
-
lifecycle.healthSupervisor = startRealtimeSupervisor({
|
|
94184
|
-
isConnected: () => generation === lifecycle.generation && client2.connected,
|
|
94185
|
-
// Share the per-connection tracker so this supervisor sees
|
|
94186
|
-
// every inbound frame the listener records.
|
|
94187
|
-
health,
|
|
94188
|
-
reconnect: (reason) => {
|
|
94189
|
-
if (generation !== lifecycle.generation) return;
|
|
94190
|
-
if (lifecycle.stopped || ctx.loggedIn === false) return;
|
|
94191
|
-
log2(`MQTT ${reason}; recycling the socket`);
|
|
94192
|
-
try {
|
|
94193
|
-
client2.end(true);
|
|
94194
|
-
} catch (_) {
|
|
94195
|
-
}
|
|
94196
|
-
const gen = generation;
|
|
94197
|
-
setTimeout(() => {
|
|
94198
|
-
if (gen !== lifecycle.generation) return;
|
|
94199
|
-
if (lifecycle.stopped || ctx.loggedIn === false) return;
|
|
94200
|
-
if (lifecycle.client && lifecycle.client.connected) return;
|
|
94201
|
-
if (lifecycle.reconnectTimer) return;
|
|
94202
|
-
scheduleReconnect("realtime socket recycled");
|
|
94203
|
-
}, 5e3).unref?.();
|
|
94204
|
-
},
|
|
94205
|
-
ping: () => {
|
|
94206
|
-
return new Promise((resolve) => {
|
|
94207
|
-
if (generation !== lifecycle.generation || !client2.connected) {
|
|
94208
|
-
resolve(false);
|
|
94209
|
-
return;
|
|
94210
|
-
}
|
|
94211
|
-
const before2 = lifecycle.health ? lifecycle.health.frames : 0;
|
|
94212
|
-
let settled = false;
|
|
94213
|
-
const done = (alive) => {
|
|
94214
|
-
if (settled) return;
|
|
94215
|
-
settled = true;
|
|
94216
|
-
resolve(alive);
|
|
94217
|
-
};
|
|
94218
|
-
const timer = setTimeout(() => {
|
|
94219
|
-
if (generation !== lifecycle.generation) return done(false);
|
|
94220
|
-
if (!client2.connected) return done(false);
|
|
94221
|
-
done(false);
|
|
94222
|
-
}, 8e3);
|
|
94223
|
-
const watcher = () => {
|
|
94224
|
-
const after2 = lifecycle.health ? lifecycle.health.frames : 0;
|
|
94225
|
-
if (after2 > before2) {
|
|
94226
|
-
clearTimeout(timer);
|
|
94227
|
-
client2.removeListener("packetreceive", watcher);
|
|
94228
|
-
done(true);
|
|
94229
|
-
}
|
|
94230
|
-
};
|
|
94231
|
-
client2.on("packetreceive", watcher);
|
|
94232
|
-
try {
|
|
94233
|
-
client2.ping();
|
|
94234
|
-
} catch {
|
|
94235
|
-
clearTimeout(timer);
|
|
94236
|
-
client2.removeListener("packetreceive", watcher);
|
|
94237
|
-
done(false);
|
|
94238
|
-
}
|
|
94239
|
-
});
|
|
94240
|
-
},
|
|
94241
|
-
onVerdict: (state) => {
|
|
94242
|
-
if (state.verdict === "dead") {
|
|
94243
|
-
warn(
|
|
94244
|
-
"MQTT health",
|
|
94245
|
-
`silent for ${Math.round(state.sinceLastFrameMs / 1e3)}s; probing`
|
|
94246
|
-
);
|
|
94247
|
-
}
|
|
94248
|
-
}
|
|
94249
|
-
});
|
|
94250
94213
|
ctx.__mqttHealth = () => lifecycle.health ? lifecycle.health.state(generation === lifecycle.generation && !!client2.connected) : null;
|
|
94251
94214
|
api.getBotInitialData().then((botData) => {
|
|
94252
94215
|
if (botData) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lazyneoaz/metachat",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "A modern TypeScript Facebook Chat API client for building reliable Messenger bots, with built-in anti-detection protection, automatic cookie refresh, music search, and AI theme support.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prepublishOnly": "npm run build",
|
|
58
58
|
"lint": "npm run typecheck",
|
|
59
59
|
"format": "prettier --write \"src/**/*.ts\" \"index.ts\"",
|
|
60
|
-
"test": "npm run build && node test/smoke.test.cjs && node test/smoke.test.mjs && node test/music-search.test.cjs && node test/mqtt-lifecycle.test.cjs && node test/session-reliability.test.cjs && node test/anti-detection.test.cjs && node test/account-safety.test.cjs && node test/liveness.test.cjs && node test/recovery.test.cjs && node test/cookie-acquisition.test.cjs && node test/realtime-health.test.cjs && node test/attachment-resilience.test.cjs && node test/reaction-validation.test.cjs && node test/api-surface-fixes.test.cjs && node test/threadinfo-regression.test.cjs && node test/new-modules.test.cjs",
|
|
60
|
+
"test": "npm run build && node test/smoke.test.cjs && node test/smoke.test.mjs && node test/music-search.test.cjs && node test/mqtt-lifecycle.test.cjs && node test/session-reliability.test.cjs && node test/anti-detection.test.cjs && node test/account-safety.test.cjs && node test/liveness.test.cjs && node test/recovery.test.cjs && node test/cookie-acquisition.test.cjs && node test/realtime-health.test.cjs && node test/attachment-resilience.test.cjs && node test/reaction-validation.test.cjs && node test/api-surface-fixes.test.cjs && node test/threadinfo-regression.test.cjs && node test/new-modules.test.cjs && node test/mention-parsing.test.cjs",
|
|
61
61
|
"audit": "npm audit",
|
|
62
62
|
"audit:fix": "npm audit fix"
|
|
63
63
|
},
|