Skip to content

Instantly share code, notes, and snippets.

@manuquentin
Last active December 20, 2015 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save manuquentin/6042760 to your computer and use it in GitHub Desktop.
Save manuquentin/6042760 to your computer and use it in GitHub Desktop.
var exitDetected = 0;
var senseiDetected = 0;
var doorOpened = 0;
var existStatusInterval = 0;
app.post('/door-open', function (req, res) {
doorOpened = 1;
existStatusInterval = setTimeout(setExitStatus, 5000);
dispatchInfos();
res.send();
});
app.post('/detect', function (req, res) {
clearTimeout(existStatusInterval);
if(doorOpened){
senseiDetected = 1;
}
doorOpened = 0;
dispatchInfos();
});
function setExitStatus(){
exitDetected = 1;
dispatchInfos();
}
function dispatchInfos(){
if (!currentSocket) {
return;
}
currentSocket.emit('status', {
sensei : senseiDetected,
exit: exitDetected
});
exitDetected = 0;
senseiDetected = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment