diff options
author | David Gay <david@davidgay.org> | 2021-06-07 21:24:02 -0400 |
---|---|---|
committer | David Gay <david@davidgay.org> | 2021-06-07 21:24:02 -0400 |
commit | 39178217ecf722fbd902e07a053e35fa290488f8 (patch) | |
tree | 818522cf10f801a4ec33f73fed7fb1bd5e214e93 | |
parent | b6955ee9aa0058f64f6e3b6314d2b7358939bc2e (diff) |
Hook in new web worker stuff with finish activity POST retry stuff
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | app/javascript/controllers/timer_controller.js | 9 | ||||
-rw-r--r-- | public/timer_worker.js | 5 |
3 files changed, 16 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 83c8c33..087d604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,12 @@ All notable changes to this project will be documented in this file. - Physical resistance 8 -> 5 - Slash base min damage 5 -> 4 - Slash base max damage 12 -> 10 + +### Networking +- I may have improved the timer reconnect code, especially in situations where the client can't connect to the + server (like if you're having internet problems). Or I may have introduced additonal problems. Or both. + But one of the main ideas is that if the client can't reach the server, it should keep trying indefinitely, once a + minute. We'll see. Let me know. ## [0.1.8.2] - 2021-06-07 diff --git a/app/javascript/controllers/timer_controller.js b/app/javascript/controllers/timer_controller.js index f6ba4f3..1af1e10 100644 --- a/app/javascript/controllers/timer_controller.js +++ b/app/javascript/controllers/timer_controller.js @@ -38,13 +38,16 @@ export default class extends Controller { url: controller.postUrlValue, success: () => { this.postFailures = 0; + App.timerWorker.postMessage({ "set_timeout": 10 }); }, error: (e, xhr) => { this.postFailures++; if (this.postFailures < 3) { - setTimeout(controller.finishActivity, 1000); // 1 second - } else if (xhr === "") { - setTimeout(controller.finishActivity, 60000); // 1 minute + App.timerWorker.postMessage({ "run_flag": true }); + App.timerWorker.postMessage({ "set_timeout": 1000 }); + } else if (this.postFailures < 5 || xhr === "") { + App.timerWorker.postMessage({ "run_flag": true }); + App.timerWorker.postMessage({ "set_timeout": 60000 }); } }, }); diff --git a/public/timer_worker.js b/public/timer_worker.js index 3d3e79a..c62679a 100644 --- a/public/timer_worker.js +++ b/public/timer_worker.js @@ -1,10 +1,11 @@ let timerInterval = null; +let timerTimeout = 10; function setTimerInterval() { if (!timerInterval) { timerInterval = setInterval(function() { postMessage("timerTick"); - }, 10); + }, timerTimeout); } } @@ -20,5 +21,7 @@ onmessage = function(event) { } else { clearTimerInterval(); } + } else if ("set_timeout" in event.data) { + timerTimeout = event.data["set_timeout"]; } } |