wileys 0.4.2 → 0.4.3
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/messages-send.js +0 -1
- package/lib/Socket/socket.js +7 -13
- package/package.json +1 -1
package/lib/Socket/socket.js
CHANGED
|
@@ -89,14 +89,6 @@ 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
|
-
}
|
|
100
92
|
};
|
|
101
93
|
/** await the next incoming message */
|
|
102
94
|
const awaitNextMessage = async (sendMsg) => {
|
|
@@ -140,7 +132,7 @@ const makeSocket = (config) => {
|
|
|
140
132
|
};
|
|
141
133
|
ws.on(`TAG:${msgId}`, onRecv);
|
|
142
134
|
ws.on('close', onErr); // if the socket closes, you'll never receive the message
|
|
143
|
-
ws.
|
|
135
|
+
ws.on('error', onErr);
|
|
144
136
|
});
|
|
145
137
|
return result;
|
|
146
138
|
}
|
|
@@ -156,11 +148,13 @@ const makeSocket = (config) => {
|
|
|
156
148
|
node.attrs.id = generateMessageTag();
|
|
157
149
|
}
|
|
158
150
|
const msgId = node.attrs.id;
|
|
159
|
-
const
|
|
160
|
-
waitForMessage(msgId, timeoutMs)
|
|
151
|
+
const result = await (0, Utils_1.promiseTimeout)(timeoutMs, async (resolve, reject) => {
|
|
152
|
+
const wait = waitForMessage(msgId, timeoutMs).catch(reject);
|
|
161
153
|
sendNode(node)
|
|
162
|
-
|
|
163
|
-
|
|
154
|
+
.then(async () => resolve(await wait))
|
|
155
|
+
.catch(reject);
|
|
156
|
+
});
|
|
157
|
+
if (result && 'tag' in result) {
|
|
164
158
|
(0, WABinary_1.assertNodeErrorFree)(result);
|
|
165
159
|
}
|
|
166
160
|
return result;
|