@@ -7,44 +7,35 @@ import jQuery from 'jquery';
7
7
import 'flipclock/compiled/flipclock.js' ;
8
8
import log from 'loglevel' ;
9
9
10
- const initialCount = 80482701 ;
11
- const pollIntervalWhenVisible = 5000 ;
12
- const pollIntervalWhenHidden = 1000 * 1000 ;
13
- const url = 'https://webtask.it.auth0.com/api/run/' +
14
- 'wt-matiasw-gmail_com-0/proxy?' +
15
- 'url=http://metrics.it.auth0.com/counters' ;
10
+ const baselineDate = new Date ( 2018 , 3 - 1 , 6 ) ;
11
+ // We should try to get a real number for this.
12
+ // Set on 2018-03-06
13
+ const baselineCount = 53919517299 ;
16
14
15
+ const secondsPerDay = 60 * 60 * 24 ;
16
+ const loginsPerDay = 50000000 ;
17
+ const loginsPerSecond = loginsPerDay / secondsPerDay ;
18
+
19
+ const intervalMs = 1000 ;
20
+
21
+ const initialCount = getLoginCount ( ) ;
17
22
const flipCounter = $ ( counterElement ) . FlipClock ( initialCount , {
18
23
clockFace : 'Counter' ,
19
24
minimumDigits : initialCount . toString ( ) . length
20
25
} ) ;
21
26
22
- function updateCounterFromWebtask ( ) {
23
- return new Promise ( ( resolve , reject ) => {
24
- httpGet ( url , false ) . then ( data => {
25
- const parsed = JSON . parse ( data ) ;
26
- flipCounter . setTime ( parsed . logins ) ;
27
- } ) . catch ( e => {
28
- log . warn ( 'Failed to set count from Webtask: ' , e ) ;
29
- } ) ;
30
- } ) ;
27
+ function getLoginCount ( ) {
28
+ return baselineCount +
29
+ Math . round ( ( new Date ( ) - baselineDate ) / 1000 * loginsPerSecond ) ;
31
30
}
32
31
33
- let elapsed = pollIntervalWhenHidden ;
34
32
function updateCounter ( ) {
35
- elapsed += pollIntervalWhenVisible ;
36
-
37
33
if ( isInViewport ( counterElement ) ) {
38
- updateCounterFromWebtask ( ) ;
39
- } else {
40
- if ( elapsed >= pollIntervalWhenHidden ) {
41
- elapsed = 0 ;
42
- updateCounterFromWebtask ( ) ;
43
- }
34
+ flipCounter . setTime ( getLoginCount ( ) ) ;
44
35
}
45
36
}
46
37
47
38
export function setupJwtCounter ( ) {
48
39
updateCounter ( ) ;
49
- setInterval ( updateCounter , pollIntervalWhenVisible ) ;
40
+ setInterval ( updateCounter , intervalMs ) ;
50
41
}
0 commit comments