@lazyneoaz/metachat 6.0.0 → 6.0.1

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 CHANGED
@@ -93854,10 +93854,11 @@ var MQTT_TOPICS = [
93854
93854
  ];
93855
93855
  var getJitter = (range) => Math.floor(Math.random() * (range * 2 + 1)) - range;
93856
93856
  var MQTT_CONFIG = {
93857
- get KEEPALIVE_INTERVAL() {
93858
- return 60 + Math.floor(Math.random() * 30);
93859
- },
93860
- CONNECT_TIMEOUT: 6e4,
93857
+ // The broker expects a ping every 30s. A longer keepalive lets the socket
93858
+ // sit past the broker's own idle window and get reaped, so match the value
93859
+ // the web client uses exactly.
93860
+ KEEPALIVE_INTERVAL: 30,
93861
+ CONNECT_TIMEOUT: 12e3,
93861
93862
  get RECONNECT_PERIOD() {
93862
93863
  return 5e3 + Math.floor(Math.random() * 2e3);
93863
93864
  },
@@ -93865,13 +93866,15 @@ var MQTT_CONFIG = {
93865
93866
  QOS_LEVEL: 1,
93866
93867
  // A dropped socket deserves a quick retry; only a refused handshake
93867
93868
  // (explicit throttle) gets the long backoff. Both ramps are jittered.
93868
- INITIAL_RETRY_DELAY: 4e3,
93869
+ INITIAL_RETRY_DELAY: 2e3,
93869
93870
  MAX_RETRY_DELAY: 3e5,
93870
93871
  RETRY_MULTIPLIER: 2,
93871
- // A refused handshake (connack returnCode != 0) means we are being
93872
- // throttled, not that the network blipped: wait much longer before trying.
93873
- THROTTLE_DELAY: 9e4,
93874
- MAX_THROTTLE_DELAY: 9e5
93872
+ // A refused handshake (connack returnCode != 0) is usually a transient
93873
+ // limiter blip: the web client simply retries its socket on the normal
93874
+ // short cadence and recovers. Start from the same delay as a drop and only
93875
+ // grow if refusals keep coming, so a one-off refusal never parks the bot.
93876
+ THROTTLE_DELAY: 2e3,
93877
+ MAX_THROTTLE_DELAY: 12e4
93875
93878
  };
93876
93879
  var SYNC_CONFIG = {
93877
93880
  API_VERSION: 11,
@@ -93880,15 +93883,15 @@ var SYNC_CONFIG = {
93880
93883
  ENCODING: "JSON"
93881
93884
  };
93882
93885
  function buildMqttUsername(ctx, sessionID) {
93883
- const profile = resolveProfile(ctx.globalOptions);
93884
93886
  return {
93885
93887
  u: ctx.userID,
93886
- s: String(sessionID),
93888
+ s: sessionID,
93887
93889
  chat_on: !!ctx.globalOptions.online,
93888
93890
  fg: false,
93889
93891
  d: ctx.clientID,
93890
93892
  ct: "websocket",
93891
- aid: ctx.mqttAppID || ctx.appID || "2220391788200892",
93893
+ aid: ctx.mqttAppID || ctx.appID || "219994525426954",
93894
+ aids: null,
93892
93895
  mqtt_sid: "",
93893
93896
  cp: 3,
93894
93897
  ecp: 10,
@@ -93898,9 +93901,8 @@ function buildMqttUsername(ctx, sessionID) {
93898
93901
  no_auto_fg: true,
93899
93902
  gas: null,
93900
93903
  pack: [],
93901
- a: profile.userAgent,
93902
- vi: "3",
93903
- lc: (profile.language || "en-US").replace("-", "_")
93904
+ p: null,
93905
+ php_override: ""
93904
93906
  };
93905
93907
  }
93906
93908
  function buildMqttOptions(ctx, host, username) {
@@ -93948,8 +93950,7 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
93948
93950
  delay: MQTT_CONFIG.INITIAL_RETRY_DELAY,
93949
93951
  throttleDelay: MQTT_CONFIG.THROTTLE_DELAY,
93950
93952
  generation: 0,
93951
- health: null,
93952
- healthSupervisor: null
93953
+ health: null
93953
93954
  };
93954
93955
  const log2 = (...args) => log(...args);
93955
93956
  function clearReconnectTimer() {
@@ -93963,13 +93964,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
93963
93964
  clearInterval(lifecycle.presenceInterval);
93964
93965
  lifecycle.presenceInterval = null;
93965
93966
  }
93966
- if (lifecycle.healthSupervisor) {
93967
- try {
93968
- lifecycle.healthSupervisor.stop();
93969
- } catch (_) {
93970
- }
93971
- lifecycle.healthSupervisor = null;
93972
- }
93973
93967
  clearReconnectTimer();
93974
93968
  }
93975
93969
  function destroyClient() {
@@ -94206,79 +94200,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
94206
94200
  ctx.mqttConnected = true;
94207
94201
  ctx.lastMqttError = null;
94208
94202
  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
94203
  ctx.__mqttHealth = () => lifecycle.health ? lifecycle.health.state(generation === lifecycle.generation && !!client2.connected) : null;
94283
94204
  api.getBotInitialData().then((botData) => {
94284
94205
  if (botData) {
package/dist/index.mjs CHANGED
@@ -93822,10 +93822,11 @@ var MQTT_TOPICS = [
93822
93822
  ];
93823
93823
  var getJitter = (range) => Math.floor(Math.random() * (range * 2 + 1)) - range;
93824
93824
  var MQTT_CONFIG = {
93825
- get KEEPALIVE_INTERVAL() {
93826
- return 60 + Math.floor(Math.random() * 30);
93827
- },
93828
- CONNECT_TIMEOUT: 6e4,
93825
+ // The broker expects a ping every 30s. A longer keepalive lets the socket
93826
+ // sit past the broker's own idle window and get reaped, so match the value
93827
+ // the web client uses exactly.
93828
+ KEEPALIVE_INTERVAL: 30,
93829
+ CONNECT_TIMEOUT: 12e3,
93829
93830
  get RECONNECT_PERIOD() {
93830
93831
  return 5e3 + Math.floor(Math.random() * 2e3);
93831
93832
  },
@@ -93833,13 +93834,15 @@ var MQTT_CONFIG = {
93833
93834
  QOS_LEVEL: 1,
93834
93835
  // A dropped socket deserves a quick retry; only a refused handshake
93835
93836
  // (explicit throttle) gets the long backoff. Both ramps are jittered.
93836
- INITIAL_RETRY_DELAY: 4e3,
93837
+ INITIAL_RETRY_DELAY: 2e3,
93837
93838
  MAX_RETRY_DELAY: 3e5,
93838
93839
  RETRY_MULTIPLIER: 2,
93839
- // A refused handshake (connack returnCode != 0) means we are being
93840
- // throttled, not that the network blipped: wait much longer before trying.
93841
- THROTTLE_DELAY: 9e4,
93842
- MAX_THROTTLE_DELAY: 9e5
93840
+ // A refused handshake (connack returnCode != 0) is usually a transient
93841
+ // limiter blip: the web client simply retries its socket on the normal
93842
+ // short cadence and recovers. Start from the same delay as a drop and only
93843
+ // grow if refusals keep coming, so a one-off refusal never parks the bot.
93844
+ THROTTLE_DELAY: 2e3,
93845
+ MAX_THROTTLE_DELAY: 12e4
93843
93846
  };
93844
93847
  var SYNC_CONFIG = {
93845
93848
  API_VERSION: 11,
@@ -93848,15 +93851,15 @@ var SYNC_CONFIG = {
93848
93851
  ENCODING: "JSON"
93849
93852
  };
93850
93853
  function buildMqttUsername(ctx, sessionID) {
93851
- const profile = resolveProfile(ctx.globalOptions);
93852
93854
  return {
93853
93855
  u: ctx.userID,
93854
- s: String(sessionID),
93856
+ s: sessionID,
93855
93857
  chat_on: !!ctx.globalOptions.online,
93856
93858
  fg: false,
93857
93859
  d: ctx.clientID,
93858
93860
  ct: "websocket",
93859
- aid: ctx.mqttAppID || ctx.appID || "2220391788200892",
93861
+ aid: ctx.mqttAppID || ctx.appID || "219994525426954",
93862
+ aids: null,
93860
93863
  mqtt_sid: "",
93861
93864
  cp: 3,
93862
93865
  ecp: 10,
@@ -93866,9 +93869,8 @@ function buildMqttUsername(ctx, sessionID) {
93866
93869
  no_auto_fg: true,
93867
93870
  gas: null,
93868
93871
  pack: [],
93869
- a: profile.userAgent,
93870
- vi: "3",
93871
- lc: (profile.language || "en-US").replace("-", "_")
93872
+ p: null,
93873
+ php_override: ""
93872
93874
  };
93873
93875
  }
93874
93876
  function buildMqttOptions(ctx, host, username) {
@@ -93916,8 +93918,7 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
93916
93918
  delay: MQTT_CONFIG.INITIAL_RETRY_DELAY,
93917
93919
  throttleDelay: MQTT_CONFIG.THROTTLE_DELAY,
93918
93920
  generation: 0,
93919
- health: null,
93920
- healthSupervisor: null
93921
+ health: null
93921
93922
  };
93922
93923
  const log2 = (...args) => log(...args);
93923
93924
  function clearReconnectTimer() {
@@ -93931,13 +93932,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
93931
93932
  clearInterval(lifecycle.presenceInterval);
93932
93933
  lifecycle.presenceInterval = null;
93933
93934
  }
93934
- if (lifecycle.healthSupervisor) {
93935
- try {
93936
- lifecycle.healthSupervisor.stop();
93937
- } catch (_) {
93938
- }
93939
- lifecycle.healthSupervisor = null;
93940
- }
93941
93935
  clearReconnectTimer();
93942
93936
  }
93943
93937
  function destroyClient() {
@@ -94174,79 +94168,6 @@ var listenMqtt_default = (defaultFuncs, api, ctx) => {
94174
94168
  ctx.mqttConnected = true;
94175
94169
  ctx.lastMqttError = null;
94176
94170
  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
94171
  ctx.__mqttHealth = () => lifecycle.health ? lifecycle.health.state(generation === lifecycle.generation && !!client2.connected) : null;
94251
94172
  api.getBotInitialData().then((botData) => {
94252
94173
  if (botData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lazyneoaz/metachat",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
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": {