@dongdev/fca-unofficial 2.0.7 → 2.0.10

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.
Files changed (80) hide show
  1. package/DOCS.md +1699 -1434
  2. package/README.md +250 -168
  3. package/package.json +54 -28
  4. package/src/api/action/addExternalModule.js +5 -5
  5. package/src/api/action/changeAvatar.js +11 -10
  6. package/src/api/action/changeBio.js +7 -8
  7. package/src/api/action/getCurrentUserID.js +1 -1
  8. package/src/api/action/handleFriendRequest.js +5 -5
  9. package/src/api/action/logout.js +9 -8
  10. package/src/api/action/refreshFb_dtsg.js +17 -12
  11. package/src/api/action/setPostReaction.js +10 -11
  12. package/src/api/action/unfriend.js +3 -4
  13. package/src/api/http/httpGet.js +7 -8
  14. package/src/api/http/httpPost.js +7 -8
  15. package/src/api/http/postFormData.js +6 -5
  16. package/src/api/messaging/addUserToGroup.js +0 -1
  17. package/src/api/messaging/changeAdminStatus.js +108 -89
  18. package/src/api/messaging/changeArchivedStatus.js +6 -6
  19. package/src/api/messaging/changeBlockedStatus.js +3 -4
  20. package/src/api/messaging/changeGroupImage.js +72 -117
  21. package/src/api/messaging/changeNickname.js +59 -48
  22. package/src/api/messaging/changeThreadColor.js +61 -47
  23. package/src/api/messaging/changeThreadEmoji.js +106 -0
  24. package/src/api/messaging/createNewGroup.js +5 -5
  25. package/src/api/messaging/createPoll.js +36 -63
  26. package/src/api/messaging/deleteMessage.js +4 -4
  27. package/src/api/messaging/deleteThread.js +4 -4
  28. package/src/api/messaging/forwardAttachment.js +38 -47
  29. package/src/api/messaging/getFriendsList.js +5 -6
  30. package/src/api/messaging/getMessage.js +4 -9
  31. package/src/api/messaging/handleMessageRequest.js +5 -5
  32. package/src/api/messaging/markAsDelivered.js +5 -5
  33. package/src/api/messaging/markAsRead.js +7 -7
  34. package/src/api/messaging/markAsReadAll.js +3 -4
  35. package/src/api/messaging/markAsSeen.js +7 -7
  36. package/src/api/messaging/muteThread.js +3 -4
  37. package/src/api/messaging/removeUserFromGroup.js +82 -56
  38. package/src/api/messaging/resolvePhotoUrl.js +2 -3
  39. package/src/api/messaging/searchForThread.js +2 -3
  40. package/src/api/messaging/sendMessage.js +171 -101
  41. package/src/api/messaging/sendMessageMqtt.js +14 -12
  42. package/src/api/messaging/sendTypingIndicator.js +11 -11
  43. package/src/api/messaging/setMessageReaction.js +68 -82
  44. package/src/api/messaging/setTitle.js +77 -48
  45. package/src/api/messaging/shareContact.js +2 -4
  46. package/src/api/messaging/threadColors.js +0 -3
  47. package/src/api/messaging/unsendMessage.js +74 -37
  48. package/src/api/messaging/uploadAttachment.js +11 -9
  49. package/src/api/socket/core/connectMqtt.js +180 -0
  50. package/src/api/socket/core/getSeqID.js +25 -0
  51. package/src/api/socket/core/getTaskResponseData.js +22 -0
  52. package/src/api/socket/core/markDelivery.js +12 -0
  53. package/src/api/socket/core/parseDelta.js +351 -0
  54. package/src/api/socket/detail/buildStream.js +176 -68
  55. package/src/api/socket/detail/constants.js +24 -0
  56. package/src/api/socket/listenMqtt.js +80 -1005
  57. package/src/api/{messaging → threads}/getThreadHistory.js +5 -22
  58. package/src/api/threads/getThreadInfo.js +35 -248
  59. package/src/api/threads/getThreadList.js +20 -20
  60. package/src/api/threads/getThreadPictures.js +3 -4
  61. package/src/api/users/getUserID.js +5 -6
  62. package/src/api/users/getUserInfo.js +305 -73
  63. package/src/api/users/getUserInfoV2.js +134 -0
  64. package/src/database/models/user.js +32 -0
  65. package/src/database/userData.js +89 -0
  66. package/src/utils/constants.js +12 -2
  67. package/src/utils/format.js +1051 -0
  68. package/src/utils/request.js +75 -7
  69. package/CHANGELOG.md +0 -52
  70. package/LICENSE-MIT +0 -21
  71. package/func/checkUpdate.js +0 -58
  72. package/func/logger.js +0 -112
  73. package/func/login.js +0 -0
  74. package/index.d.ts +0 -618
  75. package/module/config.js +0 -34
  76. package/module/login.js +0 -47
  77. package/module/loginHelper.js +0 -635
  78. package/module/options.js +0 -49
  79. package/src/api/threads/changeThreadEmoji.js +0 -55
  80. package/src/utils/index.js +0 -1497
@@ -1,96 +1,204 @@
1
1
  "use strict";
2
2
 
3
- const { Transform } = require("stream");
3
+ const { Writable, PassThrough } = require("stream");
4
4
  const Duplexify = require("duplexify");
5
5
 
6
- let WebSocket_Global;
7
6
  function buildProxy() {
8
- const Proxy = new Transform({
9
- objectMode: false,
10
- transform(chunk, enc, next) {
11
- if (WebSocket_Global.readyState !== WebSocket.OPEN) {
12
- return next();
13
- }
14
- const data = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, "utf8");
15
- try {
16
- WebSocket_Global.send(data);
17
- next();
18
- } catch (err) {
19
- console.error("WebSocket send error:", err);
20
- next(err);
21
- }
22
- },
23
- flush(done) {
24
- if (WebSocket_Global.readyState === WebSocket.OPEN) {
25
- WebSocket_Global.close();
26
- }
27
- done();
7
+ let target = null;
8
+ let ended = false;
9
+ const Proxy = new Writable({
10
+ autoDestroy: true,
11
+ write(chunk, enc, cb) {
12
+ if (ended || this.destroyed) return cb();
13
+ const ws = target;
14
+ if (ws && ws.readyState === 1) {
15
+ try {
16
+ ws.send(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk), cb);
17
+ } catch (e) {
18
+ cb(e);
19
+ }
20
+ } else cb();
28
21
  },
29
22
  writev(chunks, cb) {
23
+ if (ended || this.destroyed) return cb();
24
+ const ws = target;
25
+ if (!ws || ws.readyState !== 1) return cb();
30
26
  try {
31
27
  for (const { chunk } of chunks) {
32
- this.push(
33
- Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, "utf8")
34
- );
28
+ ws.send(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
35
29
  }
36
30
  cb();
37
- } catch (err) {
38
- console.error("Writev error:", err);
39
- cb(err);
31
+ } catch (e) {
32
+ cb(e);
40
33
  }
34
+ },
35
+ final(cb) {
36
+ ended = true;
37
+ const ws = target;
38
+ target = null;
39
+ if (ws && (ws.readyState === 0 || ws.readyState === 1)) {
40
+ try {
41
+ typeof ws.terminate === "function" ? ws.terminate() : ws.close();
42
+ } catch { }
43
+ }
44
+ cb();
41
45
  }
42
46
  });
43
-
47
+ Proxy.setTarget = ws => {
48
+ if (ended) return;
49
+ target = ws;
50
+ };
51
+ Proxy.hardEnd = () => {
52
+ ended = true;
53
+ target = null;
54
+ };
44
55
  return Proxy;
45
56
  }
57
+
46
58
  function buildStream(options, WebSocket, Proxy) {
47
- const Stream = Duplexify(undefined, undefined, options);
48
- Stream.socket = WebSocket;
49
- let pingInterval;
50
- let reconnectTimeout;
51
- const clearTimers = () => {
52
- clearInterval(pingInterval);
53
- clearTimeout(reconnectTimeout);
54
- };
55
- WebSocket.onclose = () => {
56
- clearTimers();
57
- Stream.end();
58
- Stream.destroy();
59
- };
60
- WebSocket.onerror = err => {
61
- clearTimers();
62
- Stream.destroy(err);
59
+ const readable = new PassThrough();
60
+ const Stream = Duplexify(undefined, undefined, Object.assign({ end: false, autoDestroy: true }, options));
61
+ const NoopWritable = new Writable({ write(_c, _e, cb) { cb(); } });
62
+ let ws = WebSocket;
63
+ let pingTimer = null;
64
+ let livenessTimer = null;
65
+ let lastActivity = Date.now();
66
+ let attached = false;
67
+ let style = "prop";
68
+ let closed = false;
69
+
70
+ const toBuffer = d => {
71
+ if (Buffer.isBuffer(d)) return d;
72
+ if (d instanceof ArrayBuffer) return Buffer.from(d);
73
+ if (ArrayBuffer.isView(d)) return Buffer.from(d.buffer, d.byteOffset, d.byteLength);
74
+ return Buffer.from(String(d));
63
75
  };
64
- WebSocket.onmessage = event => {
65
- clearTimeout(reconnectTimeout);
66
- const data =
67
- event.data instanceof ArrayBuffer
68
- ? Buffer.from(event.data)
69
- : Buffer.from(event.data, "utf8");
70
- Stream.push(data);
76
+
77
+ const swapToNoopWritable = () => {
78
+ try { Stream.setWritable(NoopWritable); } catch { }
71
79
  };
72
- WebSocket.onopen = () => {
73
- Stream.setReadable(Proxy);
80
+
81
+ const onOpen = () => {
82
+ if (closed) return;
83
+ Proxy.setTarget(ws);
74
84
  Stream.setWritable(Proxy);
85
+ Stream.setReadable(readable);
75
86
  Stream.emit("connect");
76
- pingInterval = setInterval(() => {
77
- if (WebSocket.readyState === WebSocket.OPEN) {
78
- WebSocket.ping();
87
+ lastActivity = Date.now();
88
+ clearInterval(pingTimer);
89
+ clearInterval(livenessTimer);
90
+ pingTimer = setInterval(() => {
91
+ if (!ws || ws.readyState !== 1) return;
92
+ if (typeof ws.ping === "function") {
93
+ try { ws.ping(); } catch { }
94
+ } else {
95
+ try { ws.send("ping"); } catch { }
79
96
  }
80
97
  }, 30000);
81
- reconnectTimeout = setTimeout(() => {
82
- if (WebSocket.readyState === WebSocket.OPEN) {
83
- WebSocket.close();
84
- Stream.end();
85
- Stream.destroy();
98
+ livenessTimer = setInterval(() => {
99
+ if (!ws || ws.readyState !== 1) return;
100
+ if (Date.now() - lastActivity > 65000) {
101
+ try { typeof ws.terminate === "function" ? ws.terminate() : ws.close(); } catch { }
86
102
  }
87
- }, 60000);
103
+ }, 10000);
88
104
  };
89
- WebSocket_Global = WebSocket;
90
- Proxy.on("close", () => {
91
- clearTimers();
92
- WebSocket.close();
93
- });
105
+
106
+ const onMessage = data => {
107
+ lastActivity = Date.now();
108
+ readable.write(toBuffer(style === "dom" && data && data.data !== undefined ? data.data : data));
109
+ };
110
+
111
+ const onPong = () => {
112
+ lastActivity = Date.now();
113
+ };
114
+
115
+ const cleanup = () => {
116
+ if (closed) return;
117
+ closed = true;
118
+ clearInterval(pingTimer);
119
+ clearInterval(livenessTimer);
120
+ pingTimer = null;
121
+ livenessTimer = null;
122
+ Proxy.hardEnd();
123
+ swapToNoopWritable();
124
+ if (ws) {
125
+ detach(ws);
126
+ try {
127
+ if (ws.readyState === 1) {
128
+ typeof ws.terminate === "function" ? ws.terminate() : ws.close();
129
+ }
130
+ } catch { }
131
+ ws = null;
132
+ }
133
+ readable.end();
134
+ };
135
+
136
+ const onError = err => {
137
+ cleanup();
138
+ Stream.destroy(err);
139
+ };
140
+
141
+ const onClose = () => {
142
+ cleanup();
143
+ Stream.end();
144
+ if (!Stream.destroyed) Stream.destroy();
145
+ };
146
+
147
+ const attach = w => {
148
+ if (attached || !w) return;
149
+ attached = true;
150
+ if (typeof w.on === "function" && typeof w.off === "function") {
151
+ style = "node";
152
+ w.on("open", onOpen);
153
+ w.on("message", onMessage);
154
+ w.on("error", onError);
155
+ w.on("close", onClose);
156
+ if (typeof w.on === "function") w.on("pong", onPong);
157
+ } else if (typeof w.addEventListener === "function" && typeof w.removeEventListener === "function") {
158
+ style = "dom";
159
+ w.addEventListener("open", onOpen);
160
+ w.addEventListener("message", onMessage);
161
+ w.addEventListener("error", onError);
162
+ w.addEventListener("close", onClose);
163
+ } else {
164
+ style = "prop";
165
+ w.onopen = onOpen;
166
+ w.onmessage = onMessage;
167
+ w.onerror = onError;
168
+ w.onclose = onClose;
169
+ }
170
+ };
171
+
172
+ const detach = w => {
173
+ if (!attached || !w) return;
174
+ attached = false;
175
+ if (style === "node" && typeof w.off === "function") {
176
+ w.off("open", onOpen);
177
+ w.off("message", onMessage);
178
+ w.off("error", onError);
179
+ w.off("close", onClose);
180
+ if (typeof w.off === "function") w.off("pong", onPong);
181
+ } else if (style === "dom" && typeof w.removeEventListener === "function") {
182
+ w.removeEventListener("open", onOpen);
183
+ w.removeEventListener("message", onMessage);
184
+ w.removeEventListener("error", onError);
185
+ w.removeEventListener("close", onClose);
186
+ } else {
187
+ w.onopen = null;
188
+ w.onmessage = null;
189
+ w.onerror = null;
190
+ w.onclose = null;
191
+ }
192
+ };
193
+
194
+ attach(ws);
195
+ if (ws && ws.readyState === 1) onOpen();
196
+
197
+ Stream.on("prefinish", swapToNoopWritable);
198
+ Stream.on("finish", cleanup);
199
+ Stream.on("close", cleanup);
200
+ Proxy.on("close", swapToNoopWritable);
201
+
94
202
  return Stream;
95
203
  }
96
204
 
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ module.exports = {
3
+ topics: [
4
+ "/ls_req",
5
+ "/ls_resp",
6
+ "/legacy_web",
7
+ "/webrtc",
8
+ "/rtc_multi",
9
+ "/onevc",
10
+ "/br_sr",
11
+ "/sr_res",
12
+ "/t_ms",
13
+ "/thread_typing",
14
+ "/orca_typing_notifications",
15
+ "/notify_disconnect",
16
+ "/orca_presence",
17
+ "/inbox",
18
+ "/mercury",
19
+ "/messaging_events",
20
+ "/orca_message_notifications",
21
+ "/pp",
22
+ "/webrtc_response"
23
+ ]
24
+ };