@capturebridge/sdk 0.7.1 → 0.9.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/CHANGELOG.md +22 -0
- package/Camera.js +27 -32
- package/CanonCamera.js +2 -2
- package/CaptureBridge.js +13 -15
- package/CapturePlugin.js +21 -32
- package/Common.js +129 -7
- package/Device.js +169 -25
- 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/Verifone.js +68 -0
- 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/verifone_minimal.html +23 -0
- package/examples/windows_scanner_minimal.html +32 -0
- package/package.json +2 -2
package/Device.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
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
|
+
urlParamsToString
|
|
11
|
+
} from './Common.js'
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* Device
|
|
@@ -33,12 +43,27 @@ class Device {
|
|
|
33
43
|
Object.assign(this, {}, properties)
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Will throw an exception if a plugin cannot perform the provided RPC command
|
|
48
|
+
* @param {string} method - The JSON RPC method to check.
|
|
49
|
+
*/
|
|
36
50
|
can (method) {
|
|
37
51
|
if (this.plugin.methods.indexOf(method) === -1) {
|
|
38
52
|
throw new Error(`${method} not supported for this device`)
|
|
39
53
|
}
|
|
40
54
|
}
|
|
41
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Will throw an exception if the plugin cannot performa at least one of the
|
|
58
|
+
* provided JSON RPC commandss
|
|
59
|
+
* @param {string[]} methods - The JSON RPC methods to check.
|
|
60
|
+
*/
|
|
61
|
+
canDoOne (methods) {
|
|
62
|
+
if (!methods.some(m => this.plugin.methods.includes(m))) {
|
|
63
|
+
throw new Error(`Device does not support any of the methods: ${methods.join(',')}`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
42
67
|
/**
|
|
43
68
|
* Get the stream endpoint URL.
|
|
44
69
|
*
|
|
@@ -50,16 +75,57 @@ class Device {
|
|
|
50
75
|
* for any reason, the live feed will automatically be stopped.
|
|
51
76
|
*
|
|
52
77
|
* @method
|
|
78
|
+
* @param {StreamOptions} [streamOpt] - Additional options for streaming.
|
|
53
79
|
* @returns {string} stream endpoint URL
|
|
54
80
|
* @example
|
|
55
81
|
* const img = document.createElement('img')
|
|
56
82
|
* img.src = device.streamUrl()
|
|
57
83
|
* document.body.appendChild(img)
|
|
58
84
|
*/
|
|
59
|
-
streamUrl () {
|
|
85
|
+
streamUrl (streamOpt = {}) {
|
|
60
86
|
this.can('start_feed')
|
|
61
87
|
this.can('stop_feed')
|
|
62
|
-
|
|
88
|
+
const mergedOpts = Object.assign({}, DEFAULT_STREAM_OPT, streamOpt)
|
|
89
|
+
const params = new URLSearchParams(mergedOpts).toString()
|
|
90
|
+
return `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/stream?${params}`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Take full capture from the specified device and return an
|
|
95
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static|ObjectURL}
|
|
96
|
+
* that can be set directly on an img tag's src attribute. Note that URLs
|
|
97
|
+
* created by this method should be
|
|
98
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static|revoked}
|
|
99
|
+
* when they are no longer needed.
|
|
100
|
+
* (Async/Await version)
|
|
101
|
+
*
|
|
102
|
+
* @method
|
|
103
|
+
* @async
|
|
104
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
105
|
+
* frame.
|
|
106
|
+
* @returns {string}
|
|
107
|
+
* @example
|
|
108
|
+
* // Load the blob into FileReader and append to the document's body
|
|
109
|
+
* const blob = await device.captureAsBlob()
|
|
110
|
+
* const reader = new FileReader()
|
|
111
|
+
* reader.onload = event => {
|
|
112
|
+
* const img = document.createElement('img')
|
|
113
|
+
* img.src = event.target.result
|
|
114
|
+
* document.body.appendChild(img)
|
|
115
|
+
* }
|
|
116
|
+
* reader.readAsDataURL(blob)
|
|
117
|
+
*/
|
|
118
|
+
async captureAsObjectURL (captureOpt = {}) {
|
|
119
|
+
this.can('capture')
|
|
120
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
121
|
+
|
|
122
|
+
// Method ignores kind, always returns an object URL
|
|
123
|
+
delete captureParams.kind
|
|
124
|
+
|
|
125
|
+
const params = urlParamsToString(captureParams)
|
|
126
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
127
|
+
const response = await fetch(url, POST)
|
|
128
|
+
return await response.blob()
|
|
63
129
|
}
|
|
64
130
|
|
|
65
131
|
/**
|
|
@@ -70,6 +136,8 @@ class Device {
|
|
|
70
136
|
*
|
|
71
137
|
* @method
|
|
72
138
|
* @async
|
|
139
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
140
|
+
* frame.
|
|
73
141
|
* @returns {object} {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob}
|
|
74
142
|
* @example
|
|
75
143
|
* // Load the blob into FileReader and append to the document's body
|
|
@@ -82,9 +150,15 @@ class Device {
|
|
|
82
150
|
* }
|
|
83
151
|
* reader.readAsDataURL(blob)
|
|
84
152
|
*/
|
|
85
|
-
async captureAsBlob () {
|
|
153
|
+
async captureAsBlob (captureOpt = {}) {
|
|
86
154
|
this.can('capture')
|
|
87
|
-
const
|
|
155
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
156
|
+
|
|
157
|
+
// Method ignores kind, always returns binary data (blob)
|
|
158
|
+
delete captureParams.kind
|
|
159
|
+
|
|
160
|
+
const params = urlParamsToString(captureParams)
|
|
161
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
88
162
|
const response = await fetch(url, POST)
|
|
89
163
|
return await response.blob()
|
|
90
164
|
}
|
|
@@ -96,7 +170,9 @@ class Device {
|
|
|
96
170
|
* (Callback version)
|
|
97
171
|
*
|
|
98
172
|
* @method
|
|
99
|
-
* @param {function} callback
|
|
173
|
+
* @param {function} callback
|
|
174
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
175
|
+
* frame.
|
|
100
176
|
* @example
|
|
101
177
|
* // Load the blob into FileReader and append to the document's body
|
|
102
178
|
* device.captureAsBlobHandler((error, blob) => {
|
|
@@ -109,8 +185,8 @@ class Device {
|
|
|
109
185
|
* reader.readAsDataURL(blob)
|
|
110
186
|
* })
|
|
111
187
|
*/
|
|
112
|
-
captureAsBlobHandler (callback) {
|
|
113
|
-
asyncToCallback(this, this.captureAsBlob, callback)
|
|
188
|
+
captureAsBlobHandler (callback, captureOpt = {}) {
|
|
189
|
+
asyncToCallback(this, this.captureAsBlob, captureOpt, callback)
|
|
114
190
|
}
|
|
115
191
|
|
|
116
192
|
/**
|
|
@@ -121,6 +197,8 @@ class Device {
|
|
|
121
197
|
*
|
|
122
198
|
* @method
|
|
123
199
|
* @async
|
|
200
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
201
|
+
* frame.
|
|
124
202
|
* @returns {string} Base64 Encoded image
|
|
125
203
|
* @example
|
|
126
204
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -130,10 +208,18 @@ class Device {
|
|
|
130
208
|
* img.src = 'data:image/jpeg;base64,' + base64
|
|
131
209
|
* document.body.appendChild(img)
|
|
132
210
|
*/
|
|
133
|
-
async captureAsBase64 () {
|
|
211
|
+
async captureAsBase64 (captureOpt = {}) {
|
|
134
212
|
this.can('capture')
|
|
135
|
-
const
|
|
213
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
214
|
+
|
|
215
|
+
// Method ignores kind, always returns base64 data
|
|
216
|
+
delete captureParams.kind
|
|
217
|
+
captureParams.base64 = true
|
|
218
|
+
|
|
219
|
+
const params = urlParamsToString(captureParams)
|
|
220
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/capture?${params}`
|
|
136
221
|
const response = await fetch(url, POST)
|
|
222
|
+
await checkResponse(response)
|
|
137
223
|
const { image } = await response.json()
|
|
138
224
|
return image
|
|
139
225
|
}
|
|
@@ -144,9 +230,11 @@ class Device {
|
|
|
144
230
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
145
231
|
* (Callback version)
|
|
146
232
|
* @method
|
|
147
|
-
* @param {function} callback
|
|
233
|
+
* @param {function} callback
|
|
234
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
235
|
+
* frame.
|
|
148
236
|
*/
|
|
149
|
-
captureAsBase64Handler (callback) {
|
|
237
|
+
captureAsBase64Handler (callback, captureOpt = {}) {
|
|
150
238
|
asyncToCallback(this, this.captureAsBase64, callback)
|
|
151
239
|
}
|
|
152
240
|
|
|
@@ -171,6 +259,8 @@ class Device {
|
|
|
171
259
|
*
|
|
172
260
|
* @async
|
|
173
261
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
262
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
263
|
+
* frame.
|
|
174
264
|
* @returns {string} Base64 Encoded image
|
|
175
265
|
* @example
|
|
176
266
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -180,14 +270,21 @@ class Device {
|
|
|
180
270
|
* img.src = 'data:image/jpeg;base64,' + base64
|
|
181
271
|
* document.body.appendChild(img)
|
|
182
272
|
*/
|
|
183
|
-
async frameAsBase64 (millis =
|
|
273
|
+
async frameAsBase64 (captureOpt = {}, millis = 500) {
|
|
184
274
|
this.can('start_feed')
|
|
185
|
-
const
|
|
275
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
276
|
+
|
|
277
|
+
// Method ignores kind, always returns base64 data
|
|
278
|
+
delete captureParams.kind
|
|
279
|
+
captureParams.base64 = true
|
|
280
|
+
|
|
281
|
+
const params = urlParamsToString(captureParams)
|
|
282
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/livefeed?${params}`
|
|
186
283
|
const response = await fetch(url)
|
|
187
284
|
const result = await response.json()
|
|
188
285
|
if (result.error && (result.code === 425 || result.code === 400)) {
|
|
189
286
|
await timeout(millis)
|
|
190
|
-
return await this.frameAsBase64(millis)
|
|
287
|
+
return await this.frameAsBase64(captureOpt, millis)
|
|
191
288
|
} else {
|
|
192
289
|
return result.image
|
|
193
290
|
}
|
|
@@ -212,7 +309,9 @@ class Device {
|
|
|
212
309
|
* @see {@link streamUrl}
|
|
213
310
|
* @see {@link setStopFeed}
|
|
214
311
|
*
|
|
215
|
-
* @param {function} callback
|
|
312
|
+
* @param {function} callback
|
|
313
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
314
|
+
* frame.
|
|
216
315
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
217
316
|
* @example
|
|
218
317
|
* // Add the base64 string as a Data URL to an img tag and append to
|
|
@@ -223,8 +322,8 @@ class Device {
|
|
|
223
322
|
* document.body.appendChild(img)
|
|
224
323
|
* })
|
|
225
324
|
*/
|
|
226
|
-
frameAsBase64Handler (callback, millis =
|
|
227
|
-
asyncToCallback(this, this.frameAsBase64, callback, millis)
|
|
325
|
+
frameAsBase64Handler (callback, captureOpt = {}, millis = 500) {
|
|
326
|
+
asyncToCallback(this, this.frameAsBase64, callback, captureOpt, millis)
|
|
228
327
|
}
|
|
229
328
|
|
|
230
329
|
/**
|
|
@@ -247,6 +346,8 @@ class Device {
|
|
|
247
346
|
* @see {@link stopFeed}
|
|
248
347
|
*
|
|
249
348
|
* @async
|
|
349
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
350
|
+
* frame.
|
|
250
351
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
251
352
|
* @returns {object} {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob}
|
|
252
353
|
* @example
|
|
@@ -260,10 +361,16 @@ class Device {
|
|
|
260
361
|
* }
|
|
261
362
|
* reader.readAsDataURL(blob)
|
|
262
363
|
*/
|
|
263
|
-
async frameAsBlob (millis =
|
|
364
|
+
async frameAsBlob (captureOpt = {}, millis = 500) {
|
|
264
365
|
this.can('start_feed')
|
|
265
|
-
const
|
|
266
|
-
|
|
366
|
+
const captureParams = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
367
|
+
|
|
368
|
+
// Method ignores kind, always returns binary data (blob)
|
|
369
|
+
delete captureParams.kind
|
|
370
|
+
|
|
371
|
+
const params = urlParamsToString(captureParams)
|
|
372
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/livefeed?${params}`
|
|
373
|
+
const result = await this.frameAsBase64(captureOpt, millis)
|
|
267
374
|
if (typeof result === 'string') {
|
|
268
375
|
timeout(millis)
|
|
269
376
|
const response = await fetch(url)
|
|
@@ -291,8 +398,13 @@ class Device {
|
|
|
291
398
|
* @see {@link streamUrl}
|
|
292
399
|
* @see {@link setStopFeed}
|
|
293
400
|
*
|
|
294
|
-
* @param {function} callback
|
|
401
|
+
* @param {function} callback
|
|
402
|
+
*
|
|
403
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
404
|
+
* frame.
|
|
405
|
+
*
|
|
295
406
|
* @param {number} [millis] - Milliseconds to wait if feed is not ready
|
|
407
|
+
*
|
|
296
408
|
* @example
|
|
297
409
|
* // Load the blob into FileReader and append to the document's body
|
|
298
410
|
* device.frameAsBlobHandler((error, blob) => {
|
|
@@ -305,8 +417,8 @@ class Device {
|
|
|
305
417
|
* reader.readAsDataURL(blob)
|
|
306
418
|
* })
|
|
307
419
|
*/
|
|
308
|
-
frameAsBlobHandler (callback, millis =
|
|
309
|
-
asyncToCallback(this, this.frameAsBlob, callback, millis)
|
|
420
|
+
frameAsBlobHandler (callback, captureOpt = {}, millis = 500) {
|
|
421
|
+
asyncToCallback(this, this.frameAsBlob, callback, captureOpt, millis)
|
|
310
422
|
}
|
|
311
423
|
|
|
312
424
|
/**
|
|
@@ -363,7 +475,7 @@ class Device {
|
|
|
363
475
|
* console.log(await await device.clear())
|
|
364
476
|
*/
|
|
365
477
|
async clear (backlight) {
|
|
366
|
-
this.
|
|
478
|
+
this.canDoOne(['draw', 'clear'])
|
|
367
479
|
let url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/display`
|
|
368
480
|
if (typeof backlight === 'boolean') {
|
|
369
481
|
url += `?backlight=${backlight}`
|
|
@@ -446,6 +558,38 @@ class Device {
|
|
|
446
558
|
async displayObjectsHandler (objects, clear = true, callback) {
|
|
447
559
|
asyncToCallback(this, this.displayObjects, callback, objects, clear)
|
|
448
560
|
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Get detailed information about a device
|
|
564
|
+
*
|
|
565
|
+
* @description Returns detailed information about a device.
|
|
566
|
+
*
|
|
567
|
+
* @async
|
|
568
|
+
* @method
|
|
569
|
+
* @returns {object} Device info
|
|
570
|
+
* @example
|
|
571
|
+
* const info = await device.info()
|
|
572
|
+
*/
|
|
573
|
+
async info () {
|
|
574
|
+
this.can('device_info')
|
|
575
|
+
const url = `${this.baseUrl}/plugin/${this.plugin.id}/device/${this.id}/info`
|
|
576
|
+
const response = await fetch(url)
|
|
577
|
+
return await response.json()
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Get detailed information about a device
|
|
582
|
+
*
|
|
583
|
+
* @description Returns detailed information about a device.
|
|
584
|
+
*
|
|
585
|
+
* @method
|
|
586
|
+
* @returns {object} Device info
|
|
587
|
+
* @example
|
|
588
|
+
* const info = await device.info()
|
|
589
|
+
*/
|
|
590
|
+
async infoHandler (callback) {
|
|
591
|
+
asyncToCallback(this, this.info, callback)
|
|
592
|
+
}
|
|
449
593
|
}
|
|
450
594
|
|
|
451
595
|
export default Device
|
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 {
|