forked from infusion/jQuery-webcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.webcam.js
93 lines (75 loc) · 2.19 KB
/
jquery.webcam.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
/**
* jQuery webcam
* Copyright (c) 2010, Robert Eisele ([email protected])
* Dual licensed under the MIT or GPL Version 2 licenses.
* Date: 09/12/2010
*
* @author Robert Eisele
* @version 1.0
*
* @see http://www.xarg.org/project/jquery-webcam-plugin/
**/
(function ($) {
var webcam = {
extern: null, // external select token to support jQuery dialogs
append: true, // append object instead of overwriting
width: 320,
height: 240,
mode: "callback", // callback | save | stream
swffile: "jscam.swf",
quality: 85,
debug: function () {},
onCapture: function () {},
onTick: function () {},
onSave: function () {},
onLoad: function () {}
};
window.webcam = webcam;
$.fn.webcam = function(options) {
if (typeof options === "object") {
for (var ndx in webcam) {
if (options[ndx] !== undefined) {
webcam[ndx] = options[ndx];
}
}
}
var source = '<object id="XwebcamXobjectX" type="application/x-shockwave-flash" data="'+webcam.swffile+'" width="'+webcam.width+'" height="'+webcam.height+'"><param name="movie" value="'+webcam.swffile+'" /><param name="FlashVars" value="mode='+webcam.mode+'&quality='+webcam.quality+'" /><param name="allowScriptAccess" value="always" /></object>';
if (null !== webcam.extern) {
$(webcam.extern)[webcam.append ? "append" : "html"](source);
} else {
this[webcam.append ? "append" : "html"](source);
}
(_register = function(run) {
var cam = document.getElementById('XwebcamXobjectX');
if (cam.capture !== undefined) {
/* Simple callback methods are not allowed :-/ */
webcam.capture = function(x) {
try {
return cam.capture(x);
} catch(e) {}
}
webcam.save = function(x) {
try {
return cam.save(x);
} catch(e) {}
}
webcam.setCamera = function(x) {
try {
return cam.setCamera(x);
} catch(e) {}
}
webcam.getCameraList = function() {
try {
return cam.getCameraList();
} catch(e) {}
}
webcam.onLoad();
} else if (0 == run) {
webcam.debug("error", "Flash movie not yet registered!");
} else {
/* Flash interface not ready yet */
window.setTimeout(_register, 1000 * (4 - run), run - 1);
}
})(3);
}
})(jQuery);