@capturebridge/sdk 0.7.0 → 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 +63 -68
- package/CanonCamera.js +25 -25
- package/CaptureBridge.js +160 -162
- package/CapturePlugin.js +68 -79
- package/Common.js +182 -98
- package/Device.js +547 -451
- package/ICAO.js +70 -70
- package/IFace.js +278 -274
- package/Logs.js +129 -129
- package/MockCamera.js +17 -10
- package/Plugin.js +299 -298
- package/Scanner.js +55 -64
- package/SignatureTablet.js +108 -109
- package/SignatureTabletWidgets.js +164 -153
- package/StreamingCapturePlugin.js +129 -121
- package/TopazSigGem.js +25 -25
- 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/CapturePlugin.js
CHANGED
|
@@ -1,79 +1,68 @@
|
|
|
1
|
-
import Plugin from './Plugin.js'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
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 {
|
|
3
|
+
BASE_URL,
|
|
4
|
+
DATAURL_JPEG,
|
|
5
|
+
DEFAULT_CAPTURE_OPT,
|
|
6
|
+
blobToBuffer
|
|
7
|
+
} from './Common.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* CapturePlugin
|
|
11
|
+
* @classdesc Class for working with a plugin that acquires high resolution
|
|
12
|
+
* images from a device.
|
|
13
|
+
* @extends Plugin
|
|
14
|
+
* @see {@link Camera}
|
|
15
|
+
* @see {@link SignatureTablet}
|
|
16
|
+
* @see {@link Scanner}
|
|
17
|
+
*/
|
|
18
|
+
class CapturePlugin extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* Instantiate a CapturePlugin
|
|
21
|
+
* @constructor
|
|
22
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
23
|
+
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
24
|
+
* camera instance. The plugin must support the `start_feed`, `stop_feed`,
|
|
25
|
+
* `devices`, and `capture` methods.
|
|
26
|
+
* @example
|
|
27
|
+
* const capture = new CapturePlugin('capture_camera_canon')
|
|
28
|
+
*/
|
|
29
|
+
constructor (plugin, baseUrl = BASE_URL) {
|
|
30
|
+
super(plugin, baseUrl)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Take a full capture
|
|
35
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing an
|
|
36
|
+
* image.
|
|
37
|
+
* @param {string|object} [deviceOpt] - Take the capture using either a
|
|
38
|
+
* specific Device ID or a Device Object. The default is the first available
|
|
39
|
+
* device.
|
|
40
|
+
*
|
|
41
|
+
* @async
|
|
42
|
+
* @example
|
|
43
|
+
* // Capture an image as an ArrayBuffer and add it to an img tag appended to
|
|
44
|
+
* // the document's body.
|
|
45
|
+
* const img = document.createElement('img')
|
|
46
|
+
* img.src = await capture.fullCapture()
|
|
47
|
+
* document.body.appendChild(img)
|
|
48
|
+
*/
|
|
49
|
+
async fullCapture (captureOpt = {}, deviceOpt) {
|
|
50
|
+
const device = await this.setupDevice(deviceOpt)
|
|
51
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
52
|
+
switch (mergedOpt.kind) {
|
|
53
|
+
case 'objecturl':
|
|
54
|
+
return URL.createObjectURL(await device.captureAsBlob(mergedOpt))
|
|
55
|
+
case 'blob':
|
|
56
|
+
return await device.captureAsBlob(mergedOpt)
|
|
57
|
+
case 'buffer':
|
|
58
|
+
return await blobToBuffer(await device.captureAsBlob(mergedOpt))
|
|
59
|
+
case 'base64':
|
|
60
|
+
return await device.captureAsBase64(mergedOpt)
|
|
61
|
+
case 'dataurl':
|
|
62
|
+
return DATAURL_JPEG + (await device.captureAsBase64(mergedOpt))
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Unknown image response kind: ${mergedOpt.kind}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default CapturePlugin
|
package/Common.js
CHANGED
|
@@ -1,98 +1,182 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default base URL for making API requests.
|
|
3
|
-
* @constant
|
|
4
|
-
* @type {string}
|
|
5
|
-
* @default https://
|
|
6
|
-
*/
|
|
7
|
-
export const BASE_URL = 'https://
|
|
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 {
|
|
16
|
-
*/
|
|
17
|
-
export const POST = {
|
|
18
|
-
mode: 'cors',
|
|
19
|
-
method: 'post'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
*
|
|
38
|
-
* @constant
|
|
39
|
-
* @
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @summary Default base URL for making API requests.
|
|
3
|
+
* @constant
|
|
4
|
+
* @type {string}
|
|
5
|
+
* @default {@link https://local.capturebridge.net:9001}
|
|
6
|
+
*/
|
|
7
|
+
export const BASE_URL = 'https://local.capturebridge.net: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 {object}
|
|
16
|
+
*/
|
|
17
|
+
export const POST = {
|
|
18
|
+
mode: 'cors',
|
|
19
|
+
method: 'post'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @summary
|
|
24
|
+
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
25
|
+
* options for making
|
|
26
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE|DELETE}
|
|
27
|
+
* requests to the API.
|
|
28
|
+
* @constant
|
|
29
|
+
* @type {object}
|
|
30
|
+
*/
|
|
31
|
+
export const DELETE = {
|
|
32
|
+
mode: 'cors',
|
|
33
|
+
method: 'delete'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @summary Default options for stream operations
|
|
38
|
+
* @constant
|
|
39
|
+
* @property {number} rotate - Angle, in degrees to rotate the stream. Must be
|
|
40
|
+
* a value from -359 to 359. A value outside of that range, or a 0 will perform
|
|
41
|
+
* no rotation.
|
|
42
|
+
* @typedef {object} StreamOptions
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_STREAM_OPT = {
|
|
45
|
+
rotate: 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @typedef {string} CaptureResponseKind
|
|
50
|
+
* @summary Specifies the desired return type for a captured object. Valid
|
|
51
|
+
* values are `objecturl`, `blob`, `buffer`, `base64`, or `dataurl`.
|
|
52
|
+
*
|
|
53
|
+
* - `objecturl` will load the captured object into an
|
|
54
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static|ObjectURL}
|
|
55
|
+
* that can be set directly on an img tag's src attribute. Note that these URLs
|
|
56
|
+
* should be {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static|revoked}
|
|
57
|
+
* when they are no longer needed.
|
|
58
|
+
*
|
|
59
|
+
* - `buffer` will load the image into an
|
|
60
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
|
|
61
|
+
*
|
|
62
|
+
* - `blob` will return a
|
|
63
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
|
|
64
|
+
* be used with a
|
|
65
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
|
|
66
|
+
*
|
|
67
|
+
* - `base64` will return the image contents as a
|
|
68
|
+
* {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
|
|
69
|
+
* suitable for use with JSON serialization.
|
|
70
|
+
*
|
|
71
|
+
* - `dataurl` will return a
|
|
72
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
|
|
73
|
+
* that can be set on an img tag's src attribute or loaded as a document
|
|
74
|
+
* location.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @summary Default options for capture operations.
|
|
80
|
+
* @constant
|
|
81
|
+
* @property {number?} rotate - Angle, in degrees to rotate the captured object.
|
|
82
|
+
* Must be a value from -359 to 359. A value of 0 will perform no rotation.
|
|
83
|
+
* @property {boolean?} base64 - Return the captured object as a base64 encoded
|
|
84
|
+
* string. The default behavior is to return the image as binary data.
|
|
85
|
+
* @property {CaptureResponseKind} kind - Specifies how to return the captured
|
|
86
|
+
* object. Some SDK methods that are designed to only return a particular type,
|
|
87
|
+
* such as {@link Device#frameAsBase64}, ignore this parameter. This parameter
|
|
88
|
+
* is also not sent in API requests, it is used internally by the SDK for
|
|
89
|
+
* constructing the appropriate response type.
|
|
90
|
+
* @typedef {object} CaptureOptions
|
|
91
|
+
*/
|
|
92
|
+
export const DEFAULT_CAPTURE_OPT = {
|
|
93
|
+
rotate: 0,
|
|
94
|
+
base64: false,
|
|
95
|
+
kind: 'objecturl'
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @summary `data:` prefix for JPEG
|
|
100
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
101
|
+
* @constant
|
|
102
|
+
* @type {string}
|
|
103
|
+
*/
|
|
104
|
+
export const DATAURL_JPEG = 'data:image/jpeg;base64,'
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @summary `data:` prefix for PNG
|
|
108
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
109
|
+
* @constant
|
|
110
|
+
* @type {string}
|
|
111
|
+
*/
|
|
112
|
+
export const DATAURL_PNG = 'data:image/png;base64,'
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* An Async/Await version of
|
|
116
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout|setTimeout}
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
export const timeout = millis => {
|
|
120
|
+
return new Promise(resolve => setTimeout(resolve, millis))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Convert a Blob to a Buffer
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
export const blobToBuffer = blob => {
|
|
128
|
+
return new Promise(resolve => {
|
|
129
|
+
const reader = new window.FileReader()
|
|
130
|
+
reader.onload = event => resolve(event.target.result)
|
|
131
|
+
reader.readAsArrayBuffer(blob)
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Convert a Blob to a Base64 String
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
export const blobToBase64 = blob => {
|
|
140
|
+
return new Promise(resolve => {
|
|
141
|
+
const reader = new window.FileReader()
|
|
142
|
+
reader.onload = event => resolve(event.target.result.split(',')[1])
|
|
143
|
+
reader.readAsDataURL(blob)
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Helper function for classes to easily add callback style support to their
|
|
149
|
+
* async/await methods.
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
export const asyncToCallback = (thisValue, asyncFn, callback, ...params) => {
|
|
153
|
+
(async () => {
|
|
154
|
+
try {
|
|
155
|
+
const result = await asyncFn.call(thisValue, ...(params.length ? params : []))
|
|
156
|
+
callback(null, result)
|
|
157
|
+
} catch (ex) {
|
|
158
|
+
callback(ex)
|
|
159
|
+
}
|
|
160
|
+
})()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Helper function to throw if an http response was a error.
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
export const checkResponse = async (response) => {
|
|
168
|
+
if (!response.ok) {
|
|
169
|
+
const error = await response.json()
|
|
170
|
+
const msg = error.message || error.summary || error.code || 'Unexpected error'
|
|
171
|
+
const ex = new Error(msg)
|
|
172
|
+
ex.code = error.code || 500
|
|
173
|
+
ex.summary = error.summary || 'Unexpected error'
|
|
174
|
+
throw ex
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Allows passing in a string for the response type of capture methods
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
export const DEPRECATION_01 = true
|