Last active
October 27, 2016 15:21
-
-
Save boombatower/b98c854669fee122111bd49e79633af2 to your computer and use it in GitHub Desktop.
Play a notification sound whenever an Android IP Webcam motion sensor exceeds the threshold.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Execute in developer console on /sensors.html. | |
var limit = document.getElementById('motion_limit').value; | |
var audio = new Audio('http://gabenewell.org/audio/gabenewellwatchingyou.mp3'); | |
(function() { | |
var origOpen = XMLHttpRequest.prototype.open; | |
XMLHttpRequest.prototype.open = function() { | |
this.addEventListener('load', function() { | |
var response = JSON.parse(this.responseText); | |
for (var i = 0; i < response['motion']['data'].length; i++) { | |
if (response['motion']['data'][i][1][0] >= limit) { | |
console.log('motion over threshold'); | |
audio.play(); | |
} | |
} | |
}); | |
origOpen.apply(this, arguments); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment