-
Notifications
You must be signed in to change notification settings - Fork 14
/
jquery.webcam.as3.js
83 lines (75 loc) · 3.58 KB
/
jquery.webcam.as3.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
/**
* jQuery AS3 Webcam
*
* Copyright (c) 2012, Sergey Shilko (sergey.shilko@gmail.com)
*
* @author Sergey Shilko
* @see https://github.com/sshilko/jQuery-AS3-Webcam
*
**/
try {
$(document).ready( function() {
var webcam = {
previewWidth: 320,
previewHeight: 240,
resolutionWidth: 320,
resolutionHeight: 240,
videoDeblocking: 0,
videoSmoothing: 0,
/**
* Determine if we need to stretch or scale the captured stream
*
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#scaleMode
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/StageScaleMode.html
*/
StageScaleMode: 'exactFit', //
/**
* Aligns video output on stage
*
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/StageAlign.html
* @see http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Stage.html#align
* Empty value defaults to "centered" option
*/
StageAlign: '',
cameraId: 'AS3webcamObject',
callTarget: 'webcam',
bgcolor: '#000000',
isSwfReady: false,
isCameraEnabled: false,
swffile: "sAS3Cam.swf",
cameraEnabled: function () { },
cameraDisabled: function () { },
noCameraFound: function () { },
isClientReady: function () { return true; },
cameraReady: function () { },
cameraConnected: function () {
this.isSwfReady = true;
var cam = document.getElementById(this.cameraId);
this.save = function() { try { return cam.save(); } catch(e) { this.swfApiFail(e); } }
this.setCamera = function(i) { try { return cam.setCamera(i); } catch(e) { this.swfApiFail(e); } }
this.getCameraList = function() { try { return cam.getCameraList(); } catch(e) { this.swfApiFail(e); } }
this.getResolution = function() { try { return cam.getResolution(); } catch(e) { this.swfApiFail(e); } },
this.cameraReady();
},
init: function(container, options) {
if (typeof options === "object") {
for (var ndx in webcam) {
if (options[ndx] !== undefined) {
webcam[ndx] = options[ndx];
}
}
}
//Security tip:
//XSS Prevention: 'allowScriptAccess' change to 'sameDomain' (if swf & page on same domain)
//see @http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps.html
var source = '<object id="'+this.cameraId+'" type="application/x-shockwave-flash" data="'+webcam.swffile+'" width="'+webcam.previewWidth+'" height="'+webcam.previewHeight+'"><param name="movie" value="'+webcam.swffile+'" /><param name="FlashVars" value="callTarget='+this.callTarget+'&resolutionWidth='+webcam.resolutionWidth+'&resolutionHeight='+webcam.resolutionHeight+'&smoothing='+webcam.videoSmoothing+'&deblocking='+webcam.videoDeblocking+'&StageScaleMode='+webcam.StageScaleMode+'&StageAlign='+webcam.StageAlign+'" /><param name="allowScriptAccess" value="always" /><param name="bgcolor" value="'+webcam.bgcolor+'" /></object>';
$(container).html(source);
return this;
},
swfApiFail: function (e) { },
debug: function () { }
};
window.webcam = webcam;
$.fn.webcam = function(options) { return webcam.init(this, options); };
});
} catch (e) {}