@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 CHANGED
@@ -1,68 +1,63 @@
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 {
3
+ BASE_URL,
4
+ DEFAULT_CAPTURE_OPT,
5
+ DEPRECATION_01,
6
+ asyncToCallback
7
+ } from './Common.js'
8
+
9
+ /**
10
+ * Camera
11
+ * @classdesc Class for invoking methods on a Camera
12
+ * @extends StreamingCapturePlugin
13
+ * @see {@link CanonCamera}
14
+ */
15
+ class Camera extends StreamingCapturePlugin {
16
+ /**
17
+ * Instantiate a Generic Camera
18
+ * @constructor
19
+ * @param {string} pluginId - The Id of the desired plugin to use for this
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.
23
+ * @example
24
+ * const camera = new Camera('capture_camera_canon')
25
+ */
26
+ constructor (pluginId, baseUrl = BASE_URL) {
27
+ super(pluginId, baseUrl)
28
+ }
29
+
30
+ /**
31
+ * Capture a photo
32
+ * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
33
+ * photo.
34
+ * @param {string|object} [deviceOpt] - Take the photo using either a specific
35
+ * Device ID or a Device Object. The default is the first available device.
36
+ *
37
+ * @async
38
+ * @example
39
+ * // Capture a photo as an ObjectURL, add it to an img element and append to
40
+ * // the document's body.
41
+ * const img = document.createElement('img')
42
+ * img.src = await camera.takePhoto()
43
+ * document.body.appendChild(img)
44
+ */
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)
56
+ }
57
+
58
+ takePhotoHandler (captureOpt = {}, deviceOpt, callback) {
59
+ asyncToCallback(this, this.fullCapture, callback, captureOpt, deviceOpt)
60
+ }
61
+ }
62
+
63
+ 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
+ * @extends Camera
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({kind: '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,160 @@
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, checkResponse } 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://local.capturebridge.net: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://local.capturebridge.net: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://local.capturebridge.net: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://local.capturebridge.net: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://local.capturebridge.net: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://local.capturebridge.net: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://local.capturebridge.net: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
+ const response = await fetch(`${this.baseUrl}/plugin/${id}`)
135
+ await checkResponse(response)
136
+ const pluginJSON = await response.json()
137
+ return new Plugin(pluginJSON)
138
+ }
139
+
140
+ /**
141
+ * Get a single plugin by ID (Callback version).
142
+ * @method
143
+ * @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPlugins|API Endpoint (/plugin)}
144
+ * @see {@link Plugin}
145
+ * @param {string} id - Plugin ID
146
+ * @param {function} callback - Invoked with two arguments. The first argument
147
+ * is an Error object (if an error occurred) or null. The second argument is
148
+ * the requested {@link Plugin} object. If no matching plugin was found the
149
+ * second argument will be null.
150
+ * @example
151
+ * captureBridge.pluginHandler('capture_camera_canon', (error, plugin) => {
152
+ * console.log(error, plugin)
153
+ * })
154
+ */
155
+ pluginHandler (id, callback) {
156
+ asyncToCallback(this, this.plugin, callback, id)
157
+ }
158
+ }
159
+
160
+ export default CaptureBridge