wileys 0.4.4 → 0.4.6
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/wileys-version.json +1 -1
- package/lib/Socket/socket.js +57 -41
- package/package.json +1 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -389,7 +389,7 @@ const makeSocket = (config) => {
|
|
|
389
389
|
end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
|
|
390
390
|
};
|
|
391
391
|
const requestPairingCode = async (phoneNumber, pairKey) => {
|
|
392
|
-
|
|
392
|
+
var _a, _b;
|
|
393
393
|
const pairingCode = pairKey || (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
|
|
394
394
|
if (pairKey && pairKey.length !== 8) {
|
|
395
395
|
throw new Error('Custom pairing code must be exactly 8 chars');
|
|
@@ -400,53 +400,69 @@ const makeSocket = (config) => {
|
|
|
400
400
|
name: '~'
|
|
401
401
|
};
|
|
402
402
|
ev.emit('creds.update', authState.creds);
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
xmlns: 'md'
|
|
410
|
-
},
|
|
411
|
-
content: [
|
|
412
|
-
{
|
|
413
|
-
tag: 'link_code_companion_reg',
|
|
403
|
+
const maxRetries = 2;
|
|
404
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
405
|
+
try {
|
|
406
|
+
await waitForSocketOpen();
|
|
407
|
+
await sendNode({
|
|
408
|
+
tag: 'iq',
|
|
414
409
|
attrs: {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
410
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
411
|
+
type: 'set',
|
|
412
|
+
id: generateMessageTag(),
|
|
413
|
+
xmlns: 'md'
|
|
419
414
|
},
|
|
420
415
|
content: [
|
|
421
416
|
{
|
|
422
|
-
tag: '
|
|
423
|
-
attrs: {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
content:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
417
|
+
tag: 'link_code_companion_reg',
|
|
418
|
+
attrs: {
|
|
419
|
+
jid: authState.creds.me.id,
|
|
420
|
+
stage: 'companion_hello',
|
|
421
|
+
// eslint-disable-next-line camelcase
|
|
422
|
+
should_show_push_notification: 'true'
|
|
423
|
+
},
|
|
424
|
+
content: [
|
|
425
|
+
{
|
|
426
|
+
tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
|
|
427
|
+
attrs: {},
|
|
428
|
+
content: await generatePairingKey()
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
tag: 'companion_server_auth_key_pub',
|
|
432
|
+
attrs: {},
|
|
433
|
+
content: authState.creds.noiseKey.public
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
tag: 'companion_platform_id',
|
|
437
|
+
attrs: {},
|
|
438
|
+
content: (0, Utils_1.getPlatformId)(browser[1])
|
|
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
|
+
]
|
|
445
451
|
}
|
|
446
452
|
]
|
|
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;
|
|
447
461
|
}
|
|
448
|
-
|
|
449
|
-
|
|
462
|
+
logger.warn({ attempt, statusCode, trace: error === null || error === void 0 ? void 0 : error.stack }, 'pairing code request failed, retrying');
|
|
463
|
+
await (0, Utils_1.delay)(500 * attempt);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
450
466
|
return authState.creds.pairingCode;
|
|
451
467
|
};
|
|
452
468
|
async function generatePairingKey() {
|