-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathFileAPI.Flash.Camera.js
More file actions
102 lines (84 loc) · 2.21 KB
/
FileAPI.Flash.Camera.js
File metadata and controls
102 lines (84 loc) · 2.21 KB
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
/**
* FileAPI fallback to Flash
*
* @flash-developer "Vladimir Demidov" <v.demidov@corp.mail.ru>
*/
/*global window, FileAPI */
(function (window, jQuery, api) {
"use strict";
var
_each = api.each
, _extend = api.extend
, _cameraQueue = []
, Flash = api.Flash
, _wrap = Flash.wrap
, _unwrap = Flash.unwrap
;
if( api.support.flash && (api.media && !api.support.media) ){
api.extend(Flash, {
patchCamera: function (){
api.Camera.fallback = function (el, options, callback){
var camId = api.uid();
api.log('FlashAPI.Camera.publish: ' + camId);
Flash.publish(el, camId, _extend(options, {
camera: true,
onEvent: _wrap(function _(evt){
if( evt.type === 'camera' ){
_unwrap(_);
if( evt.error ){
api.log('FlashAPI.Camera.publish.error: ' + evt.error);
callback(evt.error);
} else {
api.log('FlashAPI.Camera.publish.success: ' + camId);
callback(null);
}
}
})
}));
};
// Run
_each(_cameraQueue, function (args){
api.Camera.fallback.apply(api.Camera, args);
});
_cameraQueue = [];
// FileAPI.Camera:proto
_extend(api.Camera.prototype, {
_id: function (){
return this.video.id;
},
start: function (callback){
var _this = this;
Flash.cmd(this._id(), 'camera.on', {
callback: _wrap(function _(evt){
_unwrap(_);
if( evt.error ){
api.log('FlashAPI.camera.on.error: ' + evt.error);
callback(evt.error, _this);
} else {
api.log('FlashAPI.camera.on.success: ' + _this._id());
_this._active = true;
callback(null, _this);
}
})
});
},
stop: function (){
this._active = false;
Flash.cmd(this._id(), 'camera.off');
},
shot: function (){
api.log('FlashAPI.Camera.shot:', this._id());
var shot = Flash.cmd(this._id(), 'shot', {});
shot.type = 'image/png';
shot.flashId = this._id();
shot.isShot = true;
return new api.Camera.Shot(shot);
}
});
}
});
api.Camera.fallback = function (){
_cameraQueue.push(arguments);
};
}
})(window, window.jQuery, FileAPI);