@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.
@@ -1,153 +1,164 @@
1
- import { blobToBase64 } from './Common.js'
2
-
3
- export class DisplayWidget {
4
- x
5
- y
6
- constructor (x, y) {
7
- this.x = x
8
- this.y = y
9
- }
10
- }
11
-
12
- /**
13
- * TextButton
14
- * @classdesc A button for displaying clickable text on a tablet
15
- *
16
- * @see {@link SignatureTablet}
17
- */
18
- export class TextButton extends DisplayWidget {
19
- text
20
- fontFace
21
- fontSize
22
- id
23
- /**
24
- * Instantiate a Tablet Text Button
25
- * @constructor
26
- * @param {string} text - Text to display on the button
27
- * @param {number} x - X position to draw the button
28
- * @param {number} y - Y position to draw the button
29
- * @param {text} [id] - ID of the button that will be returned when it is
30
- * clicked. If not set one will attempt to be constructed from the button
31
- * text but there is no guarantee it will be unique.
32
- * @param {string} [fontFace] - Font face for the text on the button.
33
- * Defaults to 'Arial'
34
- * @param {number} [fontSize] - Size of the font for the text on the button.
35
- * Defaults to 40.
36
- * @example
37
- * const new TextButton("OK", 20, 200)
38
- */
39
- constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
40
- super(x, y)
41
- this.text = text
42
- this.fontFace = fontFace
43
- this.fontSize = fontSize
44
- if (id) {
45
- this.id = id
46
- } else {
47
- this.id = text.length > 16 ? text.slice(0, 16) : text
48
- }
49
- }
50
-
51
- toJSON () {
52
- return {
53
- type: 'button',
54
- text: this.text,
55
- font_face: this.fontFace,
56
- font_size: this.fontSize,
57
- x: this.x,
58
- y: this.y,
59
- id: this.id
60
- }
61
- }
62
- }
63
-
64
- /**
65
- * Text
66
- * @classdesc Text to be displayed on a tablet
67
- *
68
- * @see {@link SignatureTablet}
69
- */
70
- export class Text extends DisplayWidget {
71
- text
72
- fontFace
73
- fontSize
74
- /**
75
- * Instantiate a Text object
76
- * @constructor
77
- * @param {string} text - Text to display on the button
78
- * @param {number} x - X position to draw the button
79
- * @param {number} y - Y position to draw the button
80
- * @param {string} [fontFace] - Font face for the text on the button.
81
- * Defaults to 'Arial'
82
- * @param {number} [fontSize] - Size of the font for the text on the button.
83
- * Defaults to 40.
84
- * @example
85
- * const new Text("Do you agree?", 20, 200)
86
- */
87
- constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
88
- super(x, y)
89
- this.text = text
90
- this.fontFace = fontFace
91
- this.fontSize = fontSize
92
- }
93
-
94
- toJSON () {
95
- return {
96
- type: 'text',
97
- text: this.text,
98
- font_face: this.fontFace,
99
- font_size: this.fontSize,
100
- x: this.x,
101
- y: this.y
102
- }
103
- }
104
- }
105
-
106
- /**
107
- * Image
108
- * @classdesc Image to be displayed on a tablet
109
- *
110
- * @see {@link SignatureTablet}
111
- */
112
- export class Image extends DisplayWidget {
113
- url
114
- imageData
115
- delay
116
- /**
117
- * Instantiate an Image object
118
- * @constructor
119
- * @param {string} url - URL of the image.
120
- * @param {number} [x] - X position to draw the button
121
- * @param {number} [y] - Y position to draw the button
122
- * @param {number} [delay] - Milliseconds to sleep after displaying the image
123
- * @example
124
- * const new Image("/img/logo.tif", 20, 200)
125
- */
126
- constructor (url, x = 0, y = 0, delay = 0) {
127
- super(x, y)
128
- this.url = url
129
- this.delay = delay
130
- }
131
-
132
- /**
133
- * Fetch the image data and base64 encode it
134
- * @async
135
- * @example
136
- * const new Image("/img/logo.tif", 20, 200)
137
- */
138
- async data () {
139
- const response = await fetch(this.url)
140
- const blob = await response.blob()
141
- this.imageData = await blobToBase64(blob)
142
- }
143
-
144
- toJSON () {
145
- return {
146
- type: 'image',
147
- data: this.imageData,
148
- delay: this.delay,
149
- x: this.x,
150
- y: this.y
151
- }
152
- }
153
- }
1
+ /**
2
+ * @module SignatureTabletWidgets
3
+ */
4
+
5
+ import { blobToBase64 } from './Common.js'
6
+
7
+ /**
8
+ * DisplayWidget
9
+ * @classdesc Represents a widget that can be displayed at some x and y coordinates
10
+ * @see {@link TextButton}
11
+ * @see {@link Text}
12
+ * @see {@link Image}
13
+ */
14
+ export class DisplayWidget {
15
+ x
16
+ y
17
+ constructor (x, y) {
18
+ this.x = x
19
+ this.y = y
20
+ }
21
+ }
22
+
23
+ /**
24
+ * TextButton
25
+ * @classdesc A button for displaying clickable text on a tablet
26
+ * @extends DisplayWidget
27
+ * @see {@link SignatureTablet}
28
+ */
29
+ export class TextButton extends DisplayWidget {
30
+ text
31
+ fontFace
32
+ fontSize
33
+ id
34
+ /**
35
+ * Instantiate a Tablet Text Button
36
+ * @constructor
37
+ * @param {string} text - Text to display on the button
38
+ * @param {number} x - X position to draw the button
39
+ * @param {number} y - Y position to draw the button
40
+ * @param {text} [id] - ID of the button that will be returned when it is
41
+ * clicked. If not set one will attempt to be constructed from the button
42
+ * text but there is no guarantee it will be unique.
43
+ * @param {string} [fontFace] - Font face for the text on the button.
44
+ * Defaults to 'Arial'
45
+ * @param {number} [fontSize] - Size of the font for the text on the button.
46
+ * Defaults to 40.
47
+ * @example
48
+ * const new TextButton("OK", 20, 200)
49
+ */
50
+ constructor (text, x, y, id, fontFace = 'Arial', fontSize = 40) {
51
+ super(x, y)
52
+ this.text = text
53
+ this.fontFace = fontFace
54
+ this.fontSize = fontSize
55
+ if (id) {
56
+ this.id = id
57
+ } else {
58
+ this.id = text.length > 16 ? text.slice(0, 16) : text
59
+ }
60
+ }
61
+
62
+ toJSON () {
63
+ return {
64
+ type: 'button',
65
+ text: this.text,
66
+ font_face: this.fontFace,
67
+ font_size: this.fontSize,
68
+ x: this.x,
69
+ y: this.y,
70
+ id: this.id
71
+ }
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Text
77
+ * @classdesc Text to be displayed on a tablet
78
+ * @extends DisplayWidget
79
+ * @see {@link SignatureTablet}
80
+ */
81
+ export class Text extends DisplayWidget {
82
+ text
83
+ fontFace
84
+ fontSize
85
+ /**
86
+ * Instantiate a Text object
87
+ * @constructor
88
+ * @param {string} text - Text to display on the button
89
+ * @param {number} x - X position to draw the button
90
+ * @param {number} y - Y position to draw the button
91
+ * @param {string} [fontFace] - Font face for the text on the button.
92
+ * Defaults to 'Arial'
93
+ * @param {number} [fontSize] - Size of the font for the text on the button.
94
+ * Defaults to 40.
95
+ * @example
96
+ * const new Text("Do you agree?", 20, 200)
97
+ */
98
+ constructor (text, x, y, fontFace = 'Arial', fontSize = 40) {
99
+ super(x, y)
100
+ this.text = text
101
+ this.fontFace = fontFace
102
+ this.fontSize = fontSize
103
+ }
104
+
105
+ toJSON () {
106
+ return {
107
+ type: 'text',
108
+ text: this.text,
109
+ font_face: this.fontFace,
110
+ font_size: this.fontSize,
111
+ x: this.x,
112
+ y: this.y
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Image
119
+ * @classdesc Image to be displayed on a tablet
120
+ * @extends DisplayWidget
121
+ * @see {@link SignatureTablet}
122
+ */
123
+ export class Image extends DisplayWidget {
124
+ url
125
+ imageData
126
+ delay
127
+ /**
128
+ * Instantiate an Image object
129
+ * @constructor
130
+ * @param {string} url - URL of the image.
131
+ * @param {number} [x] - X position to draw the button
132
+ * @param {number} [y] - Y position to draw the button
133
+ * @param {number} [delay] - Milliseconds to sleep after displaying the image
134
+ * @example
135
+ * const new Image("/img/logo.tif", 20, 200)
136
+ */
137
+ constructor (url, x = 0, y = 0, delay = 0) {
138
+ super(x, y)
139
+ this.url = url
140
+ this.delay = delay
141
+ }
142
+
143
+ /**
144
+ * Fetch the image data and base64 encode it
145
+ * @async
146
+ * @example
147
+ * const new Image("/img/logo.tif", 20, 200)
148
+ */
149
+ async data () {
150
+ const response = await fetch(this.url)
151
+ const blob = await response.blob()
152
+ this.imageData = await blobToBase64(blob)
153
+ }
154
+
155
+ toJSON () {
156
+ return {
157
+ type: 'image',
158
+ data: this.imageData,
159
+ delay: this.delay,
160
+ x: this.x,
161
+ y: this.y
162
+ }
163
+ }
164
+ }
@@ -1,121 +1,129 @@
1
- import CapturePlugin from './CapturePlugin.js'
2
- import { BASE_URL, DATAURL_JPEG, blobToBuffer } from './Common.js'
3
-
4
- class StreamingCapturePlugin extends CapturePlugin {
5
- constructor (plugin, baseUrl = BASE_URL) {
6
- super(plugin, baseUrl)
7
- }
8
-
9
- /**
10
- * Get the CapturePlugin's stream endpoint URL.
11
- *
12
- * @description The URL returned from this endpoint can be attached to an
13
- * img tag's src attribute. The camera's live stream will be started and
14
- * begin streaming to the img tag as a
15
- * {@link https://en.wikipedia.org/wiki/Motion_JPEG|Motion JPEG} stream.
16
- * If the src is changed, the img removed from the DOM, or client disconnected
17
- * for any reason, the live feed will automatically be stopped.
18
- *
19
- * @param {string|object} [deviceOpt] - Get the stream URL from either a
20
- * specific Device ID or a Device Object. The default is the first available
21
- * device.
22
- *
23
- * @async
24
- * @method
25
- * @returns {string} stream endpoint URL
26
- * @example
27
- * const img = document.createElement('img')
28
- * img.src = await camera.streamUrl()
29
- * document.body.appendChild(img)
30
- */
31
- async streamUrl (deviceOpt) {
32
- const device = await this.setupDevice(deviceOpt)
33
- return device.streamUrl()
34
- }
35
-
36
- /**
37
- * Get the most recent frame from a device's live feed.
38
- *
39
- * @description This method will startup the device's live
40
- * feed if necessary and wait for it to initialize before returning a frame.
41
- * Subsequent calls will return the next available frame.
42
- * You must manually stop the live feed if you are using this method.
43
- *
44
- * If implementing a real-time preview, it is highly recommended to use the
45
- * stream endpoint which will stream a Motion JPEG.
46
- *
47
- * @see {@link CapturePlugin#streamUrl}
48
- * @see {@link CapturePlugin#stopFeed}
49
- *
50
- * @param {string} [kind=buffer] - Specify how to return the captured image. Valid
51
- * values are 'blob', 'buffer', 'base64', or 'dataurl'.
52
- *
53
- * The default value of 'buffer' will load the image into an
54
- * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer|ArrayBuffer}
55
- * that can be set directly on an img tag's src attribute.
56
- *
57
- * The value of 'blob' will return a
58
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/Blob|Blob} that can
59
- * be used with a
60
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/FileReader|FileReader}.
61
- *
62
- * The value of 'base64' will return the image contents as a
63
- * {@link https://en.wikipedia.org/wiki/Base64|Base64} encoded string that is
64
- * suitable for use with JSON serialization.
65
- *
66
- * The value of 'dataurl' will return a JPEG
67
- * {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs|Data URL}
68
- * that can be set on an img tag's src attribute or loaded as a document
69
- * location.
70
- *
71
- * @param {string|object} [deviceOpt] - Return the frame from either a
72
- * specific Device ID or a Device Object. The default, if not supplied, is the
73
- * first available device.
74
- *
75
- * @async
76
- * @method
77
- * @example
78
- * // Get the most recent frame from the camera's live feed as an ArrayBuffer
79
- * // and add it to an img tag appended to the document's body.
80
- * const img = document.createElement('img')
81
- * img.src = await camera.getMostRecentFrame()
82
- * document.body.appendChild(img)
83
- *
84
- * // Stop the live feed when done getting frames
85
- * await camera.stopFeed()
86
- */
87
- async getMostRecentFrame (kind = 'buffer', deviceOpt) {
88
- const device = await this.setupDevice(deviceOpt)
89
- switch (kind) {
90
- case 'blob':
91
- return await device.frameAsBlob()
92
- case 'buffer':
93
- return await blobToBuffer(await device.frameAsBlob())
94
- case 'base64':
95
- return await device.frameAsBase64()
96
- case 'dataurl':
97
- return DATAURL_JPEG + (await device.frameAsBase64())
98
- }
99
- throw new Error(`Unknown image response type: ${kind}`)
100
- }
101
-
102
- /**
103
- * Stop the camera's live feed if it is running.
104
- *
105
- * @method
106
- * @async
107
- * @returns {object} Status of the stop operation
108
- * @example
109
- * // CapturePlugin is now running it's live feed in a background thread
110
- * const frame = await camera.getMostRecentFrame()
111
- * // Do some stuff with frame...
112
- * // Stop the live feed
113
- * console.log(await camera.stopFeed())
114
- */
115
- async stopFeed (deviceOpt) {
116
- const device = await this.setupDevice(deviceOpt)
117
- return await device.stopFeed()
118
- }
119
- }
120
-
121
- export default StreamingCapturePlugin
1
+ import CapturePlugin from './CapturePlugin.js'
2
+ import {
3
+ BASE_URL,
4
+ DATAURL_JPEG,
5
+ blobToBuffer,
6
+ DEFAULT_CAPTURE_OPT,
7
+ DEPRECATION_01
8
+ } from './Common.js'
9
+
10
+ /**
11
+ * StreamingCapturePlugin
12
+ * @extends CapturePlugin
13
+ * @classdesc Class for invoking streaming-related methods
14
+ */
15
+ class StreamingCapturePlugin extends CapturePlugin {
16
+ constructor (plugin, baseUrl = BASE_URL) {
17
+ super(plugin, baseUrl)
18
+ }
19
+
20
+ /**
21
+ * Get the CapturePlugin's stream endpoint URL.
22
+ *
23
+ * @description The URL returned from this endpoint can be attached to an
24
+ * img tag's src attribute. The camera's live stream will be started and
25
+ * begin streaming to the img tag as a
26
+ * {@link https://en.wikipedia.org/wiki/Motion_JPEG|Motion JPEG} stream.
27
+ * If the src is changed, the img removed from the DOM, or client disconnected
28
+ * for any reason, the live feed will automatically be stopped.
29
+ *
30
+ * @param {string|object} [deviceOpt] - Get the stream URL from either a
31
+ * specific Device ID or a Device Object. The default is the first available
32
+ * device.
33
+ *
34
+ * @async
35
+ * @method
36
+ * @returns {string} stream endpoint URL
37
+ * @example
38
+ * const img = document.createElement('img')
39
+ * img.src = await camera.streamUrl()
40
+ * document.body.appendChild(img)
41
+ */
42
+ async streamUrl (streamOpt = {}, deviceOpt) {
43
+ const device = await this.setupDevice(deviceOpt)
44
+ return device.streamUrl(streamOpt)
45
+ }
46
+
47
+ /**
48
+ * Get the most recent frame from a device's live feed.
49
+ *
50
+ * @description This method will startup the device's live
51
+ * feed if necessary and wait for it to initialize before returning a frame.
52
+ * Subsequent calls will return the next available frame.
53
+ * You must manually stop the live feed if you are using this method.
54
+ *
55
+ * If implementing a real-time preview, it is highly recommended to use the
56
+ * stream endpoint which will stream a Motion JPEG.
57
+ *
58
+ * @see {@link CapturePlugin#streamUrl}
59
+ * @see {@link CapturePlugin#stopFeed}
60
+ *
61
+ * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
62
+ * photo.
63
+ *
64
+ * @param {string|object} [deviceOpt] - Return the frame from either a
65
+ * specific Device ID or a Device Object. The default, if not supplied, is the
66
+ * first available device.
67
+ *
68
+ * @async
69
+ * @method
70
+ * @example
71
+ * // Get the most recent frame from the camera's live feed as an ArrayBuffer
72
+ * // and add it to an img tag appended to the document's body.
73
+ * const img = document.createElement('img')
74
+ * img.src = await camera.getMostRecentFrame()
75
+ * document.body.appendChild(img)
76
+ *
77
+ * // Stop the live feed when done getting frames
78
+ * await camera.stopFeed()
79
+ */
80
+ async getMostRecentFrame (captureOpt = {}, deviceOpt) {
81
+ if (typeof captureOpt === 'string' && DEPRECATION_01) {
82
+ captureOpt = { kind: captureOpt }
83
+ console.warn('CaptureBridge SDK Deprecation Warning: ' +
84
+ '`StreamingCapturePlugin.getMostRecentFrame()` converted the ' +
85
+ '`captureOpt` argument from a string (%s) to an object (%s). This ' +
86
+ 'conversion may not be performed in future SDK versions.',
87
+ captureOpt.kind, JSON.stringify(captureOpt))
88
+ }
89
+ const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
90
+ const device = await this.setupDevice(mergedOpt)
91
+ switch (mergedOpt.kind) {
92
+ case 'objecturl':
93
+ return URL.createObjectURL(await device.frameAsBlob(mergedOpt))
94
+ case 'blob':
95
+ return await device.frameAsBlob(mergedOpt)
96
+ case 'buffer':
97
+ return await blobToBuffer(await device.frameAsBlob(mergedOpt))
98
+ case 'base64':
99
+ return await device.frameAsBase64(mergedOpt)
100
+ case 'dataurl':
101
+ return DATAURL_JPEG + (await device.frameAsBase64(mergedOpt))
102
+ }
103
+ throw new Error(`Unknown image response kind: ${mergedOpt.kind}`)
104
+ }
105
+
106
+ /**
107
+ * Stop the camera's live feed if it is running.
108
+ *
109
+ * @param {string|object} [deviceOpt] - Stop the feed for a specific Device ID
110
+ * or a Device Object. The default, if not supplied, is the first available
111
+ * device.
112
+ *
113
+ * @method
114
+ * @async
115
+ * @returns {object} Status of the stop operation
116
+ * @example
117
+ * // CapturePlugin is now running it's live feed in a background thread
118
+ * const frame = await camera.getMostRecentFrame()
119
+ * // Do some stuff with frame...
120
+ * // Stop the live feed
121
+ * console.log(await camera.stopFeed())
122
+ */
123
+ async stopFeed (deviceOpt) {
124
+ const device = await this.setupDevice(deviceOpt)
125
+ return await device.stopFeed()
126
+ }
127
+ }
128
+
129
+ export default StreamingCapturePlugin
package/TopazSigGem.js CHANGED
@@ -1,25 +1,25 @@
1
- import SignatureTablet from './SignatureTablet.js'
2
- import { BASE_URL } from './Common.js'
3
-
4
- /**
5
- * TopazSigGem
6
- * @classdesc Convience class for instantiating a Topaz SigGem Signature Tablet
7
- * Inherits all methods on the {@link SignatureTablet} class.
8
- *
9
- * @see {@link SignatureTablet}
10
- */
11
- class TopazSigGem extends SignatureTablet {
12
- /**
13
- * Instantiate a Topaz SigGem Signature Tablet
14
- * @constructor
15
- * @param {string} [baseURL] - Protocol, domain, and port for the service.
16
- * @example
17
- * const camera = new TopazSigGem()
18
- *
19
- */
20
- constructor (baseUrl = BASE_URL) {
21
- super('capture_signature_topaz', baseUrl)
22
- }
23
- }
24
-
25
- export default TopazSigGem
1
+ import SignatureTablet from './SignatureTablet.js'
2
+ import { BASE_URL } from './Common.js'
3
+
4
+ /**
5
+ * TopazSigGem
6
+ * @classdesc Convience class for instantiating a Topaz SigGem Signature Tablet
7
+ * Inherits all methods on the {@link SignatureTablet} class.
8
+ * @extends SignatureTablet
9
+ * @see {@link SignatureTablet}
10
+ */
11
+ class TopazSigGem extends SignatureTablet {
12
+ /**
13
+ * Instantiate a Topaz SigGem Signature Tablet
14
+ * @constructor
15
+ * @param {string} [baseURL] - Protocol, domain, and port for the service.
16
+ * @example
17
+ * const camera = new TopazSigGem()
18
+ *
19
+ */
20
+ constructor (baseUrl = BASE_URL) {
21
+ super('capture_signature_topaz', baseUrl)
22
+ }
23
+ }
24
+
25
+ export default TopazSigGem
package/Version.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @summary SDK Version as published on
3
+ * {@link https://www.npmjs.com/package/@capturebridge/sdk|NPM}
4
+ * @constant
5
+ * @type {string}
6
+ */
7
+ const VERSION = '0.8.0'
8
+ export default VERSION