forked from sshilko/jQuery-AS3-Webcam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webcam.js
73 lines (61 loc) · 2.42 KB
/
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
/* JS-Webcam | https://github.com/fatlinesofcode/JS-Webcam */
(function(wrapperName) {
var o = window[wrapperName] = {};
o.settings = {
wrapper : wrapperName, // reference only - see %%NAME%%
element : "webcam",
/* some defaults handled in flash (save a few bytes minified)
bandwidth : 0,
quality : 100,
framerate : 14,
mirror : false,
deblocking: 0,
smoothing : false,
*/
bgcolor : "#000000",
wmode : "opaque"
};
o.onError = function() { };
o.onReady = function() { };
o.documentReady = false;
var preLoad = window.onload;
window.onload = function() {
if(typeof preLoad == 'function') preLoad();
o.documentReady = true;
};
o.embed = function(src, width, height, settings) {
if(settings != undefined)
this.applySettings(settings);
this.settings.windowWidth = width;
this.settings.windowHeight = height;
swfobject.embedSWF(src, this.settings.element, width, height, "11.1.0", null, this.settings,
{ wmode: this.settings.wmode, bgcolor: this.settings.bgcolor }, null,
function(e) { if(!e.success) window[wrapperName].onError({flag: "NOFLASHPLAYER"}); }
);
};
o.isClientReady = function() {
return !!this.documentReady;
};
o.applySettings = function(obj) {
if(typeof obj == 'object')
this.settings = merge(this.settings, obj);
};
o.swfReady = function() {
var el = document.getElementById(this.settings.element);
this.play = function() { try { return el.play(); } catch (e) { return false; } };
this.pause = function() { try { return el.pause(); } catch (e) { return false; } };
this.save = function(resMode) { try { return el.save(resMode); } catch (e) { return false; } };
this.setCamera = function(i) { try { return el.setCamera(i); } catch (e) { return false; } };
this.getCameras = function() { try { return el.getCameras(); } catch (e) { return false; } };
this.chooseCamera = function() { try { return el.chooseCamera(); } catch (e) { return false; } };
this.getResolution = function() { try { return el.getResolution(); } catch (e) { return false; } };
this.onReady();
};
function merge(baseObj, newObj) {
for(var key in newObj)
if(newObj.hasOwnProperty(key))
baseObj[key] = newObj[key];
return baseObj;
};
})("webcam"); // %%NAME%% - set wrapper name in anonymous function call
// so it can be changed after being minified if required.