File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,25 @@ const getClaps = url =>
10
10
}
11
11
} ) . then ( response => response . text ( ) ) ;
12
12
13
+
14
+ const WAVELENGTH = 60 * 5 ;
15
+ const secondsForClap = a => ( WAVELENGTH * Math . asin ( a / 10 ) ) / ( Math . PI * 2 ) ;
16
+
17
+ const computeRequest = clapCount => {
18
+ const requiredSeconds = secondsForClap ( clapCount ) ;
19
+ const serverSeconds = ( Date . now ( ) / 1000 ) % 60 ;
20
+ const delta = requiredSeconds - serverSeconds ;
21
+ return delta ;
22
+ }
23
+
13
24
const updateClaps = ( claps , url ) =>
14
25
// TODO: polyfill for IE (not edge)
15
26
fetch ( `${ API } /update-claps` + ( url ? `?url=${ url } ` : "" ) , {
16
27
method : "POST" ,
17
28
headers : {
18
29
"Content-Type" : "text/plain"
19
30
} ,
20
- body : JSON . stringify ( claps )
31
+ body : JSON . stringify ( computeRequest ( claps ) )
21
32
} ) . then ( response => response . text ( ) ) ;
22
33
23
34
const arrayOfSize = size => new Array ( size ) . fill ( undefined ) ;
You can’t perform that action at this time.
0 commit comments