@eryxenx/fca 1.0.7 → 1.0.8

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": "@eryxenx/fca",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Facebook Chat API by EryXenX | Stable • Auto Re-login • Full E2EE Support — send messages, media, reactions & more in encrypted chats, hassle-free",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -22,6 +22,15 @@ const nativeMediaBridge = require("./native/nativeMediaBridge");
22
22
  const { decodeIncomingMedia } = require("./mediaDecode");
23
23
  const localMediaServer = require("./localMediaServer");
24
24
 
25
+ // Native media engine (image/video/audio send, reactions, unsend, markRead,
26
+ // group receive) is ON by default — matches pre-1.0.7 behavior. Set
27
+ // FCA_E2EE_NATIVE=0 to force it off (falls back to the legacy vendor engine)
28
+ // if the native/vendored device-kick conflict described below becomes an
29
+ // issue for your deployment.
30
+ function _nativeMediaEnabled() {
31
+ return process.env.FCA_E2EE_NATIVE !== "0";
32
+ }
33
+
25
34
  // Simple FIFO-bounded Map.set — evicts the oldest entry once maxSize is
26
35
  // exceeded, so long-lived per-message caches (media buffers, thread/sender
27
36
  // lookups) can't grow unbounded over a multi-hour/overnight process
@@ -377,11 +386,11 @@ class E2EEBridge {
377
386
  // loop (a fresh Noise handshake every few seconds). Until the two
378
387
  // engines can use distinct device ids, the native engine must stay
379
388
  // OFF for the vendored socket to stay alive. Opt back in with
380
- // FCA_E2EE_NATIVE=1 (group E2EE receive + native media sends) if you
389
+ // FCA_E2EE_NATIVE=0 (group E2EE receive + native media sends) if you
381
390
  // accept the resulting socket churn.
382
- const _nativeEnabled = process.env.FCA_E2EE_NATIVE === "1";
391
+ const _nativeEnabled = _nativeMediaEnabled();
383
392
  if (!_nativeEnabled) {
384
- logger.info("E2EE", "[native-group] native engine disabled (FCA_E2EE_NATIVE!=1) — vendored socket kept exclusive to avoid server-side device kicks");
393
+ logger.info("E2EE", "[native-group] native engine disabled (FCA_E2EE_NATIVE=0) — vendored socket kept exclusive to avoid server-side device kicks");
385
394
  }
386
395
  try {
387
396
  if (!_nativeEnabled) throw { _skipNative: true };
@@ -511,11 +520,11 @@ class E2EEBridge {
511
520
  const isGroup = this._knownE2EEGroups.has(String(threadId));
512
521
 
513
522
  if (!attachment && isGroup) {
514
- if (process.env.FCA_E2EE_NATIVE !== "1") {
523
+ if (!_nativeMediaEnabled()) {
515
524
  // Native engine disabled (default) — it shares the same E2EE
516
525
  // device id as the vendored socket and triggers server-side
517
526
  // device kicks. Group E2EE text send unavailable in this mode.
518
- throw new Error("E2EE group text send requires the native engine (FCA_E2EE_NATIVE=1), which is disabled to protect the vendored socket from server-side device kicks.");
527
+ throw new Error("E2EE group text send requires the native engine, which is disabled (FCA_E2EE_NATIVE=0) to protect the vendored socket from server-side device kicks.");
519
528
  }
520
529
  // Vendor's own group Sender-Key encryption is broken (see native-group
521
530
  // listener above) — group text sends go through native instead.
@@ -593,8 +602,8 @@ class E2EEBridge {
593
602
  const appState = this.api.getAppState();
594
603
  let result;
595
604
  try {
596
- if (process.env.FCA_E2EE_NATIVE !== "1") {
597
- throw new Error("native engine disabled (FCA_E2EE_NATIVE!=1) — see native-group note");
605
+ if (!_nativeMediaEnabled()) {
606
+ throw new Error("native engine disabled (FCA_E2EE_NATIVE=0) — see native-group note");
598
607
  }
599
608
  result = await nativeMediaBridge.sendMedia(appState, threadId, mediaType, data, mimeType, {
600
609
  caption: text || undefined,
@@ -690,7 +699,7 @@ class E2EEBridge {
690
699
 
691
700
  async markRead(threadId, watermarkTs) {
692
701
  this.ensureConnected();
693
- if (process.env.FCA_E2EE_NATIVE === "1")
702
+ if (_nativeMediaEnabled())
694
703
  return nativeMediaBridge.markRead(this.api.getAppState(), threadId, watermarkTs);
695
704
  // Native disabled: read receipts aren't available through the vendored
696
705
  // engine — treat as a no-op rather than waking the native engine.
@@ -711,8 +720,8 @@ class E2EEBridge {
711
720
  this._knownE2EEGroups = this._knownE2EEGroups || new Set();
712
721
  const isGroup = this._knownE2EEGroups.has(String(threadId));
713
722
  try {
714
- if (process.env.FCA_E2EE_NATIVE !== "1")
715
- throw new Error("native engine disabled (FCA_E2EE_NATIVE!=1)");
723
+ if (!_nativeMediaEnabled())
724
+ throw new Error("native engine disabled (FCA_E2EE_NATIVE=0)");
716
725
  return await nativeMediaBridge.sendReaction(this.api.getAppState(), threadId, messageId, senderJid, reaction, isGroup);
717
726
  } catch (err) {
718
727
  if (isGroup) {
@@ -734,8 +743,8 @@ class E2EEBridge {
734
743
  this._knownE2EEGroups = this._knownE2EEGroups || new Set();
735
744
  const isGroup = this._knownE2EEGroups.has(String(threadId));
736
745
  try {
737
- if (process.env.FCA_E2EE_NATIVE !== "1")
738
- throw new Error("native engine disabled (FCA_E2EE_NATIVE!=1)");
746
+ if (!_nativeMediaEnabled())
747
+ throw new Error("native engine disabled (FCA_E2EE_NATIVE=0)");
739
748
  return await nativeMediaBridge.unsendMessage(this.api.getAppState(), threadId, messageId, isGroup);
740
749
  } catch (err) {
741
750
  if (isGroup) {
@@ -752,8 +761,8 @@ class E2EEBridge {
752
761
  this._knownE2EEGroups = this._knownE2EEGroups || new Set();
753
762
  const isGroup = this._knownE2EEGroups.has(String(threadId));
754
763
  if (isGroup) {
755
- if (process.env.FCA_E2EE_NATIVE !== "1")
756
- throw new Error("E2EE group edit requires the native engine (FCA_E2EE_NATIVE=1), which is disabled.");
764
+ if (!_nativeMediaEnabled())
765
+ throw new Error("E2EE group edit requires the native engine, which is disabled (FCA_E2EE_NATIVE=0).");
757
766
  // Vendor's group Sender-Key encryption is broken, so route
758
767
  // group edits through native (it doesn't need a chatJid — the
759
768
  // messageId alone identifies which chat/message to edit).
@@ -947,4 +956,4 @@ function _getImageDimensions(buf, mimeType) {
947
956
  }
948
957
  } catch (_) {}
949
958
  return null;
950
- }
959
+ }