@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/Camera.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import StreamingCapturePlugin from './StreamingCapturePlugin.js'
|
|
2
|
-
import { BASE_URL, asyncToCallback } from './Common.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Camera
|
|
6
|
-
* @classdesc Class for invoking methods on a Camera
|
|
7
|
-
*
|
|
8
|
-
* @see {@link CanonCamera}
|
|
9
|
-
*/
|
|
10
|
-
class Camera extends StreamingCapturePlugin {
|
|
11
|
-
/**
|
|
12
|
-
* Instantiate a Generic Camera
|
|
13
|
-
* @constructor
|
|
14
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
|
-
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
16
|
-
* camera instance. The plugin must support the "start_feed", "stop_feed",
|
|
17
|
-
* "devices", and "capture" methods.
|
|
18
|
-
* @example
|
|
19
|
-
* const camera = new Camera('capture_camera_canon')
|
|
20
|
-
*/
|
|
21
|
-
constructor (pluginId, baseUrl = BASE_URL) {
|
|
22
|
-
super(pluginId, baseUrl)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Capture a photo
|
|
27
|
-
* @param {string} [kind] - Specify how to return the captured photo. Valid
|
|
28
|
-
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
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
|
-
*
|
|
48
|
-
* @param {string|object} [deviceOpt] - Take the photo using either a specific
|
|
49
|
-
* Device ID or a Device Object. The default is the first available device.
|
|
50
|
-
*
|
|
51
|
-
* @async
|
|
52
|
-
* @example
|
|
53
|
-
* // Capture a photo as an ArrayBuffer and add it to an img tag appended to
|
|
54
|
-
* // the document's body.
|
|
55
|
-
* const img = document.createElement('img')
|
|
56
|
-
* img.src = await camera.takePhoto('base64')
|
|
57
|
-
* document.body.appendChild(img)
|
|
58
|
-
*/
|
|
59
|
-
async takePhoto (kind = 'buffer', deviceOpt) {
|
|
60
|
-
return await this.fullCapture(kind, deviceOpt)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
takePhotoHandler (kind = 'buffer', deviceOpt, callback) {
|
|
64
|
-
asyncToCallback(this, this.fullCapture, callback, kind, deviceOpt)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default Camera
|
|
1
|
+
import StreamingCapturePlugin from './StreamingCapturePlugin.js'
|
|
2
|
+
import { BASE_URL, asyncToCallback } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Camera
|
|
6
|
+
* @classdesc Class for invoking methods on a Camera
|
|
7
|
+
*
|
|
8
|
+
* @see {@link CanonCamera}
|
|
9
|
+
*/
|
|
10
|
+
class Camera extends StreamingCapturePlugin {
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate a Generic Camera
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
|
+
* @param {string} pluginId - The Id of the desired plugin to use for this
|
|
16
|
+
* camera instance. The plugin must support the "start_feed", "stop_feed",
|
|
17
|
+
* "devices", and "capture" methods.
|
|
18
|
+
* @example
|
|
19
|
+
* const camera = new Camera('capture_camera_canon')
|
|
20
|
+
*/
|
|
21
|
+
constructor (pluginId, baseUrl = BASE_URL) {
|
|
22
|
+
super(pluginId, baseUrl)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Capture a photo
|
|
27
|
+
* @param {string} [kind] - Specify how to return the captured photo. Valid
|
|
28
|
+
* values are 'blob', 'buffer', 'base64', or 'dataurl'.
|
|
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
|
+
*
|
|
48
|
+
* @param {string|object} [deviceOpt] - Take the photo using either a specific
|
|
49
|
+
* Device ID or a Device Object. The default is the first available device.
|
|
50
|
+
*
|
|
51
|
+
* @async
|
|
52
|
+
* @example
|
|
53
|
+
* // Capture a photo as an ArrayBuffer and add it to an img tag appended to
|
|
54
|
+
* // the document's body.
|
|
55
|
+
* const img = document.createElement('img')
|
|
56
|
+
* img.src = await camera.takePhoto('base64')
|
|
57
|
+
* document.body.appendChild(img)
|
|
58
|
+
*/
|
|
59
|
+
async takePhoto (kind = 'buffer', deviceOpt) {
|
|
60
|
+
return await this.fullCapture(kind, deviceOpt)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
takePhotoHandler (kind = 'buffer', deviceOpt, callback) {
|
|
64
|
+
asyncToCallback(this, this.fullCapture, callback, kind, deviceOpt)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default Camera
|
package/CanonCamera.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import Camera from './Camera.js'
|
|
2
|
-
import { BASE_URL } from './Common.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* CanonCamera
|
|
6
|
-
* @classdesc Convenience class for instantiating a Canon Camera Object.
|
|
7
|
-
* Inherits all methods on the {@link Camera} class.
|
|
8
|
-
*
|
|
9
|
-
* @see {@link Camera}
|
|
10
|
-
*/
|
|
11
|
-
class CanonCamera extends Camera {
|
|
12
|
-
/**
|
|
13
|
-
* Instantiate a Canon Camera
|
|
14
|
-
* @constructor
|
|
15
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
16
|
-
* @example
|
|
17
|
-
* const camera = new CanonCamera()
|
|
18
|
-
* const base64 = await camera.takePhoto('base64')
|
|
19
|
-
*/
|
|
20
|
-
constructor (baseUrl = BASE_URL) {
|
|
21
|
-
super('capture_camera_canon', baseUrl)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default CanonCamera
|
|
1
|
+
import Camera from './Camera.js'
|
|
2
|
+
import { BASE_URL } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* CanonCamera
|
|
6
|
+
* @classdesc Convenience class for instantiating a Canon Camera Object.
|
|
7
|
+
* Inherits all methods on the {@link Camera} class.
|
|
8
|
+
*
|
|
9
|
+
* @see {@link Camera}
|
|
10
|
+
*/
|
|
11
|
+
class CanonCamera extends Camera {
|
|
12
|
+
/**
|
|
13
|
+
* Instantiate a Canon Camera
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
16
|
+
* @example
|
|
17
|
+
* const camera = new CanonCamera()
|
|
18
|
+
* const base64 = await camera.takePhoto('base64')
|
|
19
|
+
*/
|
|
20
|
+
constructor (baseUrl = BASE_URL) {
|
|
21
|
+
super('capture_camera_canon', baseUrl)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default CanonCamera
|
package/CaptureBridge.js
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
import Plugin from './Plugin.js'
|
|
2
|
-
import { BASE_URL, asyncToCallback } from './Common.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Capture Bridge
|
|
6
|
-
*
|
|
7
|
-
* @classdesc Class for interacting with the HTTP API's base methods.
|
|
8
|
-
*/
|
|
9
|
-
class CaptureBridge {
|
|
10
|
-
baseUrl
|
|
11
|
-
/**
|
|
12
|
-
* Instantiate a client for interacting with the Capture Bridge service.
|
|
13
|
-
* @constructor
|
|
14
|
-
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
|
-
* @example
|
|
16
|
-
* const captureBridge = new CaptureBridge()
|
|
17
|
-
*/
|
|
18
|
-
constructor (baseUrl = BASE_URL) {
|
|
19
|
-
this.baseUrl = baseUrl
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get service version info
|
|
24
|
-
* @method
|
|
25
|
-
* @async
|
|
26
|
-
* @returns {object} Service version info.
|
|
27
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
28
|
-
* @example
|
|
29
|
-
* const captureBridge = new CaptureBridge()
|
|
30
|
-
* const {version} = await captureBridge.version()
|
|
31
|
-
* console.log(version)
|
|
32
|
-
*/
|
|
33
|
-
async version () {
|
|
34
|
-
const response = await fetch(`${this.baseUrl}/version`)
|
|
35
|
-
return await response.json()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Get service version info (Callback)
|
|
40
|
-
* @method
|
|
41
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
42
|
-
* @param {function} callback - Invoked with two arguments. The first argument
|
|
43
|
-
* is an Error object (if an error occurred) or null. The second argument is
|
|
44
|
-
* the version info.
|
|
45
|
-
* @example
|
|
46
|
-
* captureBridge.versionHandler((error, {version}) => {
|
|
47
|
-
* if (error) {
|
|
48
|
-
* console.error('Error fetching version:', error)
|
|
49
|
-
* } else {
|
|
50
|
-
* console.log(`Version: ${version}`)
|
|
51
|
-
* }
|
|
52
|
-
* })
|
|
53
|
-
*/
|
|
54
|
-
versionHandler (callback) {
|
|
55
|
-
asyncToCallback(this, this.version, callback)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Get service status information
|
|
60
|
-
* @method
|
|
61
|
-
* @async
|
|
62
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
63
|
-
* @returns {object} Service status information.
|
|
64
|
-
* @example
|
|
65
|
-
* const captureBridge = new CaptureBridge()
|
|
66
|
-
* const statusInfo = await captureBridge.status()
|
|
67
|
-
* console.log(statusInfo)
|
|
68
|
-
*/
|
|
69
|
-
async status () {
|
|
70
|
-
const response = await fetch(`${this.baseUrl}/status`)
|
|
71
|
-
return await response.json()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Get service status information (Callback)
|
|
76
|
-
* @method
|
|
77
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
78
|
-
* @param {function} callback - Invoked with two arguments. The first argument
|
|
79
|
-
* is an Error object (if an error occurred) or null. The second argument is
|
|
80
|
-
* the status info.
|
|
81
|
-
* object.
|
|
82
|
-
* @example
|
|
83
|
-
* const captureBridge = new CaptureBridge()
|
|
84
|
-
* captureBridge.statusHandler(statusInfo => console.log(statusInfo))
|
|
85
|
-
*/
|
|
86
|
-
statusHandler (callback) {
|
|
87
|
-
asyncToCallback(this, this.status, callback)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Get all installed plugins
|
|
92
|
-
* @method
|
|
93
|
-
* @async
|
|
94
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
95
|
-
* @see {@link Plugin}
|
|
96
|
-
* @returns {object[]} Array of {@link Plugin} objects.
|
|
97
|
-
* @example
|
|
98
|
-
* const plugins = await captureBridge.plugins()
|
|
99
|
-
*/
|
|
100
|
-
async plugins () {
|
|
101
|
-
const response = await fetch(`${this.baseUrl}/plugin`)
|
|
102
|
-
const plugins = await response.json()
|
|
103
|
-
return plugins.map(p => new Plugin(p, this.baseUrl))
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Get all installed plugins (Callback)
|
|
108
|
-
* @method
|
|
109
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
110
|
-
* @see {@link Plugin}
|
|
111
|
-
* @param {function} callback - Invoked with two arguments. The first argument
|
|
112
|
-
* is an Error object (if an error occurred) or null. The second argument is
|
|
113
|
-
* an Array of {@link Plugin} objects. If no plugins are installed the second
|
|
114
|
-
* argument will be an empty Array.
|
|
115
|
-
* @example
|
|
116
|
-
* captureBridge.pluginsHandler(plugins => console.log(plugins))
|
|
117
|
-
*/
|
|
118
|
-
pluginsHandler (callback) {
|
|
119
|
-
asyncToCallback(this, this.plugins, callback)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Get a single plugin by ID
|
|
124
|
-
* @method
|
|
125
|
-
* @async
|
|
126
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
127
|
-
* @see {@link Plugin}
|
|
128
|
-
* @param {string} id - Plugin ID
|
|
129
|
-
* @returns {object?} {@link Plugin} object or null
|
|
130
|
-
* @example
|
|
131
|
-
* const plugin = await captureBridge.plugin('capture_camera_canon')
|
|
132
|
-
*/
|
|
133
|
-
async plugin (id) {
|
|
134
|
-
// See: ValidRD/wa_capture_bridge/issues/48
|
|
135
|
-
// TODO: we need a /plugin/:id endpoint
|
|
136
|
-
const response = await fetch(`${this.baseUrl}/plugin`)
|
|
137
|
-
const plugins = await response.json()
|
|
138
|
-
const plugin = plugins.find(p => p.id === id)
|
|
139
|
-
return plugin ? new Plugin(plugin) : null
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Get a single plugin by ID (Callback version).
|
|
144
|
-
* @method
|
|
145
|
-
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
146
|
-
* @see {@link Plugin}
|
|
147
|
-
* @param {string} id - Plugin ID
|
|
148
|
-
* @param {function} callback - Invoked with two arguments. The first argument
|
|
149
|
-
* is an Error object (if an error occurred) or null. The second argument is
|
|
150
|
-
* the requested {@link Plugin} object. If no matching plugin was found the
|
|
151
|
-
* second argument will be null.
|
|
152
|
-
* @example
|
|
153
|
-
* captureBridge.pluginHandler('capture_camera_canon', (error, plugin) => {
|
|
154
|
-
* console.log(error, plugin)
|
|
155
|
-
* })
|
|
156
|
-
*/
|
|
157
|
-
pluginHandler (id, callback) {
|
|
158
|
-
asyncToCallback(this, this.plugin, callback, id)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export default CaptureBridge
|
|
1
|
+
import Plugin from './Plugin.js'
|
|
2
|
+
import { BASE_URL, asyncToCallback } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Capture Bridge
|
|
6
|
+
*
|
|
7
|
+
* @classdesc Class for interacting with the HTTP API's base methods.
|
|
8
|
+
*/
|
|
9
|
+
class CaptureBridge {
|
|
10
|
+
baseUrl
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate a client for interacting with the Capture Bridge service.
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
|
+
* @example
|
|
16
|
+
* const captureBridge = new CaptureBridge()
|
|
17
|
+
*/
|
|
18
|
+
constructor (baseUrl = BASE_URL) {
|
|
19
|
+
this.baseUrl = baseUrl
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get service version info
|
|
24
|
+
* @method
|
|
25
|
+
* @async
|
|
26
|
+
* @returns {object} Service version info.
|
|
27
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
28
|
+
* @example
|
|
29
|
+
* const captureBridge = new CaptureBridge()
|
|
30
|
+
* const {version} = await captureBridge.version()
|
|
31
|
+
* console.log(version)
|
|
32
|
+
*/
|
|
33
|
+
async version () {
|
|
34
|
+
const response = await fetch(`${this.baseUrl}/version`)
|
|
35
|
+
return await response.json()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get service version info (Callback)
|
|
40
|
+
* @method
|
|
41
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetVersion|API Endpoint (/version)}
|
|
42
|
+
* @param {function} callback - Invoked with two arguments. The first argument
|
|
43
|
+
* is an Error object (if an error occurred) or null. The second argument is
|
|
44
|
+
* the version info.
|
|
45
|
+
* @example
|
|
46
|
+
* captureBridge.versionHandler((error, {version}) => {
|
|
47
|
+
* if (error) {
|
|
48
|
+
* console.error('Error fetching version:', error)
|
|
49
|
+
* } else {
|
|
50
|
+
* console.log(`Version: ${version}`)
|
|
51
|
+
* }
|
|
52
|
+
* })
|
|
53
|
+
*/
|
|
54
|
+
versionHandler (callback) {
|
|
55
|
+
asyncToCallback(this, this.version, callback)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get service status information
|
|
60
|
+
* @method
|
|
61
|
+
* @async
|
|
62
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
63
|
+
* @returns {object} Service status information.
|
|
64
|
+
* @example
|
|
65
|
+
* const captureBridge = new CaptureBridge()
|
|
66
|
+
* const statusInfo = await captureBridge.status()
|
|
67
|
+
* console.log(statusInfo)
|
|
68
|
+
*/
|
|
69
|
+
async status () {
|
|
70
|
+
const response = await fetch(`${this.baseUrl}/status`)
|
|
71
|
+
return await response.json()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get service status information (Callback)
|
|
76
|
+
* @method
|
|
77
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Service-GetStatus|API Endpoint (/status)}
|
|
78
|
+
* @param {function} callback - Invoked with two arguments. The first argument
|
|
79
|
+
* is an Error object (if an error occurred) or null. The second argument is
|
|
80
|
+
* the status info.
|
|
81
|
+
* object.
|
|
82
|
+
* @example
|
|
83
|
+
* const captureBridge = new CaptureBridge()
|
|
84
|
+
* captureBridge.statusHandler(statusInfo => console.log(statusInfo))
|
|
85
|
+
*/
|
|
86
|
+
statusHandler (callback) {
|
|
87
|
+
asyncToCallback(this, this.status, callback)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get all installed plugins
|
|
92
|
+
* @method
|
|
93
|
+
* @async
|
|
94
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
95
|
+
* @see {@link Plugin}
|
|
96
|
+
* @returns {object[]} Array of {@link Plugin} objects.
|
|
97
|
+
* @example
|
|
98
|
+
* const plugins = await captureBridge.plugins()
|
|
99
|
+
*/
|
|
100
|
+
async plugins () {
|
|
101
|
+
const response = await fetch(`${this.baseUrl}/plugin`)
|
|
102
|
+
const plugins = await response.json()
|
|
103
|
+
return plugins.map(p => new Plugin(p, this.baseUrl))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get all installed plugins (Callback)
|
|
108
|
+
* @method
|
|
109
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
110
|
+
* @see {@link Plugin}
|
|
111
|
+
* @param {function} callback - Invoked with two arguments. The first argument
|
|
112
|
+
* is an Error object (if an error occurred) or null. The second argument is
|
|
113
|
+
* an Array of {@link Plugin} objects. If no plugins are installed the second
|
|
114
|
+
* argument will be an empty Array.
|
|
115
|
+
* @example
|
|
116
|
+
* captureBridge.pluginsHandler(plugins => console.log(plugins))
|
|
117
|
+
*/
|
|
118
|
+
pluginsHandler (callback) {
|
|
119
|
+
asyncToCallback(this, this.plugins, callback)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get a single plugin by ID
|
|
124
|
+
* @method
|
|
125
|
+
* @async
|
|
126
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
127
|
+
* @see {@link Plugin}
|
|
128
|
+
* @param {string} id - Plugin ID
|
|
129
|
+
* @returns {object?} {@link Plugin} object or null
|
|
130
|
+
* @example
|
|
131
|
+
* const plugin = await captureBridge.plugin('capture_camera_canon')
|
|
132
|
+
*/
|
|
133
|
+
async plugin (id) {
|
|
134
|
+
// See: ValidRD/wa_capture_bridge/issues/48
|
|
135
|
+
// TODO: we need a /plugin/:id endpoint
|
|
136
|
+
const response = await fetch(`${this.baseUrl}/plugin`)
|
|
137
|
+
const plugins = await response.json()
|
|
138
|
+
const plugin = plugins.find(p => p.id === id)
|
|
139
|
+
return plugin ? new Plugin(plugin) : null
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Get a single plugin by ID (Callback version).
|
|
144
|
+
* @method
|
|
145
|
+
* @see {@link https://capture.local.valididcloud.com:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
|
|
146
|
+
* @see {@link Plugin}
|
|
147
|
+
* @param {string} id - Plugin ID
|
|
148
|
+
* @param {function} callback - Invoked with two arguments. The first argument
|
|
149
|
+
* is an Error object (if an error occurred) or null. The second argument is
|
|
150
|
+
* the requested {@link Plugin} object. If no matching plugin was found the
|
|
151
|
+
* second argument will be null.
|
|
152
|
+
* @example
|
|
153
|
+
* captureBridge.pluginHandler('capture_camera_canon', (error, plugin) => {
|
|
154
|
+
* console.log(error, plugin)
|
|
155
|
+
* })
|
|
156
|
+
*/
|
|
157
|
+
pluginHandler (id, callback) {
|
|
158
|
+
asyncToCallback(this, this.plugin, callback, id)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export default CaptureBridge
|