Skip to content

Commit

Permalink
fixed the scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Yakhnin authored and Alex Yakhnin committed Dec 20, 2016
1 parent 06af7c5 commit 6499f08
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions motiondetector.js
Expand Up @@ -27,7 +27,62 @@ Module.register('motiondetector',{

var _this = self;

if (notification === "DOM_OBJECTS_CREATED") {
// if (notification === "DOM_OBJECTS_CREATED") {
// var video = document.createElement('video');
// var cameraPreview = document.createElement("div");
// cameraPreview.id = "cameraPreview";
// cameraPreview.style = "visibility:hidden;"
// cameraPreview.appendChild(video);

// var canvas = document.createElement('canvas');

// DiffCamEngine.init({
// video: video,
// motionCanvas: canvas,
// initSuccessCallback: function () {
// DiffCamEngine.start();
// },
// initErrorCallback: function () {
// console.log('error init cam engine');
// },
// captureCallback: _this.onCapture
// });
// }
},

onCapture: function (payload) {
var _this = this;
var score = payload.score;
if (score > 20) {
_this.lastTimeMotionDetected = new Date();
if (_this.poweredOff) {
_this.poweredOff = false;
_this.sendSocketNotification('MOTION_DETECTED', _this.config);
}
}
else {
var currentDate = new Date();
var time = currentDate.getTime() - _this.lastTimeMotionDetected;
if ((time > _this.config.timeout) && (!_this.poweredOff)) {
_this.sendSocketNotification('DEACTIVATE_MONITOR', _this.config);
_this.sendNotification('DEACTIVATE_MONITOR', _this.config);
_this.poweredOff = true;
}
}
console.log('score:' + score);
},

start: function() {
Log.info('Starting module: ' + this.name);

this.lastTimeMotionDetected = new Date();

var _this = this;

// make sure that the monitor is on when starting
_this.sendSocketNotification('MOTION_DETECTED', _this.config);


var video = document.createElement('video');
var cameraPreview = document.createElement("div");
cameraPreview.id = "cameraPreview";
Expand All @@ -45,7 +100,7 @@ Module.register('motiondetector',{
initErrorCallback: function () {
console.log('error init cam engine');
},
captureCallback: function (payload) {
captureCallback: function(payload){
var score = payload.score;
if (score > 20) {
_this.lastTimeMotionDetected = new Date();
Expand All @@ -66,20 +121,6 @@ Module.register('motiondetector',{
console.log('score:' + score);
}
});
}
},

start: function() {
Log.info('Starting module: ' + this.name);

this.lastTimeMotionDetected = new Date();

var _this = this;

// make sure that the monitor is on when starting
_this.sendSocketNotification('MOTION_DETECTED', _this.config);
var width = 640;
var height = 480;

},

Expand Down

0 comments on commit 6499f08

Please sign in to comment.