Skip to content

Commit

Permalink
feat: sine wave!
Browse files Browse the repository at this point in the history
BREAKING CHANGE: extra anti-hack protection
  • Loading branch information
ColinEberhardt committed Sep 24, 2018
1 parent ca620c4 commit 25fb09d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/applause-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,25 @@ const getClaps = url =>
}
}).then(response => response.text());


const WAVELENGTH = 60 * 5;
const secondsForClap = a => (WAVELENGTH * Math.asin(a / 10)) / (Math.PI * 2);

const computeRequest = clapCount => {
const requiredSeconds = secondsForClap(clapCount);
const serverSeconds = (Date.now() / 1000) % 60;
const delta = requiredSeconds - serverSeconds;
return delta;
}

const updateClaps = (claps, url) =>
// TODO: polyfill for IE (not edge)
fetch(`${API}/update-claps` + (url ? `?url=${url}` : ""), {
method: "POST",
headers: {
"Content-Type": "text/plain"
},
body: JSON.stringify(claps)
body: JSON.stringify(computeRequest(claps))
}).then(response => response.text());

const arrayOfSize = size => new Array(size).fill(undefined);
Expand Down

0 comments on commit 25fb09d

Please sign in to comment.