@ubedsockets/baileys 1.7.1 → 1.7.2
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/Socket/socket.js +42 -39
- package/package.json +1 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -99,47 +99,50 @@ const makeSocket = (config) => {
|
|
|
99
99
|
const buff = (0, WABinary_1.encodeBinaryNode)(frame);
|
|
100
100
|
return sendRawMessage(buff);
|
|
101
101
|
};
|
|
102
|
-
|
|
102
|
+
|
|
103
|
+
/* log & process any unexpected errors */
|
|
103
104
|
const onUnexpectedError = (err, msg) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
105
|
+
logger.error({ err }, `unexpected error in '${msg}'`);
|
|
106
|
+
const message = (err && ((err.stack || err.message) || String(err))).toLowerCase();
|
|
107
|
+
// auto recover from cryptographic desyncs by re-uploading prekeys
|
|
108
|
+
if (message.includes('bad mac') || (message.includes('mac') && message.includes('invalid'))) {
|
|
109
|
+
try {
|
|
110
|
+
uploadPreKeysToServerIfRequired(true)
|
|
111
|
+
.catch(e => logger.warn({ e }, 'failed to re-upload prekeys after bad mac'));
|
|
112
|
+
}
|
|
113
|
+
catch (_e) {
|
|
114
|
+
// ignore
|
|
115
|
+
}
|
|
116
|
+
}
|
|
116
117
|
};
|
|
117
|
-
|
|
118
|
+
|
|
119
|
+
/* await the next incoming message */
|
|
118
120
|
const awaitNextMessage = async (sendMsg) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
if (!ws.isOpen) {
|
|
122
|
+
throw new boom_1.Boom('Connection Closed', {
|
|
123
|
+
statusCode: Types_1.DisconnectReason.connectionClosed
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
let onOpen;
|
|
127
|
+
let onClose;
|
|
128
|
+
const result = (0, Utils_1.promiseTimeout)(connectTimeoutMs, (resolve, reject) => {
|
|
129
|
+
onOpen = resolve;
|
|
130
|
+
onClose = mapWebSocketError(reject);
|
|
131
|
+
ws.on('frame', onOpen);
|
|
132
|
+
ws.on('close', onClose);
|
|
133
|
+
ws.on('error', onClose);
|
|
134
|
+
})
|
|
135
|
+
.finally(() => {
|
|
136
|
+
ws.off('frame', onOpen);
|
|
137
|
+
ws.off('close', onClose);
|
|
138
|
+
ws.off('error', onClose);
|
|
139
|
+
});
|
|
140
|
+
if (sendMsg) {
|
|
141
|
+
sendRawMessage(sendMsg).catch(onClose);
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
142
144
|
};
|
|
145
|
+
|
|
143
146
|
/*
|
|
144
147
|
Wait for a message with a certain tag to be received
|
|
145
148
|
@param msgId the message tag to await
|
|
@@ -259,7 +262,7 @@ const makeSocket = (config) => {
|
|
|
259
262
|
logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'recv xml' });
|
|
260
263
|
}
|
|
261
264
|
/* Check if this is a response to a message we sent */
|
|
262
|
-
anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}
|
|
265
|
+
anyTriggered = ws.emit(`${Defaults_1.DEF_TAG_PREFIX}${msgId}`, frame) || anyTriggered;
|
|
263
266
|
/* Check if this is a response to a message we are expecting */
|
|
264
267
|
const l0 = frame.tag;
|
|
265
268
|
const l1 = frame.attrs || {};
|
|
@@ -664,4 +667,4 @@ function mapWebSocketError(handler) {
|
|
|
664
667
|
return (error) => {
|
|
665
668
|
handler(new boom_1.Boom(`WebSocket Error (${error === null || error === void 0 ? void 0 : error.message})`, { statusCode: (0, Utils_1.getCodeFromWSError)(error), data: error }));
|
|
666
669
|
};
|
|
667
|
-
}
|
|
670
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubedsockets/baileys",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "@ubedsockets/baileys,baileys A high-performance WhatsApp Web API wrapper based on Baileys, optimized for bot developers with integrated utility scrapers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|