@digipair/skill-webcam 0.93.0-0 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +69 -0
- package/index.d.ts +1 -0
- package/index.esm.js +44 -0
- package/{dist → libs/skill-webcam}/src/index.d.ts +0 -1
- package/{dist → libs/skill-webcam}/src/lib/skill-webcam.d.ts +0 -1
- package/package.json +6 -20
- package/README.md +0 -7
- package/dist/index.cjs.js +0 -1146
- package/dist/index.esm.js +0 -1143
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lib/skill-webcam.d.ts.map +0 -1
- package/dist/src/lib/skill-webcam.spec.d.ts +0 -2
- package/dist/src/lib/skill-webcam.spec.d.ts.map +0 -1
- /package/{dist/index.d.ts → index.cjs.d.ts} +0 -0
- /package/{dist/schema.fr.json → schema.fr.json} +0 -0
- /package/{dist/schema.json → schema.json} +0 -0
package/dist/index.cjs.js
DELETED
|
@@ -1,1146 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var require$$0 = require('os');
|
|
4
|
-
var require$$0$1 = require('child_process');
|
|
5
|
-
var require$$1 = require('fs');
|
|
6
|
-
var require$$3 = require('path');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* JS utils
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
function _type_of$1(obj) {
|
|
14
|
-
"@swc/helpers - typeof";
|
|
15
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
16
|
-
}
|
|
17
|
-
var Utils$4 = {
|
|
18
|
-
//Highly used as an inheritance
|
|
19
|
-
setDefaults: function setDefaults(object, defaults) {
|
|
20
|
-
var defaults = (typeof defaults === "undefined" ? "undefined" : _type_of$1(defaults)) === "object" ? defaults : {};
|
|
21
|
-
var object = (typeof object === "undefined" ? "undefined" : _type_of$1(object)) === "object" ? object : {};
|
|
22
|
-
if (object === defaults) {
|
|
23
|
-
return object;
|
|
24
|
-
}
|
|
25
|
-
for(var defaultName in defaults){
|
|
26
|
-
var defaultVal = defaults[defaultName];
|
|
27
|
-
var objectVal = object[defaultName];
|
|
28
|
-
if ((typeof defaultVal === "undefined" ? "undefined" : _type_of$1(defaultVal)) === "object") {
|
|
29
|
-
object[defaultName] = Utils$4.setDefaults(objectVal, defaultVal);
|
|
30
|
-
} else if (typeof objectVal === "undefined") {
|
|
31
|
-
object[defaultName] = defaults[defaultName];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return object;
|
|
35
|
-
},
|
|
36
|
-
//Node-webcam escape string
|
|
37
|
-
escape: function escape(cmd) {
|
|
38
|
-
return '"' + cmd.replace(/(["\s'$`\\()])/g, '\\$1') + '"';
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var Utils_1 = Utils$4;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* based on mrdoob's named like Node's EventEmitter
|
|
45
|
-
* Used primarily as an inheritance via apply
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
var EventDispatcher$1 = function EventDispatcher() {};
|
|
50
|
-
EventDispatcher$1.prototype = {
|
|
51
|
-
constructor: EventDispatcher$1,
|
|
52
|
-
apply: function apply(object) {
|
|
53
|
-
object.on = EventDispatcher$1.prototype.on;
|
|
54
|
-
object.hasListener = EventDispatcher$1.prototype.hasListener;
|
|
55
|
-
object.removeListener = EventDispatcher$1.prototype.removeListener;
|
|
56
|
-
object.dispatch = EventDispatcher$1.prototype.dispatch;
|
|
57
|
-
return object;
|
|
58
|
-
},
|
|
59
|
-
on: function on(type, listener) {
|
|
60
|
-
if (this._listeners === undefined) {
|
|
61
|
-
this._listeners = {};
|
|
62
|
-
}
|
|
63
|
-
var listeners = this._listeners;
|
|
64
|
-
if (listeners[type] === undefined) {
|
|
65
|
-
listeners[type] = [];
|
|
66
|
-
}
|
|
67
|
-
if (listeners[type].indexOf(listener) === -1) {
|
|
68
|
-
listeners[type].push(listener);
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
hasListener: function hasListener(type, listener) {
|
|
72
|
-
if (this._listeners === undefined) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
var listeners = this._listeners;
|
|
76
|
-
if (listeners[type] !== undefined && listeners[type].indexOf(listener) !== -1) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
},
|
|
81
|
-
removeListener: function removeListener(type, listener) {
|
|
82
|
-
if (this._listeners === undefined) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
var listeners = this._listeners;
|
|
86
|
-
var listenerArray = listeners[type];
|
|
87
|
-
if (listenerArray !== undefined) {
|
|
88
|
-
var index = listenerArray.indexOf(listener);
|
|
89
|
-
if (index !== -1) {
|
|
90
|
-
listenerArray.splice(index, 1);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
dispatch: function dispatch(event) {
|
|
95
|
-
if (this._listeners === undefined) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
var listeners = this._listeners;
|
|
99
|
-
var listenerArray = listeners[event.type];
|
|
100
|
-
if (listenerArray !== undefined) {
|
|
101
|
-
event.target = this;
|
|
102
|
-
var array = [];
|
|
103
|
-
var length = listenerArray.length;
|
|
104
|
-
for(var i = 0; i < length; i++){
|
|
105
|
-
array[i] = listenerArray[i];
|
|
106
|
-
}
|
|
107
|
-
for(var i = 0; i < length; i++){
|
|
108
|
-
array[i].call(this, event);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var EventDispatcher_1 = EventDispatcher$1;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Shared camera utils
|
|
117
|
-
*
|
|
118
|
-
*/
|
|
119
|
-
var OS$1 = require$$0;
|
|
120
|
-
var FS$1 = require$$1;
|
|
121
|
-
var CameraUtils$1 = {
|
|
122
|
-
getCameras: function getCameras(callback) {
|
|
123
|
-
switch(CameraUtils$1.Platform){
|
|
124
|
-
case "linux":
|
|
125
|
-
case "darwin":
|
|
126
|
-
return CameraUtils$1.getLinuxCameras(callback);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
//Linux cameras read /dev dir
|
|
130
|
-
getLinuxCameras: function getLinuxCameras(callback) {
|
|
131
|
-
var reg = /^video/i;
|
|
132
|
-
var dir = "/dev/";
|
|
133
|
-
FS$1.readdir(dir, function(err, data) {
|
|
134
|
-
if (err) {
|
|
135
|
-
throw err;
|
|
136
|
-
}
|
|
137
|
-
var cams = [];
|
|
138
|
-
var dl = data.length;
|
|
139
|
-
for(var i = 0; i < dl; i++){
|
|
140
|
-
var camPath = data[i];
|
|
141
|
-
if (camPath.match(reg)) {
|
|
142
|
-
cams.push(dir + camPath);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
callback && callback(cams);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
CameraUtils$1.Platform = OS$1.platform();
|
|
150
|
-
var CameraUtils_1 = CameraUtils$1;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Shot struct
|
|
154
|
-
*
|
|
155
|
-
* @class Shot
|
|
156
|
-
* @constructor
|
|
157
|
-
* @param {String|null} location
|
|
158
|
-
* @param {Buffer|null} data
|
|
159
|
-
*
|
|
160
|
-
*/
|
|
161
|
-
function Shot$2(location, data) {
|
|
162
|
-
var scope = this;
|
|
163
|
-
scope.location = location;
|
|
164
|
-
scope.data = data;
|
|
165
|
-
}
|
|
166
|
-
Shot$2.prototype = {
|
|
167
|
-
constructor: Shot$2,
|
|
168
|
-
/**
|
|
169
|
-
* Shot location
|
|
170
|
-
*
|
|
171
|
-
* @property location
|
|
172
|
-
*
|
|
173
|
-
* @type {String|null}
|
|
174
|
-
*
|
|
175
|
-
*/ location: null,
|
|
176
|
-
/**
|
|
177
|
-
* Shot data or buffer
|
|
178
|
-
*
|
|
179
|
-
* @property data
|
|
180
|
-
*
|
|
181
|
-
* @type {Buffer|null}
|
|
182
|
-
*
|
|
183
|
-
*/ data: null
|
|
184
|
-
};
|
|
185
|
-
// Export
|
|
186
|
-
var Shot_1 = Shot$2;
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* Webcam base class
|
|
191
|
-
*
|
|
192
|
-
* @class Webcam
|
|
193
|
-
* @constructor
|
|
194
|
-
* @param {Object} options composition options
|
|
195
|
-
* used to set
|
|
196
|
-
*
|
|
197
|
-
*/
|
|
198
|
-
var CHILD_PROCESS$2 = require$$0$1;
|
|
199
|
-
var EXEC$2 = CHILD_PROCESS$2.exec;
|
|
200
|
-
var FS = require$$1;
|
|
201
|
-
var Utils$3 = Utils_1;
|
|
202
|
-
var EventDispatcher = EventDispatcher_1;
|
|
203
|
-
var CameraUtils = CameraUtils_1;
|
|
204
|
-
var Shot$1 = Shot_1;
|
|
205
|
-
/*
|
|
206
|
-
* Main class
|
|
207
|
-
*
|
|
208
|
-
*/ function Webcam$3(options) {
|
|
209
|
-
var scope = this;
|
|
210
|
-
scope.shots = [];
|
|
211
|
-
scope.opts = Utils$3.setDefaults(options, Webcam$3.Defaults);
|
|
212
|
-
}
|
|
213
|
-
Webcam$3.prototype = {
|
|
214
|
-
constructor: Webcam$3,
|
|
215
|
-
/**
|
|
216
|
-
* Main opts from construction
|
|
217
|
-
*
|
|
218
|
-
* @property opts
|
|
219
|
-
* @type {Object}
|
|
220
|
-
*
|
|
221
|
-
*/ opts: {},
|
|
222
|
-
/**
|
|
223
|
-
* Array of Shot objects
|
|
224
|
-
*
|
|
225
|
-
* @property shots
|
|
226
|
-
* @type {Shots[]}
|
|
227
|
-
*
|
|
228
|
-
*/ shots: [],
|
|
229
|
-
/**
|
|
230
|
-
* Basic camera instance clone
|
|
231
|
-
*
|
|
232
|
-
* @method clone
|
|
233
|
-
*
|
|
234
|
-
* @return Webcam
|
|
235
|
-
*
|
|
236
|
-
*/ clone: function clone() {
|
|
237
|
-
return new this.constructor(this.opts);
|
|
238
|
-
},
|
|
239
|
-
/**
|
|
240
|
-
* Clear shot and camera memory data
|
|
241
|
-
*
|
|
242
|
-
* @method clear
|
|
243
|
-
*
|
|
244
|
-
*/ clear: function clear() {
|
|
245
|
-
var scope = this;
|
|
246
|
-
scope.shots = [];
|
|
247
|
-
},
|
|
248
|
-
/**
|
|
249
|
-
* List available cameras
|
|
250
|
-
*
|
|
251
|
-
* @method list
|
|
252
|
-
*
|
|
253
|
-
* @param {Function} callback returns a list of cameras
|
|
254
|
-
*
|
|
255
|
-
*/ list: CameraUtils.getCameras,
|
|
256
|
-
/**
|
|
257
|
-
* List available camera controls
|
|
258
|
-
*
|
|
259
|
-
* @method listControls
|
|
260
|
-
*
|
|
261
|
-
* @param {Function(Array<CameraControl>)} callback Function that receives
|
|
262
|
-
* camera controls
|
|
263
|
-
*
|
|
264
|
-
* @param {String} stdoutOverride fswebcam command output override (for
|
|
265
|
-
* testing purposes)
|
|
266
|
-
*
|
|
267
|
-
*/ listControls: function listControls(callback, stdoutOverride) {
|
|
268
|
-
var scope = this;
|
|
269
|
-
var sh;
|
|
270
|
-
try {
|
|
271
|
-
sh = scope.getListControlsSh();
|
|
272
|
-
} catch (_) {
|
|
273
|
-
callback && callback([]);
|
|
274
|
-
}
|
|
275
|
-
//Shell execute
|
|
276
|
-
var shArgs = {
|
|
277
|
-
maxBuffer: 1024 * 10000
|
|
278
|
-
};
|
|
279
|
-
EXEC$2(sh, shArgs, function(err, out, derr) {
|
|
280
|
-
if (err) {
|
|
281
|
-
return callback && callback(err);
|
|
282
|
-
}
|
|
283
|
-
if (scope.opts.verbose && derr) {
|
|
284
|
-
console.log(derr);
|
|
285
|
-
}
|
|
286
|
-
scope.parseListControls(stdoutOverride || out + derr, callback);
|
|
287
|
-
});
|
|
288
|
-
},
|
|
289
|
-
/**
|
|
290
|
-
* Has camera
|
|
291
|
-
*
|
|
292
|
-
* @method hasCamera
|
|
293
|
-
*
|
|
294
|
-
* @param {Function} callback returns a Boolean
|
|
295
|
-
*
|
|
296
|
-
*/ hasCamera: function hasCamera(callback) {
|
|
297
|
-
var scope = this;
|
|
298
|
-
scope.list(function(list) {
|
|
299
|
-
callback && callback(!!list.length);
|
|
300
|
-
});
|
|
301
|
-
},
|
|
302
|
-
/**
|
|
303
|
-
* Capture shot
|
|
304
|
-
*
|
|
305
|
-
* @method capture
|
|
306
|
-
*
|
|
307
|
-
* @param {String} location
|
|
308
|
-
* @param {Function} callback
|
|
309
|
-
* @return void
|
|
310
|
-
*
|
|
311
|
-
*/ capture: function capture(location, callback) {
|
|
312
|
-
var scope = this;
|
|
313
|
-
if (location === null && scope.opts.callbackReturn === Webcam$3.CallbackReturnTypes.location) {
|
|
314
|
-
console.warn("If capturing image in memory\
|
|
315
|
-
your callback return type cannot be the location");
|
|
316
|
-
scope.opts.callbackReturn = "buffer";
|
|
317
|
-
}
|
|
318
|
-
var fileType = Webcam$3.OutputTypes[scope.opts.output];
|
|
319
|
-
var location = location === null ? null : location.match(/\..*$/) ? location : location + "." + fileType;
|
|
320
|
-
//Shell statement grab
|
|
321
|
-
var sh = scope.generateSh(location);
|
|
322
|
-
if (scope.opts.verbose) {
|
|
323
|
-
console.log(sh);
|
|
324
|
-
}
|
|
325
|
-
//Shell execute
|
|
326
|
-
var shArgs = {
|
|
327
|
-
maxBuffer: 1024 * 10000
|
|
328
|
-
};
|
|
329
|
-
EXEC$2(sh, shArgs, function(err, out, derr) {
|
|
330
|
-
if (err) {
|
|
331
|
-
return callback && callback(err);
|
|
332
|
-
}
|
|
333
|
-
if (scope.opts.verbose && derr) {
|
|
334
|
-
console.log(derr);
|
|
335
|
-
}
|
|
336
|
-
//Run validation overrides
|
|
337
|
-
var validationErrors;
|
|
338
|
-
if (validationErrors = scope.runCaptureValidations(derr)) {
|
|
339
|
-
return callback && callback(validationErrors);
|
|
340
|
-
}
|
|
341
|
-
//Callbacks
|
|
342
|
-
var shot = scope.createShot(location, derr);
|
|
343
|
-
if (scope.opts.saveShots) {
|
|
344
|
-
scope.shots.push(shot);
|
|
345
|
-
}
|
|
346
|
-
scope.dispatch({
|
|
347
|
-
type: "capture",
|
|
348
|
-
shot: shot
|
|
349
|
-
});
|
|
350
|
-
callback && scope.handleCallbackReturnType(callback, shot);
|
|
351
|
-
});
|
|
352
|
-
},
|
|
353
|
-
/**
|
|
354
|
-
* Generate cli command string
|
|
355
|
-
*
|
|
356
|
-
* @method generateSh
|
|
357
|
-
*
|
|
358
|
-
* @return {String}
|
|
359
|
-
*
|
|
360
|
-
*/ generateSh: function generateSh(location) {
|
|
361
|
-
return "";
|
|
362
|
-
},
|
|
363
|
-
/**
|
|
364
|
-
* Create a shot overider
|
|
365
|
-
*
|
|
366
|
-
* @method createShot
|
|
367
|
-
*
|
|
368
|
-
* @return {String}
|
|
369
|
-
*
|
|
370
|
-
*/ createShot: function createShot(location, data) {
|
|
371
|
-
return new Shot$1(location, data);
|
|
372
|
-
},
|
|
373
|
-
/**
|
|
374
|
-
* Get shot instances from cache index
|
|
375
|
-
*
|
|
376
|
-
* @method getShot
|
|
377
|
-
*
|
|
378
|
-
* @param {Number} shot Index of shots called
|
|
379
|
-
* @param {Function} callback Returns a call from FS.readFile data
|
|
380
|
-
*
|
|
381
|
-
* @throws Error if shot at index not found
|
|
382
|
-
*
|
|
383
|
-
* @return {Boolean}
|
|
384
|
-
*
|
|
385
|
-
*/ getShot: function getShot(index, callback) {
|
|
386
|
-
var scope = this;
|
|
387
|
-
var shot = scope.shots[index | 0];
|
|
388
|
-
if (!shot) {
|
|
389
|
-
throw new Error("Shot number " + index + " not found");
|
|
390
|
-
}
|
|
391
|
-
return shot;
|
|
392
|
-
},
|
|
393
|
-
/**
|
|
394
|
-
* Get last shot taken image data
|
|
395
|
-
*
|
|
396
|
-
* @method getLastShot
|
|
397
|
-
*
|
|
398
|
-
* @throws Error Camera has no last shot
|
|
399
|
-
*
|
|
400
|
-
* @return {Shot}
|
|
401
|
-
*
|
|
402
|
-
*/ getLastShot: function getLastShot() {
|
|
403
|
-
var scope = this;
|
|
404
|
-
if (!scope.shots.length) {
|
|
405
|
-
throw new Error("Camera has no last shot");
|
|
406
|
-
}
|
|
407
|
-
return scope.getShot(scope.shots.length - 1);
|
|
408
|
-
},
|
|
409
|
-
/**
|
|
410
|
-
* Get shot buffer from location
|
|
411
|
-
* 0 indexed
|
|
412
|
-
*
|
|
413
|
-
* @method getShotBuffer
|
|
414
|
-
*
|
|
415
|
-
* @param {Number} shot Index of shots called
|
|
416
|
-
* @param {Function} callback Returns a call from FS.readFile data
|
|
417
|
-
*
|
|
418
|
-
* @return {Boolean}
|
|
419
|
-
*
|
|
420
|
-
*/ getShotBuffer: function getShotBuffer(shot, callback) {
|
|
421
|
-
var scope = this;
|
|
422
|
-
if (typeof shot === "number") {
|
|
423
|
-
shot = scope.getShot(shot);
|
|
424
|
-
}
|
|
425
|
-
if (shot.location) {
|
|
426
|
-
FS.readFile(shot.location, function(err, data) {
|
|
427
|
-
callback(err, data);
|
|
428
|
-
});
|
|
429
|
-
} else if (!shot.data) {
|
|
430
|
-
callback(new Error("Shot not valid"));
|
|
431
|
-
} else {
|
|
432
|
-
callback(null, shot.data);
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
/**
|
|
436
|
-
* Get last shot buffer taken image data
|
|
437
|
-
*
|
|
438
|
-
* @method getLastShotBuffer
|
|
439
|
-
*
|
|
440
|
-
* @throws Error Shot not found
|
|
441
|
-
*
|
|
442
|
-
* @return {Shot}
|
|
443
|
-
*
|
|
444
|
-
*/ getLastShotBuffer: function getLastShotBuffer(callback) {
|
|
445
|
-
var scope = this;
|
|
446
|
-
var shot = scope.getLastShot();
|
|
447
|
-
scope.getShotBuffer(shot, callback);
|
|
448
|
-
},
|
|
449
|
-
/**
|
|
450
|
-
* Get shot base64 as image
|
|
451
|
-
* if passed Number will return a base 64 in the callback
|
|
452
|
-
*
|
|
453
|
-
* @method getBase64
|
|
454
|
-
*
|
|
455
|
-
* @param {Number|FS.readFile} shot To be converted
|
|
456
|
-
* @param {Function( Error|null, Mixed )} callback Returns base64 string
|
|
457
|
-
*
|
|
458
|
-
* @return {String} Dont use
|
|
459
|
-
*
|
|
460
|
-
*/ getBase64: function getBase64(shot, callback) {
|
|
461
|
-
var scope = this;
|
|
462
|
-
scope.getShotBuffer(shot, function(err, data) {
|
|
463
|
-
if (err) {
|
|
464
|
-
callback(err);
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
var base64 = scope.getBase64FromBuffer(data);
|
|
468
|
-
callback(null, base64);
|
|
469
|
-
});
|
|
470
|
-
},
|
|
471
|
-
/**
|
|
472
|
-
* Get base64 string from bufer
|
|
473
|
-
*
|
|
474
|
-
* @method getBase64
|
|
475
|
-
*
|
|
476
|
-
* @param {Number|FS.readFile} shot To be converted
|
|
477
|
-
* @param {Function( Error|null, Mixed )} callback Returns base64 string
|
|
478
|
-
*
|
|
479
|
-
* @return {String} Dont use
|
|
480
|
-
*
|
|
481
|
-
*/ getBase64FromBuffer: function getBase64FromBuffer(shotBuffer) {
|
|
482
|
-
var scope = this;
|
|
483
|
-
var image = "data:image/" + scope.opts.output + ";base64," + Buffer.from(shotBuffer).toString("base64");
|
|
484
|
-
return image;
|
|
485
|
-
},
|
|
486
|
-
/**
|
|
487
|
-
* Get last shot taken base 64 string
|
|
488
|
-
*
|
|
489
|
-
* @method getLastShot64
|
|
490
|
-
*
|
|
491
|
-
* @param {Function} callback
|
|
492
|
-
*
|
|
493
|
-
*/ getLastShot64: function getLastShot64(callback) {
|
|
494
|
-
var scope = this;
|
|
495
|
-
if (!scope.shots.length) {
|
|
496
|
-
callback && callback(new Error("Camera has no last shot"));
|
|
497
|
-
}
|
|
498
|
-
scope.getBase64(scope.shots.length - 1, callback);
|
|
499
|
-
},
|
|
500
|
-
/**
|
|
501
|
-
* Get last shot taken image data
|
|
502
|
-
*
|
|
503
|
-
* @method handleCallbackReturnType
|
|
504
|
-
*
|
|
505
|
-
* @param {Function} callback
|
|
506
|
-
* @param {String} location
|
|
507
|
-
*
|
|
508
|
-
* @throws Error callbackReturn Type not valid
|
|
509
|
-
*
|
|
510
|
-
*/ handleCallbackReturnType: function handleCallbackReturnType(callback, shot) {
|
|
511
|
-
var scope = this;
|
|
512
|
-
switch(scope.opts.callbackReturn){
|
|
513
|
-
case Webcam$3.CallbackReturnTypes.location:
|
|
514
|
-
return callback(null, shot.location);
|
|
515
|
-
case Webcam$3.CallbackReturnTypes.buffer:
|
|
516
|
-
return scope.getShotBuffer(shot, callback);
|
|
517
|
-
case Webcam$3.CallbackReturnTypes.base64:
|
|
518
|
-
return scope.getBase64(shot, callback);
|
|
519
|
-
default:
|
|
520
|
-
return callback(new Error("Callback return type not valid " + scope.opts.callbackReturn));
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
/**
|
|
524
|
-
* Data validations for a command line output
|
|
525
|
-
*
|
|
526
|
-
* @override
|
|
527
|
-
*
|
|
528
|
-
* @param {String} Command exec output
|
|
529
|
-
*
|
|
530
|
-
* @return {Error|null}
|
|
531
|
-
*
|
|
532
|
-
*/ runCaptureValidations: function runCaptureValidations(data) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
EventDispatcher.prototype.apply(Webcam$3.prototype);
|
|
537
|
-
/**
|
|
538
|
-
* Base defaults for option construction
|
|
539
|
-
*
|
|
540
|
-
* @property Webcam.Defaults
|
|
541
|
-
*
|
|
542
|
-
* @type Object
|
|
543
|
-
* @static
|
|
544
|
-
*
|
|
545
|
-
*/ Webcam$3.Defaults = {
|
|
546
|
-
//Picture related
|
|
547
|
-
width: 1280,
|
|
548
|
-
height: 720,
|
|
549
|
-
quality: 100,
|
|
550
|
-
//Delay to take shot
|
|
551
|
-
delay: 0,
|
|
552
|
-
//Title of the saved picture
|
|
553
|
-
title: false,
|
|
554
|
-
//Subtitle of the saved picture
|
|
555
|
-
subtitle: false,
|
|
556
|
-
//Timestamp of the saved picture
|
|
557
|
-
timestamp: false,
|
|
558
|
-
//Save shots in memory
|
|
559
|
-
saveShots: true,
|
|
560
|
-
// [jpeg, png] support varies
|
|
561
|
-
// Webcam.OutputTypes
|
|
562
|
-
output: "jpeg",
|
|
563
|
-
//Which camera to use
|
|
564
|
-
//Use Webcam.list() for results
|
|
565
|
-
//false for default device
|
|
566
|
-
device: false,
|
|
567
|
-
// [location, buffer, base64]
|
|
568
|
-
// Webcam.CallbackReturnTypes
|
|
569
|
-
callbackReturn: "location",
|
|
570
|
-
//Logging
|
|
571
|
-
verbose: false
|
|
572
|
-
};
|
|
573
|
-
/**
|
|
574
|
-
* Global output types
|
|
575
|
-
* Various for platform
|
|
576
|
-
*
|
|
577
|
-
* @property Webcam.OutputTypes
|
|
578
|
-
*
|
|
579
|
-
* @type Object
|
|
580
|
-
* @static
|
|
581
|
-
*
|
|
582
|
-
*/ Webcam$3.OutputTypes = {
|
|
583
|
-
"jpeg": "jpg",
|
|
584
|
-
"png": "png",
|
|
585
|
-
"bmp": "bmp"
|
|
586
|
-
};
|
|
587
|
-
/**
|
|
588
|
-
* Global output types
|
|
589
|
-
* Various for platform
|
|
590
|
-
*
|
|
591
|
-
* @property Webcam.CallbackReturnTypes
|
|
592
|
-
*
|
|
593
|
-
* @type Object
|
|
594
|
-
* @static
|
|
595
|
-
*
|
|
596
|
-
*/ Webcam$3.CallbackReturnTypes = {
|
|
597
|
-
"default": "location",
|
|
598
|
-
"location": "location",
|
|
599
|
-
"buffer": "buffer",
|
|
600
|
-
"base64": "base64" // String ex : "data..."
|
|
601
|
-
};
|
|
602
|
-
//Export
|
|
603
|
-
var Webcam_1 = Webcam$3;
|
|
604
|
-
|
|
605
|
-
/**
|
|
606
|
-
* API for fswebcam
|
|
607
|
-
*
|
|
608
|
-
* @requires [ fswebcam ]
|
|
609
|
-
*
|
|
610
|
-
* @param Object options
|
|
611
|
-
*
|
|
612
|
-
*/
|
|
613
|
-
function _type_of(obj) {
|
|
614
|
-
"@swc/helpers - typeof";
|
|
615
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
616
|
-
}
|
|
617
|
-
var Webcam$2 = Webcam_1;
|
|
618
|
-
var Utils$2 = Utils_1;
|
|
619
|
-
var Shot = Shot_1;
|
|
620
|
-
//Main class
|
|
621
|
-
function FSWebcam$1(options) {
|
|
622
|
-
var scope = this;
|
|
623
|
-
scope.opts = Utils$2.setDefaults(options, FSWebcam$1.Defaults);
|
|
624
|
-
Webcam$2.call(scope, scope.opts);
|
|
625
|
-
if (scope.opts.output === "png" && scope.opts.quality > 9) {
|
|
626
|
-
scope.opts.quality = 9;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
FSWebcam$1.prototype = Object.create(Webcam$2.prototype);
|
|
630
|
-
FSWebcam$1.prototype.constructor = FSWebcam$1;
|
|
631
|
-
FSWebcam$1.prototype.bin = "fswebcam";
|
|
632
|
-
/**
|
|
633
|
-
* @override
|
|
634
|
-
*
|
|
635
|
-
* Create shot possibly from memory stdout
|
|
636
|
-
*
|
|
637
|
-
*/ FSWebcam$1.prototype.createShot = function(location, data) {
|
|
638
|
-
if (location === null) {
|
|
639
|
-
var data = Buffer.from(data);
|
|
640
|
-
}
|
|
641
|
-
return new Shot(location, data);
|
|
642
|
-
};
|
|
643
|
-
/**
|
|
644
|
-
* @override
|
|
645
|
-
*
|
|
646
|
-
* Generate shell statement
|
|
647
|
-
*
|
|
648
|
-
* @param String location
|
|
649
|
-
*
|
|
650
|
-
*/ FSWebcam$1.prototype.generateSh = function(location) {
|
|
651
|
-
var scope = this;
|
|
652
|
-
var resolution = " -r " + scope.opts.width + "x" + scope.opts.height;
|
|
653
|
-
// Adding frame rate
|
|
654
|
-
var frames = scope.opts.frames ? "-F " + scope.opts.frames : "";
|
|
655
|
-
var output = "--" + scope.opts.output;
|
|
656
|
-
var quality = scope.opts.quality;
|
|
657
|
-
var delay = scope.opts.delay ? "-D " + scope.opts.delay : "";
|
|
658
|
-
var title = scope.opts.title ? "--title " + scope.opts.title : "";
|
|
659
|
-
var subtitle = scope.opts.subtitle ? "--subtitle " + scope.opts.subtitle : "";
|
|
660
|
-
var timestamp = scope.opts.timestamp ? "--timestamp " + scope.opts.timestamp : "";
|
|
661
|
-
var device = scope.opts.device ? "-d " + scope.opts.device : "";
|
|
662
|
-
var grey = scope.opts.greyscale ? "--greyscale" : "";
|
|
663
|
-
var rotation = scope.opts.rotation ? "--rotate " + scope.opts.rotation : "";
|
|
664
|
-
var banner = !scope.opts.topBanner && !scope.opts.bottomBanner ? "--no-banner" : scope.opts.topBanner ? "--top-banner" : "--bottom-banner";
|
|
665
|
-
var skip = scope.opts.skip ? "--skip " + scope.opts.skip : "";
|
|
666
|
-
if (scope.opts.saturation) {
|
|
667
|
-
scope.opts.setValues.Saturation = scope.opts.saturation;
|
|
668
|
-
}
|
|
669
|
-
var setValues = scope.getControlSetString(scope.opts.setValues);
|
|
670
|
-
var verbose = scope.opts.verbose ? "" : " -q";
|
|
671
|
-
// Use memory if null location
|
|
672
|
-
var shellLocation = location === null ? "- -" : location;
|
|
673
|
-
var sh = scope.bin + " " + verbose + " " + resolution + " " + frames + " " + output + " " + quality + " " + delay + " " + title + " " + subtitle + " " + timestamp + " " + device + " " + grey + " " + rotation + " " + banner + " " + setValues + " " + skip + " " + shellLocation;
|
|
674
|
-
return sh;
|
|
675
|
-
};
|
|
676
|
-
/**
|
|
677
|
-
* Get control values string
|
|
678
|
-
*
|
|
679
|
-
* @param {Object} setValues
|
|
680
|
-
*
|
|
681
|
-
* @returns {String}
|
|
682
|
-
*
|
|
683
|
-
*/ FSWebcam$1.prototype.getControlSetString = function(setValues) {
|
|
684
|
-
var str = "";
|
|
685
|
-
if ((typeof setValues === "undefined" ? "undefined" : _type_of(setValues)) !== "object") {
|
|
686
|
-
return str;
|
|
687
|
-
}
|
|
688
|
-
for(var setName in setValues){
|
|
689
|
-
var val = setValues[setName];
|
|
690
|
-
if (!val) {
|
|
691
|
-
continue;
|
|
692
|
-
}
|
|
693
|
-
// Add a space to separate values if there are multiple control values being set
|
|
694
|
-
if (str.length > 0) {
|
|
695
|
-
str += " ";
|
|
696
|
-
}
|
|
697
|
-
str += "-s ".concat(setName, "=").concat(val);
|
|
698
|
-
}
|
|
699
|
-
return str;
|
|
700
|
-
};
|
|
701
|
-
/**
|
|
702
|
-
* Get shell statement to get the available camera controls
|
|
703
|
-
*
|
|
704
|
-
* @returns {String}
|
|
705
|
-
*
|
|
706
|
-
*/ FSWebcam$1.prototype.getListControlsSh = function() {
|
|
707
|
-
var scope = this;
|
|
708
|
-
var devSwitch = scope.opts.device ? " --device=" + scope.opts.device.trim() : "";
|
|
709
|
-
return scope.bin + devSwitch + " --list-controls";
|
|
710
|
-
};
|
|
711
|
-
/**
|
|
712
|
-
* Parse output of list camera controls shell command
|
|
713
|
-
*
|
|
714
|
-
* @param {String} stdout Output of the list camera control shell command
|
|
715
|
-
*
|
|
716
|
-
* @param {Function(Array<CameraControl>)} callback Function that receives
|
|
717
|
-
* camera controls
|
|
718
|
-
*
|
|
719
|
-
*/ FSWebcam$1.prototype.parseListControls = function(stdout, callback) {
|
|
720
|
-
var cameraControls = [];
|
|
721
|
-
var inOptions = false;
|
|
722
|
-
var prefixLength = 0;
|
|
723
|
-
var headerRegExp = new RegExp("(?<prefix>.*)------------------\\s+-------------\\s+-----.*");
|
|
724
|
-
var rangeRegExp = new RegExp("(?<name>.*?)" + "\\s+-?\\d+(?:\\s+\\(\\d+%\\))?\\s+" + "(?<min>-?\\d+)" + " - " + "(?<max>-?\\d+)", "i");
|
|
725
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
726
|
-
try {
|
|
727
|
-
for(var _iterator = stdout.split(/\n|\r|\n\r|\r\n/)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
728
|
-
var line = _step.value;
|
|
729
|
-
line = line.slice(prefixLength).trim();
|
|
730
|
-
inOptions = inOptions && line.startsWith("-") ? false : inOptions;
|
|
731
|
-
if (inOptions) {
|
|
732
|
-
var rangeGroups = line.match(rangeRegExp);
|
|
733
|
-
if (rangeGroups) {
|
|
734
|
-
var name = rangeGroups.groups.name;
|
|
735
|
-
var minRange = parseInt(rangeGroups.groups.min);
|
|
736
|
-
var maxRange = parseInt(rangeGroups.groups.max);
|
|
737
|
-
cameraControls.push({
|
|
738
|
-
name: name,
|
|
739
|
-
type: "range",
|
|
740
|
-
min: minRange,
|
|
741
|
-
max: maxRange
|
|
742
|
-
});
|
|
743
|
-
} else if (line.lastIndexOf("|") !== -1) {
|
|
744
|
-
var opts = [];
|
|
745
|
-
var opt = "";
|
|
746
|
-
var name = "";
|
|
747
|
-
var idx = line.lastIndexOf("|");
|
|
748
|
-
while(idx !== -1){
|
|
749
|
-
opt = line.slice(idx + 1).trim();
|
|
750
|
-
opts.push(opt);
|
|
751
|
-
var firstIdx = line.indexOf(opt);
|
|
752
|
-
var lastIdx = line.lastIndexOf(opt);
|
|
753
|
-
if (!name && firstIdx !== -1 && firstIdx !== lastIdx) {
|
|
754
|
-
name = line.slice(0, firstIdx).trim();
|
|
755
|
-
line = line.slice(firstIdx + opt.length);
|
|
756
|
-
idx = line.lastIndexOf("|");
|
|
757
|
-
}
|
|
758
|
-
line = line.slice(0, idx).trim();
|
|
759
|
-
idx = line.lastIndexOf("|");
|
|
760
|
-
}
|
|
761
|
-
if (name && line.trim()) {
|
|
762
|
-
opts.push(line.trim());
|
|
763
|
-
} else if (!name) {
|
|
764
|
-
// Find largest number of words with two consecutive matches
|
|
765
|
-
var words = line.split(" ").filter(function(item) {
|
|
766
|
-
return Boolean(item);
|
|
767
|
-
}).reverse();
|
|
768
|
-
var num_words = 1;
|
|
769
|
-
opt = words.slice(0, num_words).reverse().join(" ");
|
|
770
|
-
var re = new RegExp(opt + "\\s+" + opt);
|
|
771
|
-
while(!re.test(line)){
|
|
772
|
-
num_words += 1;
|
|
773
|
-
opt = words.slice(0, num_words).reverse().join(" ");
|
|
774
|
-
re = new RegExp(opt + "\\s+" + opt);
|
|
775
|
-
}
|
|
776
|
-
var firstIdx = line.indexOf(opt);
|
|
777
|
-
name = line.slice(0, firstIdx).trim();
|
|
778
|
-
opts.push(opt);
|
|
779
|
-
}
|
|
780
|
-
cameraControls.push({
|
|
781
|
-
name: name,
|
|
782
|
-
type: "list",
|
|
783
|
-
opts: opts.reverse()
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
var obj = line.match(headerRegExp);
|
|
788
|
-
if (obj) {
|
|
789
|
-
inOptions = true;
|
|
790
|
-
// The output of the fswebcam --list-controls command has
|
|
791
|
-
// terminal escape characters at the beginning of the each line
|
|
792
|
-
prefixLength = obj.groups.prefix.length;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
} catch (err) {
|
|
796
|
-
_didIteratorError = true;
|
|
797
|
-
_iteratorError = err;
|
|
798
|
-
} finally{
|
|
799
|
-
try {
|
|
800
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
801
|
-
_iterator.return();
|
|
802
|
-
}
|
|
803
|
-
} finally{
|
|
804
|
-
if (_didIteratorError) {
|
|
805
|
-
throw _iteratorError;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
callback && callback(cameraControls);
|
|
810
|
-
};
|
|
811
|
-
/**
|
|
812
|
-
* Data validations based on fs output
|
|
813
|
-
*
|
|
814
|
-
* @inheritdoc
|
|
815
|
-
*
|
|
816
|
-
*/ FSWebcam$1.prototype.runCaptureValidations = function(data) {
|
|
817
|
-
if (FSWebcam$1.Validations.noWebcam.exec(data)) {
|
|
818
|
-
return new Error("No webcam found");
|
|
819
|
-
}
|
|
820
|
-
return null;
|
|
821
|
-
};
|
|
822
|
-
//Defaults
|
|
823
|
-
FSWebcam$1.Defaults = {
|
|
824
|
-
topBanner: false,
|
|
825
|
-
bottomBanner: false,
|
|
826
|
-
title: false,
|
|
827
|
-
subTitle: false,
|
|
828
|
-
timestamp: false,
|
|
829
|
-
greyscale: false,
|
|
830
|
-
saturation: false,
|
|
831
|
-
skip: false,
|
|
832
|
-
setValues: {}
|
|
833
|
-
};
|
|
834
|
-
//Validations const
|
|
835
|
-
FSWebcam$1.Validations = {
|
|
836
|
-
noWebcam: /no.*such.*(file|device)/i
|
|
837
|
-
};
|
|
838
|
-
//Export
|
|
839
|
-
var FSWebcam_1 = FSWebcam$1;
|
|
840
|
-
|
|
841
|
-
/**
|
|
842
|
-
* API for imagesnap Mac OSX
|
|
843
|
-
*
|
|
844
|
-
* @requires [ imagesnap ]
|
|
845
|
-
*
|
|
846
|
-
* @param Object options
|
|
847
|
-
*
|
|
848
|
-
*/
|
|
849
|
-
var CHILD_PROCESS$1 = require$$0$1;
|
|
850
|
-
var EXEC$1 = CHILD_PROCESS$1.exec;
|
|
851
|
-
var Webcam$1 = Webcam_1;
|
|
852
|
-
var Utils$1 = Utils_1;
|
|
853
|
-
//Main class
|
|
854
|
-
function ImageSnapWebcam$1(options) {
|
|
855
|
-
var scope = this;
|
|
856
|
-
scope.opts = Utils$1.setDefaults(options, ImageSnapWebcam$1.Defaults);
|
|
857
|
-
//Without a delay imagesnap will not work
|
|
858
|
-
//Test on macbook 2015 13' retina
|
|
859
|
-
if (scope.opts.delay < 1) {
|
|
860
|
-
scope.opts.delay = 1;
|
|
861
|
-
}
|
|
862
|
-
//Construct
|
|
863
|
-
Webcam$1.call(scope, scope.opts);
|
|
864
|
-
}
|
|
865
|
-
ImageSnapWebcam$1.prototype = Object.create(Webcam$1.prototype);
|
|
866
|
-
ImageSnapWebcam$1.prototype.constructor = ImageSnapWebcam$1;
|
|
867
|
-
ImageSnapWebcam$1.prototype.bin = "imagesnap";
|
|
868
|
-
/**
|
|
869
|
-
* @override
|
|
870
|
-
*
|
|
871
|
-
* Generate shell statement
|
|
872
|
-
*
|
|
873
|
-
* @param String location
|
|
874
|
-
*
|
|
875
|
-
*/ ImageSnapWebcam$1.prototype.generateSh = function(location) {
|
|
876
|
-
var scope = this;
|
|
877
|
-
var verbose = scope.opts.verbose ? "-v" : "-q";
|
|
878
|
-
var delay = scope.opts.delay ? "-w " + scope.opts.delay : "";
|
|
879
|
-
var device = scope.opts.device ? "-d '" + scope.opts.device + "'" : "";
|
|
880
|
-
var sh = scope.bin + " " + delay + " " + device + " " + verbose + " " + location;
|
|
881
|
-
return sh;
|
|
882
|
-
};
|
|
883
|
-
/**
|
|
884
|
-
* @Override
|
|
885
|
-
*
|
|
886
|
-
* Webcam list
|
|
887
|
-
*
|
|
888
|
-
* @param Function callback
|
|
889
|
-
*
|
|
890
|
-
*/ ImageSnapWebcam$1.prototype.list = function(callback) {
|
|
891
|
-
var scope = this;
|
|
892
|
-
var sh = scope.bin + " -l";
|
|
893
|
-
var cams = [];
|
|
894
|
-
EXEC$1(sh, function(err, data, out) {
|
|
895
|
-
var lines = data.split("\n");
|
|
896
|
-
var ll = lines.length;
|
|
897
|
-
for(var i = 0; i < ll; i++){
|
|
898
|
-
var line = lines[i];
|
|
899
|
-
if (line === "Video Devices:" || !line) {
|
|
900
|
-
continue;
|
|
901
|
-
}
|
|
902
|
-
//imagesnap update adds extra stuff
|
|
903
|
-
line = line.replace(/.*?\[(.*?)\].*/, "$1");
|
|
904
|
-
cams.push(line);
|
|
905
|
-
}
|
|
906
|
-
callback && callback(cams);
|
|
907
|
-
});
|
|
908
|
-
};
|
|
909
|
-
//Defaults
|
|
910
|
-
ImageSnapWebcam$1.Defaults = {
|
|
911
|
-
delay: 1
|
|
912
|
-
};
|
|
913
|
-
//Export
|
|
914
|
-
var ImageSnapWebcam_1 = ImageSnapWebcam$1;
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* API for Windows
|
|
918
|
-
*
|
|
919
|
-
* @requires [ CommandCam ]
|
|
920
|
-
*
|
|
921
|
-
* @param Object options
|
|
922
|
-
*
|
|
923
|
-
*/
|
|
924
|
-
var CHILD_PROCESS = require$$0$1;
|
|
925
|
-
var EXEC = CHILD_PROCESS.exec;
|
|
926
|
-
var Webcam = Webcam_1;
|
|
927
|
-
var Utils = Utils_1;
|
|
928
|
-
var Path = require$$3;
|
|
929
|
-
//Main class
|
|
930
|
-
function WindowsWebcam$1(options) {
|
|
931
|
-
var scope = this;
|
|
932
|
-
scope.opts = Utils.setDefaults(options, WindowsWebcam$1.Defaults);
|
|
933
|
-
//Construct
|
|
934
|
-
Webcam.call(scope, scope.opts);
|
|
935
|
-
//command cam uses miliseconds
|
|
936
|
-
scope.opts.delay = scope.opts.delay * 1000;
|
|
937
|
-
}
|
|
938
|
-
WindowsWebcam$1.prototype = Object.create(Webcam.prototype);
|
|
939
|
-
WindowsWebcam$1.prototype.constructor = WindowsWebcam$1;
|
|
940
|
-
WindowsWebcam$1.prototype.bin = "\"" + Path.resolve(__dirname, "..", "bindings", "CommandCam", "CommandCam.exe") + "\"";
|
|
941
|
-
/**
|
|
942
|
-
* @override
|
|
943
|
-
*
|
|
944
|
-
* Generate shell statement
|
|
945
|
-
*
|
|
946
|
-
* @param String location
|
|
947
|
-
*
|
|
948
|
-
*/ WindowsWebcam$1.prototype.generateSh = function(location) {
|
|
949
|
-
var scope = this;
|
|
950
|
-
var device = scope.opts.device ? "/devnum " + scope.opts.device : "";
|
|
951
|
-
var delay = scope.opts.delay ? "/delay " + scope.opts.delay : "";
|
|
952
|
-
var sh = scope.bin + " " + delay + " " + device + " " + "/filename " + location;
|
|
953
|
-
return sh;
|
|
954
|
-
};
|
|
955
|
-
/**
|
|
956
|
-
* List webcam devices using bin
|
|
957
|
-
*
|
|
958
|
-
* @param Function callback
|
|
959
|
-
*
|
|
960
|
-
*/ WindowsWebcam$1.prototype.list = function(callback) {
|
|
961
|
-
var scope = this;
|
|
962
|
-
var sh = scope.bin + " /devlist";
|
|
963
|
-
var cams = [];
|
|
964
|
-
EXEC(sh, function(err, data, out) {
|
|
965
|
-
if (err) {
|
|
966
|
-
throw err;
|
|
967
|
-
}
|
|
968
|
-
var lines = out.split("\n");
|
|
969
|
-
var ll = lines.length;
|
|
970
|
-
var camNum = 1;
|
|
971
|
-
for(var i = 0; i < ll; i++){
|
|
972
|
-
var line = lines[i];
|
|
973
|
-
line = line.replace("\r", "");
|
|
974
|
-
if (!!line && line !== "Available capture devices:" && "No video devices found") {
|
|
975
|
-
cams.push(camNum.toString());
|
|
976
|
-
camNum++;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
callback && callback(cams);
|
|
980
|
-
});
|
|
981
|
-
};
|
|
982
|
-
//Defaults
|
|
983
|
-
WindowsWebcam$1.Defaults = {
|
|
984
|
-
output: "bmp"
|
|
985
|
-
};
|
|
986
|
-
//Export
|
|
987
|
-
var WindowsWebcam_1 = WindowsWebcam$1;
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* Factory based on OS output
|
|
991
|
-
*
|
|
992
|
-
*/
|
|
993
|
-
|
|
994
|
-
var OS = require$$0;
|
|
995
|
-
//Webcam types
|
|
996
|
-
var FSWebcam = FSWebcam_1;
|
|
997
|
-
var ImageSnapWebcam = ImageSnapWebcam_1;
|
|
998
|
-
var WindowsWebcam = WindowsWebcam_1;
|
|
999
|
-
//Main singleton
|
|
1000
|
-
var Factory = new function() {
|
|
1001
|
-
var scope = this;
|
|
1002
|
-
//Main Class get
|
|
1003
|
-
scope.create = function(options, type) {
|
|
1004
|
-
var p = type || Factory.Platform;
|
|
1005
|
-
var Type = Factory.Types[p];
|
|
1006
|
-
if (!Type) {
|
|
1007
|
-
throw new Error("Sorry, no webcam type specified yet for platform " + p);
|
|
1008
|
-
}
|
|
1009
|
-
return new Type(options);
|
|
1010
|
-
};
|
|
1011
|
-
};
|
|
1012
|
-
Factory.Platform = OS.platform();
|
|
1013
|
-
//OS Webcam types
|
|
1014
|
-
Factory.Types = {
|
|
1015
|
-
linux: FSWebcam,
|
|
1016
|
-
darwin: ImageSnapWebcam,
|
|
1017
|
-
fswebcam: FSWebcam,
|
|
1018
|
-
win32: WindowsWebcam,
|
|
1019
|
-
win64: WindowsWebcam
|
|
1020
|
-
};
|
|
1021
|
-
//Export
|
|
1022
|
-
var Factory_1 = Factory;
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* Main classes and use
|
|
1026
|
-
*
|
|
1027
|
-
* @module NodeWebcam
|
|
1028
|
-
*
|
|
1029
|
-
*/
|
|
1030
|
-
/**
|
|
1031
|
-
* @class API
|
|
1032
|
-
*
|
|
1033
|
-
*/ var NodeWebcam = {
|
|
1034
|
-
version: "0.4.1",
|
|
1035
|
-
REVISION: 4,
|
|
1036
|
-
Factory: Factory_1,
|
|
1037
|
-
Webcam: Factory_1,
|
|
1038
|
-
FSWebcam: FSWebcam_1,
|
|
1039
|
-
ImageSnapWebcam: ImageSnapWebcam_1,
|
|
1040
|
-
WindowsWebcam: WindowsWebcam_1
|
|
1041
|
-
};
|
|
1042
|
-
//API
|
|
1043
|
-
/**
|
|
1044
|
-
* Main create
|
|
1045
|
-
*
|
|
1046
|
-
* @method create
|
|
1047
|
-
*
|
|
1048
|
-
* @param {Object} options
|
|
1049
|
-
*
|
|
1050
|
-
*/ NodeWebcam.create = function(options) {
|
|
1051
|
-
return NodeWebcam.Factory.create(options);
|
|
1052
|
-
};
|
|
1053
|
-
/**
|
|
1054
|
-
* Quick capture helper
|
|
1055
|
-
*
|
|
1056
|
-
* @method capture
|
|
1057
|
-
*
|
|
1058
|
-
* @param {String} location
|
|
1059
|
-
* @param {Object} options
|
|
1060
|
-
* @param {Function} callback
|
|
1061
|
-
*
|
|
1062
|
-
*/ NodeWebcam.capture = function(location, options, callback) {
|
|
1063
|
-
var webcam = NodeWebcam.create(options);
|
|
1064
|
-
webcam.capture(location, callback);
|
|
1065
|
-
return webcam;
|
|
1066
|
-
};
|
|
1067
|
-
/**
|
|
1068
|
-
* Camera list helper
|
|
1069
|
-
*
|
|
1070
|
-
* @method list
|
|
1071
|
-
*
|
|
1072
|
-
* @param {Function(Array<String>)} callback
|
|
1073
|
-
*
|
|
1074
|
-
*/ NodeWebcam.list = function(callback) {
|
|
1075
|
-
var cam = NodeWebcam.create({});
|
|
1076
|
-
cam.list(callback);
|
|
1077
|
-
};
|
|
1078
|
-
/**
|
|
1079
|
-
* @typedef CameraControl
|
|
1080
|
-
* @type {Object}
|
|
1081
|
-
* @param {String} name Control name, as it should appear in the setValues object
|
|
1082
|
-
* @param {String} type Either "range" or "list"
|
|
1083
|
-
* @param {Number} min For "range" controls, minimum control value
|
|
1084
|
-
* @param {Number} max For "range" controls, maximum control value
|
|
1085
|
-
* @param {Array(<String>)} opts For "list" controls, available control options
|
|
1086
|
-
*
|
|
1087
|
-
*/ /**
|
|
1088
|
-
* Camera options helper
|
|
1089
|
-
*
|
|
1090
|
-
* @method listControls
|
|
1091
|
-
*
|
|
1092
|
-
* @param {String} device
|
|
1093
|
-
* @param {Function(Array<CameraControl>)} callback
|
|
1094
|
-
*
|
|
1095
|
-
*/ NodeWebcam.listControls = function(device, callback) {
|
|
1096
|
-
var cam = NodeWebcam.create({
|
|
1097
|
-
device: device
|
|
1098
|
-
});
|
|
1099
|
-
cam.listControls(callback);
|
|
1100
|
-
};
|
|
1101
|
-
//Export
|
|
1102
|
-
var nodeWebcam = NodeWebcam;
|
|
1103
|
-
|
|
1104
|
-
let WebcamService = class WebcamService {
|
|
1105
|
-
async capture(params, _pinsSettingsList, _context) {
|
|
1106
|
-
const { width = 1280, height = 720, quality = 100, output = 'jpeg', device, verbose = false } = params;
|
|
1107
|
-
const opts = {
|
|
1108
|
-
width,
|
|
1109
|
-
height,
|
|
1110
|
-
quality,
|
|
1111
|
-
delay: 0,
|
|
1112
|
-
saveShots: false,
|
|
1113
|
-
output,
|
|
1114
|
-
device: device != null ? device : false,
|
|
1115
|
-
callbackReturn: 'base64',
|
|
1116
|
-
verbose
|
|
1117
|
-
};
|
|
1118
|
-
const webcam = nodeWebcam.create(opts);
|
|
1119
|
-
const result = await new Promise((resolve, reject)=>{
|
|
1120
|
-
webcam.capture("capture", (err, data)=>{
|
|
1121
|
-
if (err) {
|
|
1122
|
-
reject(err);
|
|
1123
|
-
} else {
|
|
1124
|
-
resolve(data);
|
|
1125
|
-
}
|
|
1126
|
-
});
|
|
1127
|
-
});
|
|
1128
|
-
webcam.clear();
|
|
1129
|
-
return result;
|
|
1130
|
-
}
|
|
1131
|
-
async list(_params, _pinsSettingsList, _context) {
|
|
1132
|
-
let webcam = nodeWebcam.create({});
|
|
1133
|
-
const list = (await new Promise((resolve)=>{
|
|
1134
|
-
webcam.list((data)=>{
|
|
1135
|
-
resolve(data);
|
|
1136
|
-
});
|
|
1137
|
-
})).map((camera)=>camera.replace(/^=> /g, ''));
|
|
1138
|
-
webcam.clear();
|
|
1139
|
-
return list;
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1142
|
-
const capture = (params, pinsSettingsList, context)=>new WebcamService().capture(params, pinsSettingsList, context);
|
|
1143
|
-
const list = (params, pinsSettingsList, context)=>new WebcamService().list(params, pinsSettingsList, context);
|
|
1144
|
-
|
|
1145
|
-
exports.capture = capture;
|
|
1146
|
-
exports.list = list;
|