@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/Camera.js
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import StreamingCapturePlugin from './StreamingCapturePlugin.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BASE_URL,
|
|
4
|
+
DEFAULT_CAPTURE_OPT,
|
|
5
|
+
DEPRECATION_01,
|
|
6
|
+
asyncToCallback
|
|
7
|
+
} from './Common.js'
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Camera
|
|
6
11
|
* @classdesc Class for invoking methods on a Camera
|
|
7
|
-
*
|
|
12
|
+
* @extends StreamingCapturePlugin
|
|
8
13
|
* @see {@link CanonCamera}
|
|
9
14
|
*/
|
|
10
15
|
class Camera extends StreamingCapturePlugin {
|
|
11
16
|
/**
|
|
12
17
|
* Instantiate a Generic Camera
|
|
13
18
|
* @constructor
|
|
14
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
19
|
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
16
|
-
* camera instance. The plugin must support the
|
|
17
|
-
*
|
|
20
|
+
* camera instance. The plugin must support the `start_feed`, `stop_feed`,
|
|
21
|
+
* `devices`, and `capture` methods.
|
|
22
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
18
23
|
* @example
|
|
19
24
|
* const camera = new Camera('capture_camera_canon')
|
|
20
25
|
*/
|
|
@@ -24,44 +29,34 @@ class Camera extends StreamingCapturePlugin {
|
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
31
|
* Capture a photo
|
|
27
|
-
* @param {
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* The default value of 'buffer' will load the image into an
|
|
31
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
|
|
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.
|
|
47
|
-
*
|
|
32
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
33
|
+
* photo.
|
|
48
34
|
* @param {string|object} [deviceOpt] - Take the photo using either a specific
|
|
49
35
|
* Device ID or a Device Object. The default is the first available device.
|
|
50
36
|
*
|
|
51
37
|
* @async
|
|
52
38
|
* @example
|
|
53
|
-
* // Capture a photo as an
|
|
39
|
+
* // Capture a photo as an ObjectURL, add it to an img element and append to
|
|
54
40
|
* // the document's body.
|
|
55
41
|
* const img = document.createElement('img')
|
|
56
|
-
* img.src = await camera.takePhoto(
|
|
42
|
+
* img.src = await camera.takePhoto()
|
|
57
43
|
* document.body.appendChild(img)
|
|
58
44
|
*/
|
|
59
|
-
async takePhoto (
|
|
60
|
-
|
|
45
|
+
async takePhoto (captureOpt = {}, deviceOpt) {
|
|
46
|
+
if (typeof captureOpt === 'string' && DEPRECATION_01) {
|
|
47
|
+
captureOpt = { kind: captureOpt }
|
|
48
|
+
console.warn('CaptureBridge SDK Deprecation Warning: ' +
|
|
49
|
+
'`Camera.takePhoto()` converted the `captureOpt` argument from a ' +
|
|
50
|
+
'string (%s) to an object (%s). This conversion may not be performed ' +
|
|
51
|
+
'in future SDK versions.',
|
|
52
|
+
captureOpt.kind, JSON.stringify(captureOpt))
|
|
53
|
+
}
|
|
54
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
55
|
+
return await this.fullCapture(mergedOpt, deviceOpt)
|
|
61
56
|
}
|
|
62
57
|
|
|
63
|
-
takePhotoHandler (
|
|
64
|
-
asyncToCallback(this, this.fullCapture, callback,
|
|
58
|
+
takePhotoHandler (captureOpt = {}, deviceOpt, callback) {
|
|
59
|
+
asyncToCallback(this, this.fullCapture, callback, captureOpt, deviceOpt)
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
|
package/CanonCamera.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BASE_URL } from './Common.js'
|
|
|
5
5
|
* CanonCamera
|
|
6
6
|
* @classdesc Convenience class for instantiating a Canon Camera Object.
|
|
7
7
|
* Inherits all methods on the {@link Camera} class.
|
|
8
|
-
*
|
|
8
|
+
* @extends Camera
|
|
9
9
|
* @see {@link Camera}
|
|
10
10
|
*/
|
|
11
11
|
class CanonCamera extends Camera {
|
|
@@ -15,7 +15,7 @@ class CanonCamera extends Camera {
|
|
|
15
15
|
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
16
16
|
* @example
|
|
17
17
|
* const camera = new CanonCamera()
|
|
18
|
-
* const base64 = await camera.takePhoto('base64')
|
|
18
|
+
* const base64 = await camera.takePhoto({kind: 'base64'})
|
|
19
19
|
*/
|
|
20
20
|
constructor (baseUrl = BASE_URL) {
|
|
21
21
|
super('capture_camera_canon', baseUrl)
|
package/CaptureBridge.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Plugin from './Plugin.js'
|
|
2
|
-
import { BASE_URL, asyncToCallback } from './Common.js'
|
|
2
|
+
import { BASE_URL, asyncToCallback, checkResponse } from './Common.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Capture Bridge
|
|
@@ -24,7 +24,7 @@ class CaptureBridge {
|
|
|
24
24
|
* @method
|
|
25
25
|
* @async
|
|
26
26
|
* @returns {object} Service version info.
|
|
27
|
-
* @see {@link https://
|
|
27
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
28
28
|
* @example
|
|
29
29
|
* const captureBridge = new CaptureBridge()
|
|
30
30
|
* const {version} = await captureBridge.version()
|
|
@@ -38,7 +38,7 @@ class CaptureBridge {
|
|
|
38
38
|
/**
|
|
39
39
|
* Get service version info (Callback)
|
|
40
40
|
* @method
|
|
41
|
-
* @see {@link https://
|
|
41
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
42
42
|
* @param {function} callback - Invoked with two arguments. The first argument
|
|
43
43
|
* is an Error object (if an error occurred) or null. The second argument is
|
|
44
44
|
* the version info.
|
|
@@ -59,7 +59,7 @@ class CaptureBridge {
|
|
|
59
59
|
* Get service status information
|
|
60
60
|
* @method
|
|
61
61
|
* @async
|
|
62
|
-
* @see {@link https://
|
|
62
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
63
63
|
* @returns {object} Service status information.
|
|
64
64
|
* @example
|
|
65
65
|
* const captureBridge = new CaptureBridge()
|
|
@@ -74,7 +74,7 @@ class CaptureBridge {
|
|
|
74
74
|
/**
|
|
75
75
|
* Get service status information (Callback)
|
|
76
76
|
* @method
|
|
77
|
-
* @see {@link https://
|
|
77
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
78
78
|
* @param {function} callback - Invoked with two arguments. The first argument
|
|
79
79
|
* is an Error object (if an error occurred) or null. The second argument is
|
|
80
80
|
* the status info.
|
|
@@ -91,7 +91,7 @@ class CaptureBridge {
|
|
|
91
91
|
* Get all installed plugins
|
|
92
92
|
* @method
|
|
93
93
|
* @async
|
|
94
|
-
* @see {@link https://
|
|
94
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
95
95
|
* @see {@link Plugin}
|
|
96
96
|
* @returns {object[]} Array of {@link Plugin} objects.
|
|
97
97
|
* @example
|
|
@@ -106,7 +106,7 @@ class CaptureBridge {
|
|
|
106
106
|
/**
|
|
107
107
|
* Get all installed plugins (Callback)
|
|
108
108
|
* @method
|
|
109
|
-
* @see {@link https://
|
|
109
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
110
110
|
* @see {@link Plugin}
|
|
111
111
|
* @param {function} callback - Invoked with two arguments. The first argument
|
|
112
112
|
* is an Error object (if an error occurred) or null. The second argument is
|
|
@@ -123,7 +123,7 @@ class CaptureBridge {
|
|
|
123
123
|
* Get a single plugin by ID
|
|
124
124
|
* @method
|
|
125
125
|
* @async
|
|
126
|
-
* @see {@link https://
|
|
126
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
127
127
|
* @see {@link Plugin}
|
|
128
128
|
* @param {string} id - Plugin ID
|
|
129
129
|
* @returns {object?} {@link Plugin} object or null
|
|
@@ -131,18 +131,16 @@ class CaptureBridge {
|
|
|
131
131
|
* const plugin = await captureBridge.plugin('capture_camera_canon')
|
|
132
132
|
*/
|
|
133
133
|
async plugin (id) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const plugin = plugins.find(p => p.id === id)
|
|
139
|
-
return plugin ? new Plugin(plugin) : null
|
|
134
|
+
const response = await fetch(`${this.baseUrl}/plugin/${id}`)
|
|
135
|
+
await checkResponse(response)
|
|
136
|
+
const pluginJSON = await response.json()
|
|
137
|
+
return new Plugin(pluginJSON)
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
/**
|
|
143
141
|
* Get a single plugin by ID (Callback version).
|
|
144
142
|
* @method
|
|
145
|
-
* @see {@link https://
|
|
143
|
+
* @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
146
144
|
* @see {@link Plugin}
|
|
147
145
|
* @param {string} id - Plugin ID
|
|
148
146
|
* @param {function} callback - Invoked with two arguments. The first argument
|
package/CapturePlugin.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import Plugin from './Plugin.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BASE_URL,
|
|
4
|
+
DATAURL_JPEG,
|
|
5
|
+
DEFAULT_CAPTURE_OPT,
|
|
6
|
+
blobToBuffer
|
|
7
|
+
} from './Common.js'
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* CapturePlugin
|
|
6
11
|
* @classdesc Class for working with a plugin that acquires high resolution
|
|
7
12
|
* images from a device.
|
|
8
|
-
*
|
|
13
|
+
* @extends Plugin
|
|
9
14
|
* @see {@link Camera}
|
|
10
15
|
* @see {@link SignatureTablet}
|
|
11
16
|
* @see {@link Scanner}
|
|
@@ -16,8 +21,8 @@ class CapturePlugin extends Plugin {
|
|
|
16
21
|
* @constructor
|
|
17
22
|
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
18
23
|
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
19
|
-
* camera instance. The plugin must support the
|
|
20
|
-
*
|
|
24
|
+
* camera instance. The plugin must support the `start_feed`, `stop_feed`,
|
|
25
|
+
* `devices`, and `capture` methods.
|
|
21
26
|
* @example
|
|
22
27
|
* const capture = new CapturePlugin('capture_camera_canon')
|
|
23
28
|
*/
|
|
@@ -27,27 +32,8 @@ class CapturePlugin extends Plugin {
|
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* Take a full capture
|
|
30
|
-
* @param {
|
|
31
|
-
*
|
|
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
|
-
*
|
|
35
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing an
|
|
36
|
+
* image.
|
|
51
37
|
* @param {string|object} [deviceOpt] - Take the capture using either a
|
|
52
38
|
* specific Device ID or a Device Object. The default is the first available
|
|
53
39
|
* device.
|
|
@@ -60,19 +46,22 @@ class CapturePlugin extends Plugin {
|
|
|
60
46
|
* img.src = await capture.fullCapture()
|
|
61
47
|
* document.body.appendChild(img)
|
|
62
48
|
*/
|
|
63
|
-
async fullCapture (
|
|
49
|
+
async fullCapture (captureOpt = {}, deviceOpt) {
|
|
64
50
|
const device = await this.setupDevice(deviceOpt)
|
|
65
|
-
|
|
51
|
+
const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
|
|
52
|
+
switch (mergedOpt.kind) {
|
|
53
|
+
case 'objecturl':
|
|
54
|
+
return URL.createObjectURL(await device.captureAsBlob(mergedOpt))
|
|
66
55
|
case 'blob':
|
|
67
|
-
return await device.captureAsBlob()
|
|
56
|
+
return await device.captureAsBlob(mergedOpt)
|
|
68
57
|
case 'buffer':
|
|
69
|
-
return await blobToBuffer(await device.captureAsBlob())
|
|
58
|
+
return await blobToBuffer(await device.captureAsBlob(mergedOpt))
|
|
70
59
|
case 'base64':
|
|
71
|
-
return await device.captureAsBase64()
|
|
60
|
+
return await device.captureAsBase64(mergedOpt)
|
|
72
61
|
case 'dataurl':
|
|
73
|
-
return DATAURL_JPEG + (await device.captureAsBase64())
|
|
62
|
+
return DATAURL_JPEG + (await device.captureAsBase64(mergedOpt))
|
|
74
63
|
}
|
|
75
|
-
throw new Error(`Unknown image response
|
|
64
|
+
throw new Error(`Unknown image response kind: ${mergedOpt.kind}`)
|
|
76
65
|
}
|
|
77
66
|
}
|
|
78
67
|
|
package/Common.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default base URL for making API requests.
|
|
2
|
+
* @summary Default base URL for making API requests.
|
|
3
3
|
* @constant
|
|
4
4
|
* @type {string}
|
|
5
|
-
* @default https://
|
|
5
|
+
* @default {@link https://local.capturebridge.net:9001}
|
|
6
6
|
*/
|
|
7
|
-
export const BASE_URL = 'https://
|
|
7
|
+
export const BASE_URL = 'https://local.capturebridge.net:9001'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
@@ -12,7 +12,7 @@ export const BASE_URL = 'https://capture.local.valididcloud.com:9001'
|
|
|
12
12
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST|POST}
|
|
13
13
|
* requests to the API.
|
|
14
14
|
* @constant
|
|
15
|
-
* @type {
|
|
15
|
+
* @type {object}
|
|
16
16
|
*/
|
|
17
17
|
export const POST = {
|
|
18
18
|
mode: 'cors',
|
|
@@ -20,12 +20,13 @@ export const POST = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
+
* @summary
|
|
23
24
|
* Common {@link https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API|Fetch}
|
|
24
25
|
* options for making
|
|
25
26
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE|DELETE}
|
|
26
27
|
* requests to the API.
|
|
27
28
|
* @constant
|
|
28
|
-
* @type {
|
|
29
|
+
* @type {object}
|
|
29
30
|
*/
|
|
30
31
|
export const DELETE = {
|
|
31
32
|
mode: 'cors',
|
|
@@ -33,7 +34,69 @@ export const DELETE = {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
/**
|
|
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
|
|
37
100
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
38
101
|
* @constant
|
|
39
102
|
* @type {string}
|
|
@@ -41,7 +104,7 @@ export const DELETE = {
|
|
|
41
104
|
export const DATAURL_JPEG = 'data:image/jpeg;base64,'
|
|
42
105
|
|
|
43
106
|
/**
|
|
44
|
-
* `data:` prefix for PNG
|
|
107
|
+
* @summary `data:` prefix for PNG
|
|
45
108
|
* {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URLs}
|
|
46
109
|
* @constant
|
|
47
110
|
* @type {string}
|
|
@@ -96,3 +159,24 @@ export const asyncToCallback = (thisValue, asyncFn, callback, ...params) => {
|
|
|
96
159
|
}
|
|
97
160
|
})()
|
|
98
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
|