Skip to content

Commit

Permalink
Add delay between reconnections to the websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterIO02 committed Mar 19, 2022
1 parent 8acc448 commit 1f43e49
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions files/server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const io = require("socket.io-client")
const { io } = require("socket.io-client")
const fs = require("fs")
const dataProcessor = require("./dataProcessor")
const config = require(process.cwd() + "/config.json")
Expand All @@ -14,7 +14,8 @@ if (config.customServer && config.customServer.clientUrl !== "") {
}

exports.startServer = async () => {
ioClient = io.connect(socketUrl)
const socket = io(socketUrl, { reconnectionDelay: 10000, reconnectionDelayMax: 10000 })
ioClient = socket.connect()

console.log("Server started!")

Expand All @@ -29,6 +30,7 @@ exports.startServer = async () => {
setInterval(() => {
if (isRendering() === false && desktopIdle.getIdleTime() < 30 && ioClient.connected) {
console.log("The computer is being used, disconnecting from the o!rdr server.")
// when using .disconnect() socket.io won't try to reconnect automatically
ioClient.disconnect()
} else if (desktopIdle.getIdleTime() > 45 && !ioClient.connected) {
console.log("The computer is idle, reconnecting to the o!rdr server.")
Expand Down

0 comments on commit 1f43e49

Please sign in to comment.