steamutils 1.4.88 → 1.4.90

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/SteamClient.js +28 -9
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -2159,7 +2159,7 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2159
2159
  log("logOff");
2160
2160
  isLogOff = true;
2161
2161
 
2162
- MessageQueue.length = 0;
2162
+ clearMessageQueue();
2163
2163
 
2164
2164
  callEvent(events.logOff);
2165
2165
  events.logOff = [];
@@ -2295,8 +2295,16 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2295
2295
 
2296
2296
  const MessageQueue = [];
2297
2297
 
2298
+ function clearMessageQueue() {
2299
+ while (MessageQueue.length) {
2300
+ const item = MessageQueue.shift();
2301
+ item?.callback?.();
2302
+ }
2303
+ }
2304
+
2298
2305
  async function _execMessageQueue() {
2299
2306
  if (isLogOff) {
2307
+ clearMessageQueue();
2300
2308
  return;
2301
2309
  }
2302
2310
 
@@ -2304,12 +2312,23 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2304
2312
  return;
2305
2313
  }
2306
2314
  while (MessageQueue.length) {
2307
- isSendingFriendMessages = true;
2308
- const item = MessageQueue.shift();
2309
- const result = await _sendFriendMessage(item.steamId, item.message);
2310
- item.callback(result);
2311
- if (MessageQueue.length) {
2312
- await sleep(1000);
2315
+ try {
2316
+ isSendingFriendMessages = true;
2317
+ const item = MessageQueue.shift();
2318
+ if (!item) {
2319
+ break;
2320
+ }
2321
+ const result = await _sendFriendMessage(item.steamId, item.message);
2322
+ if (typeof item.callback === "function") {
2323
+ try {
2324
+ await item.callback(result);
2325
+ } catch (e) {}
2326
+ }
2327
+ if (MessageQueue.length) {
2328
+ await sleep(1000);
2329
+ }
2330
+ } catch (e) {
2331
+ console.error("_execMessageQueue", e);
2313
2332
  }
2314
2333
  }
2315
2334
  isSendingFriendMessages = false;
@@ -2322,8 +2341,8 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2322
2341
  return;
2323
2342
  }
2324
2343
  result = await new Promise((resolve) => {
2325
- steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...arg) {
2326
- resolve(arg);
2344
+ steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...args) {
2345
+ resolve(args);
2327
2346
  });
2328
2347
  });
2329
2348
  if (result?.[1]?.server_timestamp) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.88",
3
+ "version": "1.4.90",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",