@capturebridge/sdk 0.15.0 → 0.16.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/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.16.0] - 2024-10-03
9
+
10
+ ### Changed
11
+
12
+ - `Plugin.shutdown` now accepts a `timeout` argument.
13
+
14
+ ### Removed
15
+
16
+ - Removed all callback style methods in favor of async/await methods.
17
+
8
18
  ## [0.15.0] - 2024-09-25
9
19
 
10
20
  ### Added
package/Camera.js CHANGED
@@ -2,8 +2,7 @@ import StreamingCapturePlugin from './StreamingCapturePlugin.js'
2
2
  import {
3
3
  BASE_URL,
4
4
  DEFAULT_CAPTURE_OPT,
5
- DEPRECATION_01,
6
- asyncToCallback
5
+ DEPRECATION_01
7
6
  } from './Common.js'
8
7
 
9
8
  /**
@@ -54,10 +53,6 @@ class Camera extends StreamingCapturePlugin {
54
53
  const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
55
54
  return await this.fullCapture(mergedOpt, deviceOpt)
56
55
  }
57
-
58
- takePhotoHandler (captureOpt = {}, deviceOpt, callback) {
59
- asyncToCallback(this, this.fullCapture, callback, captureOpt, deviceOpt)
60
- }
61
56
  }
62
57
 
63
58
  export default Camera
package/CaptureBridge.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Plugin from './Plugin.js'
2
- import { BASE_URL, asyncToCallback, checkResponse } from './Common.js'
2
+ import { BASE_URL, checkResponse } from './Common.js'
3
3
 
4
4
  /**
5
5
  * Capture Bridge
@@ -35,26 +35,6 @@ class CaptureBridge {
35
35
  return await response.json()
36
36
  }
37
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
38
  /**
59
39
  * Get service status information
60
40
  * @method
@@ -71,22 +51,6 @@ class CaptureBridge {
71
51
  return await response.json()
72
52
  }
73
53
 
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
54
  /**
91
55
  * Get all installed plugins
92
56
  * @method
@@ -103,22 +67,6 @@ class CaptureBridge {
103
67
  return plugins.map(p => new Plugin(p, this.baseUrl))
104
68
  }
105
69
 
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
70
  /**
123
71
  * Get a single plugin by ID
124
72
  * @method
@@ -136,25 +84,6 @@ class CaptureBridge {
136
84
  const pluginJSON = await response.json()
137
85
  return new Plugin(pluginJSON)
138
86
  }
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
87
  }
159
88
 
160
89
  export default CaptureBridge
package/Common.js CHANGED
@@ -212,22 +212,6 @@ export const blobToBase64 = blob => {
212
212
  })
213
213
  }
214
214
 
215
- /**
216
- * Helper function for classes to easily add callback style support to their
217
- * async/await methods.
218
- * @private
219
- */
220
- export const asyncToCallback = (thisValue, asyncFn, callback, ...params) => {
221
- (async () => {
222
- try {
223
- const result = await asyncFn.call(thisValue, ...(params.length ? params : []))
224
- callback(null, result)
225
- } catch (ex) {
226
- callback(ex)
227
- }
228
- })()
229
- }
230
-
231
215
  /**
232
216
  * Helper function to throw if an http response was a error.
233
217
  * @private
package/Device.js CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  DEFAULT_CAPTURE_OPT,
7
7
  checkResponse,
8
8
  timeout,
9
- asyncToCallback,
10
9
  urlParamsToString
11
10
  } from './Common.js'
12
11
 
@@ -163,32 +162,6 @@ class Device {
163
162
  return await response.blob()
164
163
  }
165
164
 
166
- /**
167
- * Take full capture from the specified device and return a
168
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
169
- * be used with a {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}
170
- * (Callback version)
171
- *
172
- * @method
173
- * @param {function} callback
174
- * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
175
- * frame.
176
- * @example
177
- * // Load the blob into FileReader and append to the document's body
178
- * device.captureAsBlobHandler((error, blob) => {
179
- * const reader = new FileReader()
180
- * reader.onload = event => {
181
- * const img = document.createElement('img')
182
- * img.src = event.target.result
183
- * document.body.appendChild(img)
184
- * }
185
- * reader.readAsDataURL(blob)
186
- * })
187
- */
188
- captureAsBlobHandler (callback, captureOpt = {}) {
189
- asyncToCallback(this, this.captureAsBlob, captureOpt, callback)
190
- }
191
-
192
165
  /**
193
166
  * Take full capture from the specified device and return a
194
167
  * base64 encoded string of the image that can be used with a
@@ -224,20 +197,6 @@ class Device {
224
197
  return image
225
198
  }
226
199
 
227
- /**
228
- * Take full capture from the specified device and return a
229
- * base64 encoded string of the image that can be used with a
230
- * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
231
- * (Callback version)
232
- * @method
233
- * @param {function} callback
234
- * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
235
- * frame.
236
- */
237
- captureAsBase64Handler (callback, captureOpt = {}) {
238
- asyncToCallback(this, this.captureAsBase64, callback)
239
- }
240
-
241
200
  /**
242
201
  * Get a base64 encoded frame from a device's live feed.
243
202
  * @method
@@ -290,42 +249,6 @@ class Device {
290
249
  }
291
250
  }
292
251
 
293
- /**
294
- * Get a base64 encoded frame from a device's live feed. (Callback version)
295
- * @method
296
- *
297
- * @description This method will startup the live
298
- * feed if necessary and wait for it to initialize before returning a frame.
299
- * Subsequent calls will return the next available frame.
300
- * You must manually stop the live feed if you are using this method.
301
- *
302
- * The frame returned will be a base64 encoded string of the image that can
303
- * be used with a
304
- * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
305
- *
306
- * If implementing a real-time preview, it is highly recommended to use the
307
- * stream endpoint which will stream a Motion JPEG.
308
- *
309
- * @see {@link streamUrl}
310
- * @see {@link setStopFeed}
311
- *
312
- * @param {function} callback
313
- * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
314
- * frame.
315
- * @param {number} [millis] - Milliseconds to wait if feed is not ready
316
- * @example
317
- * // Add the base64 string as a Data URL to an img tag and append to
318
- * // the document's body
319
- * device.frameAsBase64Handler(base64 => {
320
- * const img = document.createElement('img')
321
- * img.src = 'data:image/jpeg;base64,' + base64
322
- * document.body.appendChild(img)
323
- * })
324
- */
325
- frameAsBase64Handler (callback, captureOpt = {}, millis = 500) {
326
- asyncToCallback(this, this.frameAsBase64, callback, captureOpt, millis)
327
- }
328
-
329
252
  /**
330
253
  * Get a binary frame from a device's live feed. (Async/await version)
331
254
  * @method
@@ -379,48 +302,6 @@ class Device {
379
302
  throw new Error(result || 'Failed to get frame')
380
303
  }
381
304
 
382
- /**
383
- * Get a binary frame from a device's live feed. (Callback version)
384
- * @method
385
- *
386
- * @description This method will startup the live
387
- * feed if necessary and wait for it to initialize before returning a frame.
388
- * Subsequent calls will return the next available frame.
389
- * You must manually stop the live feed if you are using this method.
390
- *
391
- * The frame returned will be a
392
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
393
- * be used with a {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}
394
- *
395
- * If implementing a real-time preview, it is highly recommended to use the
396
- * stream endpoint which will stream a Motion JPEG.
397
- *
398
- * @see {@link streamUrl}
399
- * @see {@link setStopFeed}
400
- *
401
- * @param {function} callback
402
- *
403
- * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
404
- * frame.
405
- *
406
- * @param {number} [millis] - Milliseconds to wait if feed is not ready
407
- *
408
- * @example
409
- * // Load the blob into FileReader and append to the document's body
410
- * device.frameAsBlobHandler((error, blob) => {
411
- * const reader = new FileReader()
412
- * reader.onload = event => {
413
- * const img = document.createElement('img')
414
- * img.src = event.target.result
415
- * document.body.appendChild(img)
416
- * }
417
- * reader.readAsDataURL(blob)
418
- * })
419
- */
420
- frameAsBlobHandler (callback, captureOpt = {}, millis = 500) {
421
- asyncToCallback(this, this.frameAsBlob, callback, captureOpt, millis)
422
- }
423
-
424
305
  /**
425
306
  * Stop the live feed if it is running.
426
307
  * (Async/Await version)
@@ -441,26 +322,6 @@ class Device {
441
322
  return await response.json()
442
323
  }
443
324
 
444
- /**
445
- * Stop the live feed if it is running.
446
- * (Callback version)
447
- *
448
- * @method
449
- * @param {number} [millis] - Milliseconds to wait if feed is not ready
450
- * @param {function} callback with the status of the stop operation
451
- * @example
452
- * device.stopFeedHandler((error, blob) => {
453
- * // Plugin is now running it's live feed in a background thread
454
- * device.setStopFeed(result => {
455
- * // Live feed is now stopping
456
- * console.log(result)
457
- * })
458
- * })
459
- */
460
- stopFeedHandler (callback) {
461
- asyncToCallback(this, this.frameAsBlob, callback)
462
- }
463
-
464
325
  /**
465
326
  * Clear a device's display.
466
327
  * (Async/Await version)
@@ -484,24 +345,6 @@ class Device {
484
345
  return await response.json()
485
346
  }
486
347
 
487
- /**
488
- * Clear a device's display.
489
- * (Callback version)
490
- *
491
- * @method
492
- * @param {function} callback with the status of the clear operation
493
- * @param {boolean} [backlight] If provided and set to true, will enable
494
- * backlight. If false, it will be disabled. If unspecified no action will be
495
- * taken on the backlight.
496
- * @example
497
- * device.clearHandler((error, result) => {
498
- * console.log(result)
499
- * })
500
- */
501
- clearHandler (callback, backlight) {
502
- asyncToCallback(this, this.clear, callback, backlight)
503
- }
504
-
505
348
  /**
506
349
  * Render an Array of Objects on the display and wait for user input.
507
350
  *
@@ -548,10 +391,6 @@ class Device {
548
391
  return await response.json()
549
392
  }
550
393
 
551
- async displayObjectsHandler (objects, clear = true, callback) {
552
- asyncToCallback(this, this.displayObjects, callback, objects, clear)
553
- }
554
-
555
394
  /**
556
395
  * Get detailed information about a device
557
396
  *
@@ -569,20 +408,6 @@ class Device {
569
408
  const response = await fetch(url)
570
409
  return await response.json()
571
410
  }
572
-
573
- /**
574
- * Get detailed information about a device
575
- *
576
- * @description Returns detailed information about a device.
577
- *
578
- * @method
579
- * @returns {object} Device info
580
- * @example
581
- * const info = await device.info()
582
- */
583
- async infoHandler (callback) {
584
- asyncToCallback(this, this.info, callback)
585
- }
586
411
  }
587
412
 
588
413
  export default Device
package/IFace.js CHANGED
@@ -119,10 +119,6 @@ export class IFace extends ICAO {
119
119
  return VALID_MODES
120
120
  }
121
121
 
122
- matchModesHandler (callback) {
123
- callback(null, VALID_MODES)
124
- }
125
-
126
122
  /**
127
123
  * Check the ICAO compliance of an image
128
124
  * @param {string} image - A base64 encoded image.
package/Plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import Device from './Device.js'
2
2
 
3
- import { BASE_URL, DELETE, checkResponse, asyncToCallback } from './Common.js'
3
+ import { BASE_URL, DELETE, checkResponse } from './Common.js'
4
4
 
5
5
  /**
6
6
  * @classdesc CaptureBridge utilizes a plugin system for interacting with
@@ -75,24 +75,6 @@ class Plugin {
75
75
  return devices.map(d => new Device(d, this, this.baseUrl))
76
76
  }
77
77
 
78
- /**
79
- * Get all Devices for this plugin
80
- *
81
- * @method
82
- * @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
83
- * @param {function} callback - Invoked with two arguments. The first argument
84
- * is an Error object (if an error occurred) or null. The second argument is
85
- * an Array of {@link Device} objects. If no devices are available the second
86
- * argument will be an empty Array.
87
- * @example
88
- * captureBridge.pluginHandler('capture_camera_canon', (error, plugin) => {
89
- * plugin.devicesHandler((error, devices) => console.log(devices))
90
- * })
91
- */
92
- devicesHandler (callback) {
93
- asyncToCallback(this, this.devices, callback)
94
- }
95
-
96
78
  /**
97
79
  * Get a device by ID for this plugin
98
80
  *
@@ -112,24 +94,6 @@ class Plugin {
112
94
  return device ? new Device(device, this, this.baseUrl) : null
113
95
  }
114
96
 
115
- /**
116
- * Get a Device by ID for this plugin
117
- * @method
118
- * @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-GetPluginDevices|API Endpoint (/plugin/:pluginId/device)}
119
- * @param {string} id - Device ID
120
- * @param {function} callback - Invoked with two arguments. The first argument
121
- * is an Error object (if an error occurred) or null. The second argument is
122
- * a {@link Device} object. If the requested device is not available the
123
- * second argument will be null.
124
- * @example
125
- * captureBridge.pluginHandler('capture_camera_canon', (error, plugin) => {
126
- * plugin.deviceHandler('AWOOO56709', (error, device) => console.log(device))
127
- * })
128
- */
129
- deviceHandler (id, callback) {
130
- asyncToCallback(this, this.device, callback, id)
131
- }
132
-
133
97
  async configSchema () {
134
98
  if (!await this.supportsConfig()) {
135
99
  throw new Error('Plugin does not support config')
@@ -138,10 +102,6 @@ class Plugin {
138
102
  return await response.json()
139
103
  }
140
104
 
141
- configSchemaHandler (callback) {
142
- asyncToCallback(this, this.configSchema, callback)
143
- }
144
-
145
105
  async config () {
146
106
  if (!await this.supportsConfig()) {
147
107
  throw new Error('Plugin does not support config')
@@ -150,10 +110,6 @@ class Plugin {
150
110
  return await response.json()
151
111
  }
152
112
 
153
- configHandler (callback) {
154
- asyncToCallback(this, this.config, callback)
155
- }
156
-
157
113
  async saveConfig (config) {
158
114
  if (!await this.supportsConfig()) {
159
115
  throw new Error('Plugin does not support config')
@@ -171,29 +127,29 @@ class Plugin {
171
127
  return await response.json()
172
128
  }
173
129
 
174
- async saveConfigHandler (config, callback) {
175
- asyncToCallback(this, this.saveConfig, callback, config)
176
- }
177
-
178
130
  async supportsConfig () {
179
131
  await this.update()
180
132
  return this.configMethods.every(m => this.methods.includes(m))
181
133
  }
182
134
 
183
- supportsConfigHandler (callback) {
184
- asyncToCallback(this, this.configHandler, callback)
185
- }
186
-
187
- async shutdown () {
188
- const url = `${this.baseUrl}/plugin/${this.id}`
135
+ /**
136
+ * Shutdown a plugin
137
+ * @method
138
+ * @async
139
+ * @see {@link https://local.capturebridge.net:9001/doc/#api-Plugin-ShutdownPlugin|API Endpoint (/plugin/:pluginId)}
140
+ * @param {number} [timeout=10] - Timeout in seconds. Forcefully terminate
141
+ * the plugin if it doesn't shutdown cleanly within the specified timeout. A
142
+ * value of `0` will result in immediately terminating the plugin and should
143
+ * be avoided unless the plugin is unresponsive.
144
+ * @example
145
+ * await plugin.shutdown()
146
+ */
147
+ async shutdown (timeout = 10) {
148
+ const url = `${this.baseUrl}/plugin/${this.id}?timeout=${timeout}`
189
149
  const response = await fetch(url, DELETE)
190
150
  return await response.json()
191
151
  }
192
152
 
193
- shutdownHandler (callback) {
194
- asyncToCallback(this, this.shutdown, callback)
195
- }
196
-
197
153
  async startup () {
198
154
  // See: ValidRD/wa_capture_bridge/issues/48
199
155
  // We need an explicit endpoint for this instead
@@ -205,10 +161,6 @@ class Plugin {
205
161
  return { status: 'failed' }
206
162
  }
207
163
 
208
- startupHandler (callback) {
209
- asyncToCallback(this, this.startup, callback)
210
- }
211
-
212
164
  /**
213
165
  * This class can be instantiated from either a plugin ID or a full plugin
214
166
  * object from an API request.
@@ -227,10 +179,6 @@ class Plugin {
227
179
  }
228
180
  }
229
181
 
230
- updateHandler (force = false, callback) {
231
- asyncToCallback(this, this.update, callback, force)
232
- }
233
-
234
182
  /**
235
183
  * Check if a plugin has an RPC method
236
184
  *
@@ -259,19 +207,11 @@ class Plugin {
259
207
  return await response.json()
260
208
  }
261
209
 
262
- rpcHandler (request, callback) {
263
- asyncToCallback(this, this.rpc, callback, request)
264
- }
265
-
266
210
  async ping () {
267
211
  const response = await fetch(`${this.baseUrl}/plugin/${this.id}/ping`)
268
212
  return await response.json()
269
213
  }
270
214
 
271
- pingHandler (callback) {
272
- asyncToCallback(this, this.ping, callback)
273
- }
274
-
275
215
  /**
276
216
  * Classes that extend this one will add their own methods to perform
277
217
  * operations on a device. They will call this method first to get a device
package/Version.js CHANGED
@@ -4,5 +4,5 @@
4
4
  * @constant
5
5
  * @type {string}
6
6
  */
7
- const VERSION = '0.15.0'
7
+ const VERSION = '0.16.0'
8
8
  export default VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capturebridge/sdk",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Capture Bridge JavaScript SDK for web applications",
5
5
  "type": "module",
6
6
  "types": "types.d.ts",