@capturebridge/sdk 0.7.0 → 0.7.1
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 +68 -68
- package/CanonCamera.js +25 -25
- package/CaptureBridge.js +162 -162
- package/CapturePlugin.js +79 -79
- package/Common.js +98 -98
- package/Device.js +451 -451
- package/ICAO.js +70 -70
- package/IFace.js +274 -274
- package/Logs.js +129 -129
- package/MockCamera.js +10 -10
- package/Plugin.js +298 -298
- package/Scanner.js +64 -64
- package/SignatureTablet.js +109 -109
- package/SignatureTabletWidgets.js +153 -153
- package/StreamingCapturePlugin.js +121 -121
- package/TopazSigGem.js +25 -25
- package/package.json +1 -1
package/CapturePlugin.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import Plugin from './Plugin.js'
|
|
2
|
-
import { BASE_URL, DATAURL_JPEG, blobToBuffer } from './Common.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CapturePlugin
|
|
6
|
-
* @classdesc Class for working with a plugin that acquires high resolution
|
|
7
|
-
* images from a device.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link Camera}
|
|
10
|
-
* @see {@link SignatureTablet}
|
|
11
|
-
* @see {@link Scanner}
|
|
12
|
-
*/
|
|
13
|
-
class CapturePlugin extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* Instantiate a CapturePlugin
|
|
16
|
-
* @constructor
|
|
17
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
18
|
-
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
19
|
-
* camera instance. The plugin must support the "start_feed", "stop_feed",
|
|
20
|
-
* "devices", and "capture" methods.
|
|
21
|
-
* @example
|
|
22
|
-
* const capture = new CapturePlugin('capture_camera_canon')
|
|
23
|
-
*/
|
|
24
|
-
constructor (plugin, baseUrl = BASE_URL) {
|
|
25
|
-
super(plugin, baseUrl)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Take a full capture
|
|
30
|
-
* @param {string} [kind=buffer] - Specify how to return the captured image. Valid
|
|
31
|
-
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
32
|
-
*
|
|
33
|
-
* The default value of 'buffer' will load the image into an
|
|
34
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
|
|
35
|
-
* that can be set directly on an img tag's src attribute.
|
|
36
|
-
*
|
|
37
|
-
* The value of 'blob' will return a
|
|
38
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
39
|
-
* be used with a
|
|
40
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
41
|
-
*
|
|
42
|
-
* The value of 'base64' will return the image contents as a
|
|
43
|
-
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
44
|
-
* suitable for use with JSON serialization.
|
|
45
|
-
*
|
|
46
|
-
* The value of 'dataurl' will return a JPEG
|
|
47
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
48
|
-
* that can be set on an img tag's src attribute or loaded as a document
|
|
49
|
-
* location.
|
|
50
|
-
*
|
|
51
|
-
* @param {string|object} [deviceOpt] - Take the capture using either a
|
|
52
|
-
* specific Device ID or a Device Object. The default is the first available
|
|
53
|
-
* device.
|
|
54
|
-
*
|
|
55
|
-
* @async
|
|
56
|
-
* @example
|
|
57
|
-
* // Capture an image as an ArrayBuffer and add it to an img tag appended to
|
|
58
|
-
* // the document's body.
|
|
59
|
-
* const img = document.createElement('img')
|
|
60
|
-
* img.src = await capture.fullCapture()
|
|
61
|
-
* document.body.appendChild(img)
|
|
62
|
-
*/
|
|
63
|
-
async fullCapture (kind = 'buffer', deviceOpt) {
|
|
64
|
-
const device = await this.setupDevice(deviceOpt)
|
|
65
|
-
switch (kind) {
|
|
66
|
-
case 'blob':
|
|
67
|
-
return await device.captureAsBlob()
|
|
68
|
-
case 'buffer':
|
|
69
|
-
return await blobToBuffer(await device.captureAsBlob())
|
|
70
|
-
case 'base64':
|
|
71
|
-
return await device.captureAsBase64()
|
|
72
|
-
case 'dataurl':
|
|
73
|
-
return DATAURL_JPEG + (await device.captureAsBase64())
|
|
74
|
-
}
|
|
75
|
-
throw new Error(`Unknown image response type: ${kind}`)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default CapturePlugin
|
|
1
|
+
import Plugin from './Plugin.js'
|
|
2
|
+
import { BASE_URL, DATAURL_JPEG, blobToBuffer } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CapturePlugin
|
|
6
|
+
* @classdesc Class for working with a plugin that acquires high resolution
|
|
7
|
+
* images from a device.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link Camera}
|
|
10
|
+
* @see {@link SignatureTablet}
|
|
11
|
+
* @see {@link Scanner}
|
|
12
|
+
*/
|
|
13
|
+
class CapturePlugin extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* Instantiate a CapturePlugin
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
18
|
+
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
19
|
+
* camera instance. The plugin must support the "start_feed", "stop_feed",
|
|
20
|
+
* "devices", and "capture" methods.
|
|
21
|
+
* @example
|
|
22
|
+
* const capture = new CapturePlugin('capture_camera_canon')
|
|
23
|
+
*/
|
|
24
|
+
constructor (plugin, baseUrl = BASE_URL) {
|
|
25
|
+
super(plugin, baseUrl)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Take a full capture
|
|
30
|
+
* @param {string} [kind=buffer] - Specify how to return the captured image. Valid
|
|
31
|
+
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
32
|
+
*
|
|
33
|
+
* The default value of 'buffer' will load the image into an
|
|
34
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
|
|
35
|
+
* that can be set directly on an img tag's src attribute.
|
|
36
|
+
*
|
|
37
|
+
* The value of 'blob' will return a
|
|
38
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
39
|
+
* be used with a
|
|
40
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
41
|
+
*
|
|
42
|
+
* The value of 'base64' will return the image contents as a
|
|
43
|
+
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
44
|
+
* suitable for use with JSON serialization.
|
|
45
|
+
*
|
|
46
|
+
* The value of 'dataurl' will return a JPEG
|
|
47
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
48
|
+
* that can be set on an img tag's src attribute or loaded as a document
|
|
49
|
+
* location.
|
|
50
|
+
*
|
|
51
|
+
* @param {string|object} [deviceOpt] - Take the capture using either a
|
|
52
|
+
* specific Device ID or a Device Object. The default is the first available
|
|
53
|
+
* device.
|
|
54
|
+
*
|
|
55
|
+
* @async
|
|
56
|
+
* @example
|
|
57
|
+
* // Capture an image as an ArrayBuffer and add it to an img tag appended to
|
|
58
|
+
* // the document's body.
|
|
59
|
+
* const img = document.createElement('img')
|
|
60
|
+
* img.src = await capture.fullCapture()
|
|
61
|
+
* document.body.appendChild(img)
|
|
62
|
+
*/
|
|
63
|
+
async fullCapture (kind = 'buffer', deviceOpt) {
|
|
64
|
+
const device = await this.setupDevice(deviceOpt)
|
|
65
|
+
switch (kind) {
|
|
66
|
+
case 'blob':
|
|
67
|
+
return await device.captureAsBlob()
|
|
68
|
+
case 'buffer':
|
|
69
|
+
return await blobToBuffer(await device.captureAsBlob())
|
|
70
|
+
case 'base64':
|
|
71
|
+
return await device.captureAsBase64()
|
|
72
|
+
case 'dataurl':
|
|
73
|
+
return DATAURL_JPEG + (await device.captureAsBase64())
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`Unknown image response type: ${kind}`)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default CapturePlugin
|
package/Common.js
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default base URL for making API requests.
|
|
3
|
-
* @constant
|
|
4
|
-
* @type {string}
|
|
5
|
-
* @default https://capture.local.valididcloud.com:9001
|
|
6
|
-
*/
|
|
7
|
-
export const BASE_URL = 'https://capture.local.valididcloud.com:9001'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
11
|
-
* options for making
|
|
12
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST|POST}
|
|
13
|
-
* requests to the API.
|
|
14
|
-
* @constant
|
|
15
|
-
* @type {string}
|
|
16
|
-
*/
|
|
17
|
-
export const POST = {
|
|
18
|
-
mode: 'cors',
|
|
19
|
-
method: 'post'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
24
|
-
* options for making
|
|
25
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE|DELETE}
|
|
26
|
-
* requests to the API.
|
|
27
|
-
* @constant
|
|
28
|
-
* @type {string}
|
|
29
|
-
*/
|
|
30
|
-
export const DELETE = {
|
|
31
|
-
mode: 'cors',
|
|
32
|
-
method: 'delete'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* `data:` prefix for JPEG
|
|
37
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
38
|
-
* @constant
|
|
39
|
-
* @type {string}
|
|
40
|
-
*/
|
|
41
|
-
export const DATAURL_JPEG = 'data:image/jpeg;base64,'
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* `data:` prefix for PNG
|
|
45
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
46
|
-
* @constant
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
export const DATAURL_PNG = 'data:image/png;base64,'
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* An Async/Await version of
|
|
53
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout|setTimeout}
|
|
54
|
-
* @private
|
|
55
|
-
*/
|
|
56
|
-
export const timeout = millis => {
|
|
57
|
-
return new Promise(resolve => setTimeout(resolve, millis))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Convert a Blob to a Buffer
|
|
62
|
-
* @private
|
|
63
|
-
*/
|
|
64
|
-
export const blobToBuffer = blob => {
|
|
65
|
-
return new Promise(resolve => {
|
|
66
|
-
const reader = new window.FileReader()
|
|
67
|
-
reader.onload = event => resolve(event.target.result)
|
|
68
|
-
reader.readAsArrayBuffer(blob)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Convert a Blob to a Base64 String
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
export const blobToBase64 = blob => {
|
|
77
|
-
return new Promise(resolve => {
|
|
78
|
-
const reader = new window.FileReader()
|
|
79
|
-
reader.onload = event => resolve(event.target.result.split(',')[1])
|
|
80
|
-
reader.readAsDataURL(blob)
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Helper function for classes to easily add callback style support to their
|
|
86
|
-
* async/await methods.
|
|
87
|
-
* @private
|
|
88
|
-
*/
|
|
89
|
-
export const asyncToCallback = (thisValue, asyncFn, callback, ...params) => {
|
|
90
|
-
(async () => {
|
|
91
|
-
try {
|
|
92
|
-
const result = await asyncFn.call(thisValue, ...(params.length ? params : []))
|
|
93
|
-
callback(null, result)
|
|
94
|
-
} catch (ex) {
|
|
95
|
-
callback(ex)
|
|
96
|
-
}
|
|
97
|
-
})()
|
|
98
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Default base URL for making API requests.
|
|
3
|
+
* @constant
|
|
4
|
+
* @type {string}
|
|
5
|
+
* @default https://capture.local.valididcloud.com:9001
|
|
6
|
+
*/
|
|
7
|
+
export const BASE_URL = 'https://capture.local.valididcloud.com:9001'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
11
|
+
* options for making
|
|
12
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST|POST}
|
|
13
|
+
* requests to the API.
|
|
14
|
+
* @constant
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
export const POST = {
|
|
18
|
+
mode: 'cors',
|
|
19
|
+
method: 'post'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
24
|
+
* options for making
|
|
25
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE|DELETE}
|
|
26
|
+
* requests to the API.
|
|
27
|
+
* @constant
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
30
|
+
export const DELETE = {
|
|
31
|
+
mode: 'cors',
|
|
32
|
+
method: 'delete'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* `data:` prefix for JPEG
|
|
37
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
38
|
+
* @constant
|
|
39
|
+
* @type {string}
|
|
40
|
+
*/
|
|
41
|
+
export const DATAURL_JPEG = 'data:image/jpeg;base64,'
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `data:` prefix for PNG
|
|
45
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
46
|
+
* @constant
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
export const DATAURL_PNG = 'data:image/png;base64,'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* An Async/Await version of
|
|
53
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout|setTimeout}
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
export const timeout = millis => {
|
|
57
|
+
return new Promise(resolve => setTimeout(resolve, millis))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Convert a Blob to a Buffer
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
export const blobToBuffer = blob => {
|
|
65
|
+
return new Promise(resolve => {
|
|
66
|
+
const reader = new window.FileReader()
|
|
67
|
+
reader.onload = event => resolve(event.target.result)
|
|
68
|
+
reader.readAsArrayBuffer(blob)
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Convert a Blob to a Base64 String
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
export const blobToBase64 = blob => {
|
|
77
|
+
return new Promise(resolve => {
|
|
78
|
+
const reader = new window.FileReader()
|
|
79
|
+
reader.onload = event => resolve(event.target.result.split(',')[1])
|
|
80
|
+
reader.readAsDataURL(blob)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Helper function for classes to easily add callback style support to their
|
|
86
|
+
* async/await methods.
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
export const asyncToCallback = (thisValue, asyncFn, callback, ...params) => {
|
|
90
|
+
(async () => {
|
|
91
|
+
try {
|
|
92
|
+
const result = await asyncFn.call(thisValue, ...(params.length ? params : []))
|
|
93
|
+
callback(null, result)
|
|
94
|
+
} catch (ex) {
|
|
95
|
+
callback(ex)
|
|
96
|
+
}
|
|
97
|
+
})()
|
|
98
|
+
}
|