@@ -7,44 +7,35 @@ import jQuery from 'jquery';
77import 'flipclock/compiled/flipclock.js' ;
88import log from 'loglevel' ;
99
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 ;
1614
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 ( ) ;
1722const flipCounter = $ ( counterElement ) . FlipClock ( initialCount , {
1823 clockFace : 'Counter' ,
1924 minimumDigits : initialCount . toString ( ) . length
2025} ) ;
2126
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 ) ;
3130}
3231
33- let elapsed = pollIntervalWhenHidden ;
3432function updateCounter ( ) {
35- elapsed += pollIntervalWhenVisible ;
36-
3733 if ( isInViewport ( counterElement ) ) {
38- updateCounterFromWebtask ( ) ;
39- } else {
40- if ( elapsed >= pollIntervalWhenHidden ) {
41- elapsed = 0 ;
42- updateCounterFromWebtask ( ) ;
43- }
34+ flipCounter . setTime ( getLoginCount ( ) ) ;
4435 }
4536}
4637
4738export function setupJwtCounter ( ) {
4839 updateCounter ( ) ;
49- setInterval ( updateCounter , pollIntervalWhenVisible ) ;
40+ setInterval ( updateCounter , intervalMs ) ;
5041}
0 commit comments