steamutils 1.2.9 → 1.2.11

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 +31 -16
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -199,7 +199,9 @@ function SteamClient({
199
199
  }
200
200
  intervalRandoms[key] = setTimeout(function () {
201
201
  doSetInterval(cb, timeout, key)
202
- cb()
202
+ if (state !== 'Offline') {
203
+ cb()
204
+ }
203
205
  }, _.random(timeout[0], timeout[1]))
204
206
  } else {
205
207
  if (intervals[key] !== undefined) {
@@ -208,7 +210,12 @@ function SteamClient({
208
210
  } catch (e) {
209
211
  }
210
212
  }
211
- intervals[key] = setInterval(cb, timeout)
213
+
214
+ intervals[key] = setInterval(function () {
215
+ if (state !== 'Offline') {
216
+ cb()
217
+ }
218
+ }, timeout)
212
219
  }
213
220
 
214
221
  return key
@@ -373,34 +380,42 @@ function SteamClient({
373
380
  steamClient.on('disconnected', async (eresult, msg) => {
374
381
  state = 'Offline'
375
382
  log('disconnected', eresult, msg)
376
- doClearIntervals()
383
+
377
384
  callEvent(events.disconnected, {eresult, msg})
378
385
 
379
386
  if (eresult === 3 && autoReconnect && !isLogOff) {
380
-
381
387
  async function relogin(retry) {
382
388
  if (retry <= 0) {
383
389
  console.error("Cannot relogin")
384
- return
385
- }
386
- const isSuccess = await login(true)
387
- if (isSuccess) {
388
- onEvent('loggedOn', function (loggedOnResponse) {
390
+ return false
391
+ } else {
392
+ const isSuccess = await login(true)
393
+ if (isSuccess) {
394
+ const loggedOnResponse = await new Promise(resolve => {
395
+ onEvent('loggedOn', function (loggedOnResponse) {
396
+ resolve(loggedOnResponse)
397
+ }, true, 120000)
398
+ })
389
399
  if (loggedOnResponse) {
390
400
  console.log("Relogin success")
401
+ return true
391
402
  } else {
392
- relogin(retry - 1)
403
+ return await relogin(retry - 1)
393
404
  }
394
- }, true, 120000)
395
- } else {
396
- setTimeout(function () {
397
- relogin(retry - 1)
398
- }, 60000)
405
+ } else {
406
+ await sleep(60000)
407
+ return await relogin(retry - 1)
408
+ }
399
409
  }
400
410
  }
401
411
 
402
412
  await sleep(60000)
403
- await relogin(10)
413
+ const isSuccess = await relogin(10)
414
+ if (!isSuccess) {
415
+ doClearIntervals()
416
+ }
417
+ } else {
418
+ doClearIntervals()
404
419
  }
405
420
  })
406
421
  steamClient.on('error', async (e) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.09",
3
+ "version": "1.2.11",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.3.4",