@realvare/based 2.7.59 → 2.7.60
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/lib/Defaults/index.js +2 -2
- package/lib/Signal/libsignal.js +1 -22
- package/lib/Socket/socket.js +30 -12
- package/lib/Types/index.d.ts +2 -1
- package/lib/Types/index.js +1 -0
- package/package.json +1 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -33,7 +33,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
|
|
|
33
33
|
];
|
|
34
34
|
exports.DEFAULT_CONNECTION_CONFIG = {
|
|
35
35
|
version: baileys_version_json_1.version,
|
|
36
|
-
browser: Utils_1.Browsers.
|
|
36
|
+
browser: Utils_1.Browsers.windows('Chrome'),
|
|
37
37
|
waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
|
|
38
38
|
connectTimeoutMs: 20000,
|
|
39
39
|
keepAliveIntervalMs: 30000,
|
|
@@ -103,4 +103,4 @@ exports.DEFAULT_CACHE_TTLS = {
|
|
|
103
103
|
MSG_RETRY: 60 * 60, // 1 hour
|
|
104
104
|
CALL_OFFER: 5 * 60, // 5 minutes
|
|
105
105
|
USER_DEVICES: 5 * 60, // 5 minutes
|
|
106
|
-
};
|
|
106
|
+
};
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -42,17 +42,7 @@ const sender_key_record_1 = require("./Group/sender-key-record");
|
|
|
42
42
|
const Group_1 = require("./Group");
|
|
43
43
|
function makeLibSignalRepository(auth) {
|
|
44
44
|
const storage = signalStorage(auth);
|
|
45
|
-
const lidMapping = {
|
|
46
|
-
get: async (lid) => {
|
|
47
|
-
const { [lid]: pn } = await auth.keys.get('lid-mapping', [lid]);
|
|
48
|
-
return pn;
|
|
49
|
-
},
|
|
50
|
-
set: (lid, pn) => {
|
|
51
|
-
return auth.keys.set({ 'lid-mapping': { [lid]: pn } });
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
45
|
return {
|
|
55
|
-
lidMapping,
|
|
56
46
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
57
47
|
const senderName = jidToSignalSenderKeyName(group, authorJid);
|
|
58
48
|
const cipher = new Group_1.GroupCipher(storage, senderName);
|
|
@@ -117,17 +107,6 @@ function makeLibSignalRepository(auth) {
|
|
|
117
107
|
},
|
|
118
108
|
jidToSignalProtocolAddress(jid) {
|
|
119
109
|
return jidToSignalProtocolAddress(jid).toString();
|
|
120
|
-
},
|
|
121
|
-
getLidAddress(jid) {
|
|
122
|
-
const { user, device } = (0, WABinary_1.jidDecode)(jid);
|
|
123
|
-
return new libsignal.ProtocolAddress(user, device || 0);
|
|
124
|
-
},
|
|
125
|
-
getDeviceCanHandleLid() {
|
|
126
|
-
const { platform, pushname, verifiedName } = auth.creds;
|
|
127
|
-
if (platform === 'android' || platform === 'ios' || platform === 'smba' || platform === 'smbi') {
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
return false;
|
|
131
110
|
}
|
|
132
111
|
};
|
|
133
112
|
}
|
|
@@ -192,4 +171,4 @@ function signalStorage({ creds, keys }) {
|
|
|
192
171
|
};
|
|
193
172
|
}
|
|
194
173
|
};
|
|
195
|
-
}
|
|
174
|
+
}
|
package/lib/Socket/socket.js
CHANGED
|
@@ -130,14 +130,7 @@ const makeSocket = (config) => {
|
|
|
130
130
|
// ignore
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
|
|
134
|
-
if (message.includes('429') || message.includes('rate limit')) {
|
|
135
|
-
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
136
|
-
logger.info({ wait }, 'backing off due to rate limit');
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
// intentionally empty; wait to delay further sends
|
|
139
|
-
}, wait);
|
|
140
|
-
}
|
|
133
|
+
|
|
141
134
|
};
|
|
142
135
|
/** await the next incoming message */
|
|
143
136
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -192,15 +185,40 @@ const makeSocket = (config) => {
|
|
|
192
185
|
}
|
|
193
186
|
};
|
|
194
187
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
188
|
+
const waCallAndRetry = async (task, errorStr) => {
|
|
189
|
+
let retries = 0;
|
|
190
|
+
const maxRetries = config.maxMsgRetryCount;
|
|
191
|
+
const initialDelay = config.retryRequestDelayMs;
|
|
192
|
+
while (retries < maxRetries) {
|
|
193
|
+
try {
|
|
194
|
+
return await task();
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof boom_1.Boom && error.output.statusCode === Types_1.DisconnectReason.rateLimit) {
|
|
197
|
+
retries++;
|
|
198
|
+
const delayMs = initialDelay * Math.pow(2, retries - 1); // Exponential backoff
|
|
199
|
+
logger.warn({ error, retries, delayMs }, `Rate limit hit for ${errorStr}. Retrying in ${delayMs}ms...`);
|
|
200
|
+
await (0, Utils_1.delay)(delayMs);
|
|
201
|
+
} else {
|
|
202
|
+
throw error; // Re-throw other errors immediately
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
throw new boom_1.Boom(`Failed to ${errorStr} after ${maxRetries} retries due to rate limits`, { statusCode: Types_1.DisconnectReason.rateLimit });
|
|
207
|
+
};
|
|
208
|
+
|
|
195
209
|
const query = async (node, timeoutMs) => {
|
|
196
210
|
if (!node.attrs.id) {
|
|
197
211
|
node.attrs.id = generateMessageTag();
|
|
198
212
|
}
|
|
199
213
|
const msgId = node.attrs.id;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
214
|
+
|
|
215
|
+
const [result] = await waCallAndRetry(async () => {
|
|
216
|
+
return await Promise.all([
|
|
217
|
+
waitForMessage(msgId, timeoutMs),
|
|
218
|
+
sendNode(node)
|
|
219
|
+
]);
|
|
220
|
+
}, `query ${msgId}`);
|
|
221
|
+
|
|
204
222
|
if ('tag' in result) {
|
|
205
223
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
206
224
|
}
|
package/lib/Types/index.d.ts
CHANGED
package/lib/Types/index.js
CHANGED
|
@@ -39,4 +39,5 @@ var DisconnectReason;
|
|
|
39
39
|
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
40
40
|
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
41
41
|
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
42
|
+
DisconnectReason[DisconnectReason["rateLimit"] = 429] = "rateLimit";
|
|
42
43
|
})(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
|