-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
89 lines (75 loc) · 1.76 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var scale = 10; // capture resolution over motion resolution
var isActivated = false;
var newMotion = true;
var videoVisible = false;
let sounds = ["happy-halloween",
"no",
"godzilla",
"horse",
"wheres-mommy",
"make_america_great",
"be-gone",
"laugh",
"leave-now",
"leave-now-2",
"who-is-knocking",
"who-is-knocking-2",
"who-is-knocking-3",
"bored_with_winning"];
function initSuccess() {
DiffCamEngine.start();
}
function setAction(s) {
document.getElementById("action").innerHTML = s;
}
function initError() {
alert('Something went wrong.');
}
function startComplete() {
isActivated = true;
setAction("Activated")
}
function capture(payload) {
if (!newMotion ||!payload.hasMotion) {
return;
}
setAction("new motion");
if (newMotion) {
newMotion = false;
let s = getSound();
setAction("playing: " + s);
play(s);
setTimeout(() => {
newMotion = true;
setAction("timeout done, watching")
}, 8000)
}
}
function play(audioId) {
document.getElementById(audioId).play();
// $('#audio-' + audioId)[0].play();
}
function getSound() {
min = Math.ceil(0);
max = Math.floor(sounds.length);
return sounds[Math.floor(Math.random() * (max - min)) + min];
}
DiffCamEngine.init({
video: document.getElementById('video'),
captureIntervalTime: 50,
initSuccessCallback: initSuccess,
initErrorCallback: initError,
startCompleteCallback: startComplete,
captureCallback: capture,
pixelDiffThreshold: 16,
scoreThreshold: 8
});
function toggleVideo() {
if (videoVisible) {
document.getElementById('video').style.display = "none";
} else {
document.getElementById('video').style.display = "block";
}
videoVisible = !videoVisible;
}
console.log("log pls");