steamutils 1.2.9 → 1.2.11
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/SteamClient.js +31 -16
- 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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
387
|
-
|
388
|
-
|
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
|
-
}
|
395
|
-
|
396
|
-
|
397
|
-
|
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) => {
|