-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWebcamTest.js
102 lines (75 loc) · 3.11 KB
/
WebcamTest.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
90
91
92
93
94
95
96
97
98
99
100
101
102
var webcam = null;
//Assuming using jQuery, lets wait until the document has finished loading.
$(document).ready(function () {
//This reaches out to KioskSimple and requests API initialization
try{
window.external.KioskSimpleAPIInit();
}
catch (err) {
//If we got here then we are not running within KioskSimple, lets disable all buttons and output to user
$("#btnEnableWebcam").prop('disabled', true);
$("#btnDisableWebcam").prop('disabled', true);
outputActionResult("Initialization", "Something went wrong intitializing KioskSimple. Error:" + err)
return;
}
//If we got this far, we are successfully running within KioskSimple's local code domain
if (K()) {
// hook up handler for snapshot async action
webcam = KioskSimple.Plugins.GetPlugin("Webcam");
if (webcam != null) {
webcam.OnSnapshot = OnSnapshot;
webcam.OnEnabled = OnEnabled;
webcam.OnDisabled = OnDisabled;
webcamOnError = OnError;
setupUIButtons();
outputActionResult("Initialization", "Kiosk Simple loaded.")
}
}
});
//Not 100% needed but a nice shortcut to determine if KS is preset.
function K() {
return !(typeof KioskSimple === 'undefined')
}
function OnDisabled() {
outputActionResult("Disabled", "Disabled")
}
function OnEnabled() {
outputActionResult("Enabled", "Enabled")
}
function OnError(err) {
outputActionResult("Error", err)
}
//Plugin Snapshot handler, this will fire when the TakeSnapshotAsyn method of the webcam is executed.
function OnSnapshot(path, filename) {
outputActionResult("OnSnapshot","Path:"+path+",filename:"+filename )
}
function setupUIButtons() {
$("#btnEnableWebcam").click(function () {
KioskSimple.Plugins.GetPlugin('_devices').EnableAllDevicesByCategory("Camera");
});
$("#btnDisableWebcam").click(function () {
KioskSimple.Plugins.GetPlugin('_devices').DisableAllDevicesByCategory("Camera");
});
$("#btnTakeSnapshot").click(function () {
if (webcam.Enabled()) {
outputActionResult("Taking", {})
var result = webcam.TakeSnapshot("myfileid");
outputActionResult("Snapshot taken", result)
}
});
$("#btnTakeSnapshotAsync").click(function () {
if (webcam.Enabled()) {
webcam.TakeSnapshotAsync("myfileidasync");
//OnSnapshot handler will execute upon completion of this action
}
});
$("#btnIsEnabled").click(function () {
var result = webcam.Enabled();
outputActionResult("IsEnabled", result)
//OnSnapshot handler will execute upon completion of this action
});
}
function outputActionResult(actionName, data) {
var output = "<a href='#' class='list-group-item'><h4 class='list-group-item-heading'>Action Result: " + actionName + "</h4><p class='list-group-item-text'>" + data + "</p></a>";
$(".list-group").append(output);
}