forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout.js
More file actions
39 lines (33 loc) · 1.04 KB
/
timeout.js
File metadata and controls
39 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
self.time = 0;
self.interval = null;
self.addEventListener("message", (e) => {
if (self.hasOwnProperty(e.data.method)) {
if (e.data.data !== undefined) {
return self[e.data.method](e.data.data);
}
return self[e.data.method]();
}
});
self.start = function (data) {
// Exit if timeout control is not enabled
if (!data.enabled) {
return;
}
const timestampAtStart = Math.floor(Date.now() / 1000);
const timeoutAt = timestampAtStart + (data.timeout * 60);
clearInterval(self.interval);
self.interval = setInterval(function () {
const currentTimestamp = Math.floor(Date.now() / 1000);
const timeRemaining = timeoutAt - currentTimestamp;
if (timeRemaining < data.warnSeconds && timeRemaining > 0) {
self.postMessage({ method: "countdown", data: { time: timeRemaining } });
}
if (timeRemaining < 1) {
clearInterval(self.interval);
self.postMessage({ method: "timedOut", data: { time: timeRemaining } });
}
}, 1000);
};
self.stop = function () {
clearInterval(self.interval);
};