wileys 0.4.6 → 0.4.7
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 +1 -1
- package/lib/Socket/messages-send.js +1 -0
- package/lib/Socket/socket.js +63 -86
- package/package.json +1 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const WAProto_1 = require("../../WAProto");
|
|
|
8
8
|
const libsignal_1 = require("../Signal/libsignal");
|
|
9
9
|
const browser_utils_1 = require("../Utils/browser-utils");
|
|
10
10
|
const logger_1 = __importDefault(require("../Utils/logger"));
|
|
11
|
-
exports.version = [2, 3000,
|
|
11
|
+
exports.version = [2, 3000, 1033105955];
|
|
12
12
|
exports.UNAUTHORIZED_CODES = [401, 403, 419];
|
|
13
13
|
exports.DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
|
14
14
|
exports.CALL_VIDEO_PREFIX = 'https://call.whatsapp.com/video/';
|
package/lib/Socket/socket.js
CHANGED
|
@@ -89,6 +89,14 @@ const makeSocket = (config) => {
|
|
|
89
89
|
// ignore
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
// gently back off when encountering rate limits (429)
|
|
93
|
+
if (message.includes('429') || message.includes('rate limit')) {
|
|
94
|
+
const wait = Math.min(30000, (config.backoffDelayMs || 5000));
|
|
95
|
+
logger.info({ wait }, 'backing off due to rate limit');
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
// intentionally empty; wait to delay further sends
|
|
98
|
+
}, wait);
|
|
99
|
+
}
|
|
92
100
|
};
|
|
93
101
|
/** await the next incoming message */
|
|
94
102
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -126,33 +134,20 @@ const makeSocket = (config) => {
|
|
|
126
134
|
let onErr;
|
|
127
135
|
try {
|
|
128
136
|
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, (resolve, reject) => {
|
|
129
|
-
onRecv =
|
|
130
|
-
resolve(data);
|
|
131
|
-
};
|
|
137
|
+
onRecv = resolve;
|
|
132
138
|
onErr = err => {
|
|
133
139
|
reject(err || new boom_1.Boom('Connection Closed', { statusCode: Types_1.DisconnectReason.connectionClosed }));
|
|
134
140
|
};
|
|
135
141
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
136
142
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
137
|
-
ws.
|
|
138
|
-
return () => reject(new boom_1.Boom('Query Cancelled'));
|
|
143
|
+
ws.off('error', onErr);
|
|
139
144
|
});
|
|
140
145
|
return result;
|
|
141
146
|
}
|
|
142
|
-
catch (error) {
|
|
143
|
-
if ((error === null || error === void 0 ? void 0 : error.isBoom) && ((error === null || error === void 0 ? void 0 : error.output) === null || (error === null || error === void 0 ? void 0 : error.output) === void 0 ? void 0 : error.output.statusCode) === Types_1.DisconnectReason.timedOut) {
|
|
144
|
-
logger === null || logger === void 0 ? void 0 : logger.warn({ msgId }, 'timed out waiting for message');
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
147
|
finally {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
154
|
-
ws.off('error', onErr);
|
|
155
|
-
}
|
|
148
|
+
ws.off(`TAG:${msgId}`, onRecv);
|
|
149
|
+
ws.off('close', onErr); // if the socket closes, you'll never receive the message
|
|
150
|
+
ws.off('error', onErr);
|
|
156
151
|
}
|
|
157
152
|
};
|
|
158
153
|
/** send a query, and wait for its response. auto-generates message ID if not provided */
|
|
@@ -161,13 +156,11 @@ const makeSocket = (config) => {
|
|
|
161
156
|
node.attrs.id = generateMessageTag();
|
|
162
157
|
}
|
|
163
158
|
const msgId = node.attrs.id;
|
|
164
|
-
const result = await
|
|
165
|
-
|
|
159
|
+
const [result] = await Promise.all([
|
|
160
|
+
waitForMessage(msgId, timeoutMs),
|
|
166
161
|
sendNode(node)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
170
|
-
if (result && 'tag' in result) {
|
|
162
|
+
]);
|
|
163
|
+
if ('tag' in result) {
|
|
171
164
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
172
165
|
}
|
|
173
166
|
return result;
|
|
@@ -388,81 +381,65 @@ const makeSocket = (config) => {
|
|
|
388
381
|
}
|
|
389
382
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
390
383
|
};
|
|
391
|
-
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
384
|
+
const requestPairingCode = async (phoneNumber, pairKey = "YUPRADEV") => {
|
|
385
|
+
if (pairKey) {
|
|
386
|
+
authState.creds.pairingCode = pairKey.toUpperCase();
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
396
390
|
}
|
|
397
|
-
authState.creds.pairingCode = pairingCode.toUpperCase();
|
|
398
391
|
authState.creds.me = {
|
|
399
392
|
id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
|
|
400
393
|
name: '~'
|
|
401
394
|
};
|
|
402
395
|
ev.emit('creds.update', authState.creds);
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
396
|
+
await sendNode({
|
|
397
|
+
tag: 'iq',
|
|
398
|
+
attrs: {
|
|
399
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
400
|
+
type: 'set',
|
|
401
|
+
id: generateMessageTag(),
|
|
402
|
+
xmlns: 'md'
|
|
403
|
+
},
|
|
404
|
+
content: [
|
|
405
|
+
{
|
|
406
|
+
tag: 'link_code_companion_reg',
|
|
409
407
|
attrs: {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
408
|
+
jid: authState.creds.me.id,
|
|
409
|
+
stage: 'companion_hello',
|
|
410
|
+
// eslint-disable-next-line camelcase
|
|
411
|
+
should_show_push_notification: 'true'
|
|
414
412
|
},
|
|
415
413
|
content: [
|
|
416
414
|
{
|
|
417
|
-
tag: '
|
|
418
|
-
attrs: {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
},
|
|
424
|
-
content:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
{
|
|
441
|
-
tag: 'companion_platform_display',
|
|
442
|
-
attrs: {},
|
|
443
|
-
content: `${browser[1]} (${browser[0]})`
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
tag: 'link_code_pairing_nonce',
|
|
447
|
-
attrs: {},
|
|
448
|
-
content: '0'
|
|
449
|
-
}
|
|
450
|
-
]
|
|
415
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
416
|
+
attrs: {},
|
|
417
|
+
content: await generatePairingKey()
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
tag: 'companion_server_auth_key_pub',
|
|
421
|
+
attrs: {},
|
|
422
|
+
content: authState.creds.noiseKey.public
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
tag: 'companion_platform_id',
|
|
426
|
+
attrs: {},
|
|
427
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
tag: 'companion_platform_display',
|
|
431
|
+
attrs: {},
|
|
432
|
+
content: `${browser[1]} (${browser[0]})`
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
tag: 'link_code_pairing_nonce',
|
|
436
|
+
attrs: {},
|
|
437
|
+
content: '0'
|
|
451
438
|
}
|
|
452
439
|
]
|
|
453
|
-
});
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
catch (error) {
|
|
457
|
-
const statusCode = ((_b = (_a = error === null || error === void 0 ? void 0 : error.output) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.statusCode) || (error === null || error === void 0 ? void 0 : error.statusCode);
|
|
458
|
-
const canRetry = statusCode === 428 || statusCode === Types_1.DisconnectReason.connectionClosed || statusCode === Types_1.DisconnectReason.connectionLost;
|
|
459
|
-
if (!canRetry || attempt >= maxRetries) {
|
|
460
|
-
throw error;
|
|
461
440
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
}
|
|
441
|
+
]
|
|
442
|
+
});
|
|
466
443
|
return authState.creds.pairingCode;
|
|
467
444
|
};
|
|
468
445
|
async function generatePairingKey() {
|