@capturebridge/sdk 0.7.1 → 0.8.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/Camera.js +27 -32
- package/CanonCamera.js +2 -2
- package/CaptureBridge.js +13 -15
- package/CapturePlugin.js +21 -32
- package/Common.js +91 -7
- package/Device.js +120 -24
- package/ICAO.js +1 -1
- package/IFace.js +5 -1
- package/MockCamera.js +7 -0
- package/Plugin.js +6 -5
- package/Scanner.js +13 -22
- package/SignatureTablet.js +22 -23
- package/SignatureTabletWidgets.js +14 -3
- package/StreamingCapturePlugin.js +39 -31
- package/TopazSigGem.js +1 -1
- package/Version.js +8 -0
- package/WindowsScanner.js +25 -0
- package/examples/canon.html +66 -0
- package/examples/canon_getframe.html +68 -0
- package/examples/canon_lan.html +68 -0
- package/examples/canon_minimal.html +37 -0
- package/examples/mockcamera.html +61 -0
- package/examples/mockcamera_getframe.html +63 -0
- package/examples/mockcamera_minimal.html +31 -0
- package/examples/windows_scanner_minimal.html +32 -0
- package/package.json +2 -2
package/Device.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BASE_URL,
|
|
3
|
+
POST,
|
|
4
|
+
DELETE,
|
|
5
|
+
DEFAULT_STREAM_OPT,
|
|
6
|
+
DEFAULT_CAPTURE_OPT,
|
|
7
|
+
checkResponse,
|
|
8
|
+
timeout,
|
|
9
|
+
asyncToCallback
|
|
10
|
+
} from './Common.js'
|
|
2
11
|
|
|
3
12
|
/**
|
|
4
13
|
* Device
|
|
@@ -50,16 +59,57 @@ class Device {
|
|
|
50
59
|
* for any reason, the live feed will automatically be stopped.
|
|
51
60
|
*
|
|
52
61
|
* @method
|
|
62
|
+
* @param {StreamOptions} [streamOpt] - Additional options for streaming.
|
|
53
63
|
* @returns {string} stream endpoint URL
|
|
54
64
|
* @example
|
|
55
65
|
* const img = document.createElement('img')
|
|
56
66
|
* img.src = device.streamUrl()
|
|
57
67
|
* document.body.appendChild(img)
|
|
58
68
|
*/
|
|
59
|
-
streamUrl () {
|
|
69
|
+
streamUrl (streamOpt = {}) {
|
|
60
70
|
this.can('start_feed')
|
|
61
71
|
this.can('stop_feed')
|
|
62
|
-
|
|
72
|
+
const mergedOpts = Object.assign({}, DEFAULT_STREAM_OPT, streamOpt)
|
|
73
|
+
const params = new URLSearchParams(mergedOpts).toString()
|
|
74
|
+
return `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/stream?${params}`
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Take full capture from the specified device and return an
|
|
79
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static|ObjectURL}
|
|
80
|
+
* that can be set directly on an img tag's src attribute. Note that URLs
|
|
81
|
+
* created by this method should be
|
|
82
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static|revoked}
|
|
83
|
+
* when they are no longer needed.
|
|
84
|
+
* (Async/Await version)
|
|
85
|
+
*
|
|
86
|
+
* @method
|
|
87
|
+
* @async
|
|
88
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
89
|
+
* frame.
|
|
90
|
+
* @returns {string}
|
|
91
|
+
* @example
|
|
92
|
+
* // Load the blob into FileReader and append to the document's body
|
|
93
|
+
* const blob = await device.captureAsBlob()
|
|
94
|
+
* const reader = new FileReader()
|
|
95
|
+
* reader.onload = event => {
|
|
96
|
+
* const img = document.createElement('img')
|
|
97
|
+
* img.src = event.target.result
|
|
98
|
+
* document.body.appendChild(img)
|
|
99
|
+
* }
|
|
100
|
+
* reader.readAsDataURL(blob)
|
|
101
|
+
*/
|
|
102
|
+
async captureAsObjectURL (captureOpt = {}) {
|
|
103
|
+
this.can('capture')
|
|
104
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
105
|
+
|
|
106
|
+
// Method ignores kind, always returns an object URL
|
|
107
|
+
delete captureParams.kind
|
|
108
|
+
|
|
109
|
+
const params = new URLSearchParams(captureParams).toString()
|
|
110
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
111
|
+
const response = await fetch(url, POST)
|
|
112
|
+
return await response.blob()
|
|
63
113
|
}
|
|
64
114
|
|
|
65
115
|
/**
|
|
@@ -70,6 +120,8 @@ class Device {
|
|
|
70
120
|
*
|
|
71
121
|
* @method
|
|
72
122
|
* @async
|
|
123
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
124
|
+
* frame.
|
|
73
125
|
* @returns {object} {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob}
|
|
74
126
|
* @example
|
|
75
127
|
* // Load the blob into FileReader and append to the document's body
|
|
@@ -82,9 +134,15 @@ class Device {
|
|
|
82
134
|
* }
|
|
83
135
|
* reader.readAsDataURL(blob)
|
|
84
136
|
*/
|
|
85
|
-
async captureAsBlob () {
|
|
137
|
+
async captureAsBlob (captureOpt = {}) {
|
|
86
138
|
this.can('capture')
|
|
87
|
-
const
|
|
139
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
140
|
+
|
|
141
|
+
// Method ignores kind, always returns binary data (blob)
|
|
142
|
+
delete captureParams.kind
|
|
143
|
+
|
|
144
|
+
const params = new URLSearchParams(captureParams).toString()
|
|
145
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
88
146
|
const response = await fetch(url, POST)
|
|
89
147
|
return await response.blob()
|
|
90
148
|
}
|
|
@@ -96,7 +154,9 @@ class Device {
|
|
|
96
154
|
* (Callback version)
|
|
97
155
|
*
|
|
98
156
|
* @method
|
|
99
|
-
* @param {function} callback
|
|
157
|
+
* @param {function} callback
|
|
158
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
159
|
+
* frame.
|
|
100
160
|
* @example
|
|
101
161
|
* // Load the blob into FileReader and append to the document's body
|
|
102
162
|
* device.captureAsBlobHandler((error, blob) => {
|
|
@@ -109,8 +169,8 @@ class Device {
|
|
|
109
169
|
* reader.readAsDataURL(blob)
|
|
110
170
|
* })
|
|
111
171
|
*/
|
|
112
|
-
captureAsBlobHandler (callback) {
|
|
113
|
-
asyncToCallback(this, this.captureAsBlob, callback)
|
|
172
|
+
captureAsBlobHandler (callback, captureOpt = {}) {
|
|
173
|
+
asyncToCallback(this, this.captureAsBlob, captureOpt, callback)
|
|
114
174
|
}
|
|
115
175
|
|
|
116
176
|
/**
|
|
@@ -121,6 +181,8 @@ class Device {
|
|
|
121
181
|
*
|
|
122
182
|
* @method
|
|
123
183
|
* @async
|
|
184
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
185
|
+
* frame.
|
|
124
186
|
* @returns {string} Base64 Encoded image
|
|
125
187
|
* @example
|
|
126
188
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -130,10 +192,18 @@ class Device {
|
|
|
130
192
|
* img.src = 'data:image/jpeg;base64,' + base64
|
|
131
193
|
* document.body.appendChild(img)
|
|
132
194
|
*/
|
|
133
|
-
async captureAsBase64 () {
|
|
195
|
+
async captureAsBase64 (captureOpt = {}) {
|
|
134
196
|
this.can('capture')
|
|
135
|
-
const
|
|
197
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
198
|
+
|
|
199
|
+
// Method ignores kind, always returns base64 data
|
|
200
|
+
delete captureParams.kind
|
|
201
|
+
captureParams.base64 = true
|
|
202
|
+
|
|
203
|
+
const params = new URLSearchParams(captureParams).toString()
|
|
204
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
136
205
|
const response = await fetch(url, POST)
|
|
206
|
+
await checkResponse(response)
|
|
137
207
|
const { image } = await response.json()
|
|
138
208
|
return image
|
|
139
209
|
}
|
|
@@ -144,9 +214,11 @@ class Device {
|
|
|
144
214
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
145
215
|
* (Callback version)
|
|
146
216
|
* @method
|
|
147
|
-
* @param {function} callback
|
|
217
|
+
* @param {function} callback
|
|
218
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
219
|
+
* frame.
|
|
148
220
|
*/
|
|
149
|
-
captureAsBase64Handler (callback) {
|
|
221
|
+
captureAsBase64Handler (callback, captureOpt = {}) {
|
|
150
222
|
asyncToCallback(this, this.captureAsBase64, callback)
|
|
151
223
|
}
|
|
152
224
|
|
|
@@ -171,6 +243,8 @@ class Device {
|
|
|
171
243
|
*
|
|
172
244
|
* @async
|
|
173
245
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
246
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
247
|
+
* frame.
|
|
174
248
|
* @returns {string} Base64 Encoded image
|
|
175
249
|
* @example
|
|
176
250
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -180,14 +254,21 @@ class Device {
|
|
|
180
254
|
* img.src = 'data:image/jpeg;base64,' + base64
|
|
181
255
|
* document.body.appendChild(img)
|
|
182
256
|
*/
|
|
183
|
-
async frameAsBase64 (millis =
|
|
257
|
+
async frameAsBase64 (captureOpt = {}, millis = 500) {
|
|
184
258
|
this.can('start_feed')
|
|
185
|
-
const
|
|
259
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
260
|
+
|
|
261
|
+
// Method ignores kind, always returns base64 data
|
|
262
|
+
delete captureParams.kind
|
|
263
|
+
captureParams.base64 = true
|
|
264
|
+
|
|
265
|
+
const params = new URLSearchParams(captureParams).toString()
|
|
266
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/livefeed?${params}`
|
|
186
267
|
const response = await fetch(url)
|
|
187
268
|
const result = await response.json()
|
|
188
269
|
if (result.error && (result.code === 425 || result.code === 400)) {
|
|
189
270
|
await timeout(millis)
|
|
190
|
-
return await this.frameAsBase64(millis)
|
|
271
|
+
return await this.frameAsBase64(captureOpt, millis)
|
|
191
272
|
} else {
|
|
192
273
|
return result.image
|
|
193
274
|
}
|
|
@@ -212,7 +293,9 @@ class Device {
|
|
|
212
293
|
* @see {@link streamUrl}
|
|
213
294
|
* @see {@link setStopFeed}
|
|
214
295
|
*
|
|
215
|
-
* @param {function} callback
|
|
296
|
+
* @param {function} callback
|
|
297
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
298
|
+
* frame.
|
|
216
299
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
217
300
|
* @example
|
|
218
301
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -223,8 +306,8 @@ class Device {
|
|
|
223
306
|
* document.body.appendChild(img)
|
|
224
307
|
* })
|
|
225
308
|
*/
|
|
226
|
-
frameAsBase64Handler (callback, millis =
|
|
227
|
-
asyncToCallback(this, this.frameAsBase64, callback, millis)
|
|
309
|
+
frameAsBase64Handler (callback, captureOpt = {}, millis = 500) {
|
|
310
|
+
asyncToCallback(this, this.frameAsBase64, callback, captureOpt, millis)
|
|
228
311
|
}
|
|
229
312
|
|
|
230
313
|
/**
|
|
@@ -247,6 +330,8 @@ class Device {
|
|
|
247
330
|
* @see {@link stopFeed}
|
|
248
331
|
*
|
|
249
332
|
* @async
|
|
333
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
334
|
+
* frame.
|
|
250
335
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
251
336
|
* @returns {object} {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob}
|
|
252
337
|
* @example
|
|
@@ -260,10 +345,16 @@ class Device {
|
|
|
260
345
|
* }
|
|
261
346
|
* reader.readAsDataURL(blob)
|
|
262
347
|
*/
|
|
263
|
-
async frameAsBlob (millis =
|
|
348
|
+
async frameAsBlob (captureOpt = {}, millis = 500) {
|
|
264
349
|
this.can('start_feed')
|
|
265
|
-
const
|
|
266
|
-
|
|
350
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
351
|
+
|
|
352
|
+
// Method ignores kind, always returns binary data (blob)
|
|
353
|
+
delete captureParams.kind
|
|
354
|
+
|
|
355
|
+
const params = new URLSearchParams(captureParams).toString()
|
|
356
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/livefeed?${params}`
|
|
357
|
+
const result = await this.frameAsBase64(captureOpt, millis)
|
|
267
358
|
if (typeof result === 'string') {
|
|
268
359
|
timeout(millis)
|
|
269
360
|
const response = await fetch(url)
|
|
@@ -291,8 +382,13 @@ class Device {
|
|
|
291
382
|
* @see {@link streamUrl}
|
|
292
383
|
* @see {@link setStopFeed}
|
|
293
384
|
*
|
|
294
|
-
* @param {function} callback
|
|
385
|
+
* @param {function} callback
|
|
386
|
+
*
|
|
387
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
388
|
+
* frame.
|
|
389
|
+
*
|
|
295
390
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
391
|
+
*
|
|
296
392
|
* @example
|
|
297
393
|
* // Load the blob into FileReader and append to the document's body
|
|
298
394
|
* device.frameAsBlobHandler((error, blob) => {
|
|
@@ -305,8 +401,8 @@ class Device {
|
|
|
305
401
|
* reader.readAsDataURL(blob)
|
|
306
402
|
* })
|
|
307
403
|
*/
|
|
308
|
-
frameAsBlobHandler (callback, millis =
|
|
309
|
-
asyncToCallback(this, this.frameAsBlob, callback, millis)
|
|
404
|
+
frameAsBlobHandler (callback, captureOpt = {}, millis = 500) {
|
|
405
|
+
asyncToCallback(this, this.frameAsBlob, callback, captureOpt, millis)
|
|
310
406
|
}
|
|
311
407
|
|
|
312
408
|
/**
|
package/ICAO.js
CHANGED
package/IFace.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module IFace
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import ICAO from './ICAO.js'
|
|
2
6
|
import { BASE_URL, blobToBase64 } from './Common.js'
|
|
3
7
|
|
|
@@ -75,7 +79,7 @@ export class Probe {
|
|
|
75
79
|
/**
|
|
76
80
|
* Candidate
|
|
77
81
|
* @classdesc Candidate Class for Innovatrics IFace SDK
|
|
78
|
-
*
|
|
82
|
+
* @extends Probe
|
|
79
83
|
* @see {@link IFace}
|
|
80
84
|
*/
|
|
81
85
|
export class Candidate extends Probe {
|
package/MockCamera.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import Camera from './Camera.js'
|
|
2
2
|
import { BASE_URL } from './Common.js'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* MockCamera
|
|
6
|
+
* @classdesc Convenience class for instantiating a Mock Camera Object.
|
|
7
|
+
* Inherits all methods on the {@link Camera} class.
|
|
8
|
+
* @extends Camera
|
|
9
|
+
* @see {@link Camera}
|
|
10
|
+
*/
|
|
4
11
|
class MockCamera extends Camera {
|
|
5
12
|
constructor (baseUrl = BASE_URL) {
|
|
6
13
|
super('capture_camera_mock', baseUrl)
|
package/Plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Device from './Device.js'
|
|
2
2
|
|
|
3
|
-
import { BASE_URL, DELETE, asyncToCallback } from './Common.js'
|
|
3
|
+
import { BASE_URL, DELETE, checkResponse, asyncToCallback } from './Common.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @classdesc CaptureBridge utilizes a plugin system for interacting with
|
|
@@ -62,7 +62,7 @@ class Plugin {
|
|
|
62
62
|
*
|
|
63
63
|
* @method
|
|
64
64
|
* @async
|
|
65
|
-
* @see {@link https://
|
|
65
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
|
|
66
66
|
* @returns {object[]} Array of {@link Device} objects.
|
|
67
67
|
* @example
|
|
68
68
|
* const plugin = await captureBridge.plugin('capture_camera_canon')
|
|
@@ -70,6 +70,7 @@ class Plugin {
|
|
|
70
70
|
*/
|
|
71
71
|
async devices () {
|
|
72
72
|
const response = await fetch(`${this.baseUrl}/plugin/${this.id}/device`)
|
|
73
|
+
await checkResponse(response)
|
|
73
74
|
const devices = await response.json()
|
|
74
75
|
return devices.map(d => new Device(d, this, this.baseUrl))
|
|
75
76
|
}
|
|
@@ -78,7 +79,7 @@ class Plugin {
|
|
|
78
79
|
* Get all Devices for this plugin
|
|
79
80
|
*
|
|
80
81
|
* @method
|
|
81
|
-
* @see {@link https://
|
|
82
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
|
|
82
83
|
* @param {function} callback - Invoked with two arguments. The first argument
|
|
83
84
|
* is an Error object (if an error occurred) or null. The second argument is
|
|
84
85
|
* an Array of {@link Device} objects. If no devices are available the second
|
|
@@ -97,7 +98,7 @@ class Plugin {
|
|
|
97
98
|
*
|
|
98
99
|
* @method
|
|
99
100
|
* @async
|
|
100
|
-
* @see {@link https://
|
|
101
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
|
|
101
102
|
* @param {string} id - Device ID
|
|
102
103
|
* @returns {object?} Requested {@link Device} or null
|
|
103
104
|
* @example
|
|
@@ -114,7 +115,7 @@ class Plugin {
|
|
|
114
115
|
/**
|
|
115
116
|
* Get a Device by ID for this plugin
|
|
116
117
|
* @method
|
|
117
|
-
* @see {@link https://
|
|
118
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
|
|
118
119
|
* @param {string} id - Device ID
|
|
119
120
|
* @param {function} callback - Invoked with two arguments. The first argument
|
|
120
121
|
* is an Error object (if an error occurred) or null. The second argument is
|
package/Scanner.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CapturePlugin from './CapturePlugin.js'
|
|
2
|
-
import { BASE_URL } from './Common.js'
|
|
2
|
+
import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Scanner
|
|
@@ -24,26 +24,9 @@ class Scanner extends CapturePlugin {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Scan a document
|
|
27
|
-
* @param {string} [kind] - Specify how to return the scanned document. Valid
|
|
28
|
-
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
29
27
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* that can be set directly on an img tag's src attribute.
|
|
33
|
-
*
|
|
34
|
-
* The value of 'blob' will return a
|
|
35
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
36
|
-
* be used with a
|
|
37
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
38
|
-
*
|
|
39
|
-
* The value of 'base64' will return the image contents as a
|
|
40
|
-
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
41
|
-
* suitable for use with JSON serialization.
|
|
42
|
-
*
|
|
43
|
-
* The value of 'dataurl' will return a JPEG
|
|
44
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
45
|
-
* that can be set on an img tag's src attribute or loaded as a document
|
|
46
|
-
* location.
|
|
28
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
29
|
+
* signature.
|
|
47
30
|
*
|
|
48
31
|
* @param {string|object} [deviceOpt] - Can a document using either a specific
|
|
49
32
|
* Device ID or a Device Object. The default is the first available device.
|
|
@@ -56,8 +39,16 @@ class Scanner extends CapturePlugin {
|
|
|
56
39
|
* img.src = await scanner.scan()
|
|
57
40
|
* document.body.appendChild(img)
|
|
58
41
|
*/
|
|
59
|
-
async scan (
|
|
60
|
-
|
|
42
|
+
async scan (captureOpt = {}, deviceOpt) {
|
|
43
|
+
if (typeof captureOpt === 'string' && DEPRECATION_01) {
|
|
44
|
+
captureOpt = { kind: captureOpt }
|
|
45
|
+
console.warn('CaptureBridge SDK Deprecation Warning: `Scanner.scan()` ' +
|
|
46
|
+
'converted the `captureOpt` argument from a string (%s) to an object ' +
|
|
47
|
+
'(%s). This conversion may not be performed in future SDK versions.',
|
|
48
|
+
captureOpt.kind, JSON.stringify(captureOpt))
|
|
49
|
+
}
|
|
50
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
51
|
+
return await this.fullCapture(mergedOpt, deviceOpt)
|
|
61
52
|
}
|
|
62
53
|
}
|
|
63
54
|
|
package/SignatureTablet.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import StreamingCapturePlugin from './StreamingCapturePlugin.js'
|
|
2
|
-
import { BASE_URL } from './Common.js'
|
|
2
|
+
import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* SignatureTablet
|
|
6
|
+
* @classdesc Class for invoking methods on a Signature Capture Tablet
|
|
7
|
+
* @extends StreamingCapturePlugin
|
|
8
|
+
* @see {@link TopazSigGem}
|
|
9
|
+
*/
|
|
4
10
|
class SignatureTablet extends StreamingCapturePlugin {
|
|
5
11
|
#captureBridge
|
|
6
12
|
#scene = {}
|
|
@@ -69,29 +75,13 @@ class SignatureTablet extends StreamingCapturePlugin {
|
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
77
|
* Capture a high resolution signature
|
|
72
|
-
* @param {string} [kind] - Specify how to return the captured photo. Valid
|
|
73
|
-
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
74
78
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* that can be set directly on an img tag's src attribute.
|
|
78
|
-
*
|
|
79
|
-
* The value of 'blob' will return a
|
|
80
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
81
|
-
* be used with a
|
|
82
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
83
|
-
*
|
|
84
|
-
* The value of 'base64' will return the image contents as a
|
|
85
|
-
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
86
|
-
* suitable for use with JSON serialization.
|
|
87
|
-
*
|
|
88
|
-
* The value of 'dataurl' will return a JPEG
|
|
89
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
90
|
-
* that can be set on an img tag's src attribute or loaded as a document
|
|
91
|
-
* location.
|
|
79
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
80
|
+
* signature.
|
|
92
81
|
*
|
|
93
82
|
* @param {string|object} [deviceOpt] - Capture the signature using either a
|
|
94
|
-
* specific Device ID or a Device Object. The default is the first available
|
|
83
|
+
* specific Device ID or a Device Object. The default is the first available
|
|
84
|
+
* device.
|
|
95
85
|
*
|
|
96
86
|
* @async
|
|
97
87
|
* @example
|
|
@@ -101,8 +91,17 @@ class SignatureTablet extends StreamingCapturePlugin {
|
|
|
101
91
|
* img.src = await tablet.signature()
|
|
102
92
|
* document.body.appendChild(img)
|
|
103
93
|
*/
|
|
104
|
-
async signature (
|
|
105
|
-
|
|
94
|
+
async signature (captureOpt = {}, deviceOpt) {
|
|
95
|
+
if (typeof captureOpt === 'string' && DEPRECATION_01) {
|
|
96
|
+
captureOpt = { kind: captureOpt }
|
|
97
|
+
console.warn('CaptureBridge SDK Deprecation Warning: ' +
|
|
98
|
+
'`SignatureTablet.signature()` converted the `captureOpt` argument ' +
|
|
99
|
+
'from a string (%s) to an object (%s). This conversion may not be ' +
|
|
100
|
+
'performed in future SDK versions.',
|
|
101
|
+
captureOpt.kind, JSON.stringify(captureOpt))
|
|
102
|
+
}
|
|
103
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
104
|
+
return await this.fullCapture(mergedOpt, deviceOpt)
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module SignatureTabletWidgets
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
import { blobToBase64 } from './Common.js'
|
|
2
6
|
|
|
7
|
+
/**
|
|
8
|
+
* DisplayWidget
|
|
9
|
+
* @classdesc Represents a widget that can be displayed at some x and y coordinates
|
|
10
|
+
* @see {@link TextButton}
|
|
11
|
+
* @see {@link Text}
|
|
12
|
+
* @see {@link Image}
|
|
13
|
+
*/
|
|
3
14
|
export class DisplayWidget {
|
|
4
15
|
x
|
|
5
16
|
y
|
|
@@ -12,7 +23,7 @@ export class DisplayWidget {
|
|
|
12
23
|
/**
|
|
13
24
|
* TextButton
|
|
14
25
|
* @classdesc A button for displaying clickable text on a tablet
|
|
15
|
-
*
|
|
26
|
+
* @extends DisplayWidget
|
|
16
27
|
* @see {@link SignatureTablet}
|
|
17
28
|
*/
|
|
18
29
|
export class TextButton extends DisplayWidget {
|
|
@@ -64,7 +75,7 @@ export class TextButton extends DisplayWidget {
|
|
|
64
75
|
/**
|
|
65
76
|
* Text
|
|
66
77
|
* @classdesc Text to be displayed on a tablet
|
|
67
|
-
*
|
|
78
|
+
* @extends DisplayWidget
|
|
68
79
|
* @see {@link SignatureTablet}
|
|
69
80
|
*/
|
|
70
81
|
export class Text extends DisplayWidget {
|
|
@@ -106,7 +117,7 @@ export class Text extends DisplayWidget {
|
|
|
106
117
|
/**
|
|
107
118
|
* Image
|
|
108
119
|
* @classdesc Image to be displayed on a tablet
|
|
109
|
-
*
|
|
120
|
+
* @extends DisplayWidget
|
|
110
121
|
* @see {@link SignatureTablet}
|
|
111
122
|
*/
|
|
112
123
|
export class Image extends DisplayWidget {
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import CapturePlugin from './CapturePlugin.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BASE_URL,
|
|
4
|
+
DATAURL_JPEG,
|
|
5
|
+
blobToBuffer,
|
|
6
|
+
DEFAULT_CAPTURE_OPT,
|
|
7
|
+
DEPRECATION_01
|
|
8
|
+
} from './Common.js'
|
|
3
9
|
|
|
10
|
+
/**
|
|
11
|
+
* StreamingCapturePlugin
|
|
12
|
+
* @extends CapturePlugin
|
|
13
|
+
* @classdesc Class for invoking streaming-related methods
|
|
14
|
+
*/
|
|
4
15
|
class StreamingCapturePlugin extends CapturePlugin {
|
|
5
16
|
constructor (plugin, baseUrl = BASE_URL) {
|
|
6
17
|
super(plugin, baseUrl)
|
|
@@ -28,9 +39,9 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
28
39
|
* img.src = await camera.streamUrl()
|
|
29
40
|
* document.body.appendChild(img)
|
|
30
41
|
*/
|
|
31
|
-
async streamUrl (deviceOpt) {
|
|
42
|
+
async streamUrl (streamOpt = {}, deviceOpt) {
|
|
32
43
|
const device = await this.setupDevice(deviceOpt)
|
|
33
|
-
return device.streamUrl()
|
|
44
|
+
return device.streamUrl(streamOpt)
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
/**
|
|
@@ -47,26 +58,8 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
47
58
|
* @see {@link CapturePlugin#streamUrl}
|
|
48
59
|
* @see {@link CapturePlugin#stopFeed}
|
|
49
60
|
*
|
|
50
|
-
* @param {
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* The default value of 'buffer' will load the image into an
|
|
54
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
|
|
55
|
-
* that can be set directly on an img tag's src attribute.
|
|
56
|
-
*
|
|
57
|
-
* The value of 'blob' will return a
|
|
58
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
59
|
-
* be used with a
|
|
60
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
61
|
-
*
|
|
62
|
-
* The value of 'base64' will return the image contents as a
|
|
63
|
-
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
64
|
-
* suitable for use with JSON serialization.
|
|
65
|
-
*
|
|
66
|
-
* The value of 'dataurl' will return a JPEG
|
|
67
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
68
|
-
* that can be set on an img tag's src attribute or loaded as a document
|
|
69
|
-
* location.
|
|
61
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
62
|
+
* photo.
|
|
70
63
|
*
|
|
71
64
|
* @param {string|object} [deviceOpt] - Return the frame from either a
|
|
72
65
|
* specific Device ID or a Device Object. The default, if not supplied, is the
|
|
@@ -84,24 +77,39 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
84
77
|
* // Stop the live feed when done getting frames
|
|
85
78
|
* await camera.stopFeed()
|
|
86
79
|
*/
|
|
87
|
-
async getMostRecentFrame (
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
async getMostRecentFrame (captureOpt = {}, deviceOpt) {
|
|
81
|
+
if (typeof captureOpt === 'string' && DEPRECATION_01) {
|
|
82
|
+
captureOpt = { kind: captureOpt }
|
|
83
|
+
console.warn('CaptureBridge SDK Deprecation Warning: ' +
|
|
84
|
+
'`StreamingCapturePlugin.getMostRecentFrame()` converted the ' +
|
|
85
|
+
'`captureOpt` argument from a string (%s) to an object (%s). This ' +
|
|
86
|
+
'conversion may not be performed in future SDK versions.',
|
|
87
|
+
captureOpt.kind, JSON.stringify(captureOpt))
|
|
88
|
+
}
|
|
89
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
90
|
+
const device = await this.setupDevice(mergedOpt)
|
|
91
|
+
switch (mergedOpt.kind) {
|
|
92
|
+
case 'objecturl':
|
|
93
|
+
return URL.createObjectURL(await device.frameAsBlob(mergedOpt))
|
|
90
94
|
case 'blob':
|
|
91
|
-
return await device.frameAsBlob()
|
|
95
|
+
return await device.frameAsBlob(mergedOpt)
|
|
92
96
|
case 'buffer':
|
|
93
|
-
return await blobToBuffer(await device.frameAsBlob())
|
|
97
|
+
return await blobToBuffer(await device.frameAsBlob(mergedOpt))
|
|
94
98
|
case 'base64':
|
|
95
|
-
return await device.frameAsBase64()
|
|
99
|
+
return await device.frameAsBase64(mergedOpt)
|
|
96
100
|
case 'dataurl':
|
|
97
|
-
return DATAURL_JPEG + (await device.frameAsBase64())
|
|
101
|
+
return DATAURL_JPEG + (await device.frameAsBase64(mergedOpt))
|
|
98
102
|
}
|
|
99
|
-
throw new Error(`Unknown image response
|
|
103
|
+
throw new Error(`Unknown image response kind: ${mergedOpt.kind}`)
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Stop the camera's live feed if it is running.
|
|
104
108
|
*
|
|
109
|
+
* @param {string|object} [deviceOpt] - Stop the feed for a specific Device ID
|
|
110
|
+
* or a Device Object. The default, if not supplied, is the first available
|
|
111
|
+
* device.
|
|
112
|
+
*
|
|
105
113
|
* @method
|
|
106
114
|
* @async
|
|
107
115
|
* @returns {object} Status of the stop operation
|
package/TopazSigGem.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BASE_URL } from './Common.js'
|
|
|
5
5
|
* TopazSigGem
|
|
6
6
|
* @classdesc Convience class for instantiating a Topaz SigGem Signature Tablet
|
|
7
7
|
* Inherits all methods on the {@link SignatureTablet} class.
|
|
8
|
-
*
|
|
8
|
+
* @extends SignatureTablet
|
|
9
9
|
* @see {@link SignatureTablet}
|
|
10
10
|
*/
|
|
11
11
|
class TopazSigGem extends SignatureTablet {
|