@capturebridge/sdk 0.7.1 → 0.9.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 +22 -0
- package/Camera.js +27 -32
- package/CanonCamera.js +2 -2
- package/CaptureBridge.js +13 -15
- package/CapturePlugin.js +21 -32
- package/Common.js +129 -7
- package/Device.js +169 -25
- 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/Verifone.js +68 -0
- 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/verifone_minimal.html +23 -0
- package/examples/windows_scanner_minimal.html +32 -0
- package/package.json +2 -2
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import CapturePlugin from './CapturePlugin.js'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BASE_URL,
|
|
4
|
+
DATAURL_JPEG,
|
|
5
|
+
blobToBuffer,
|
|
6
|
+
DEFAULT_CAPTURE_OPT,
|
|
7
|
+
DEPRECATION_01
|
|
8
|
+
} from './Common.js'
|
|
3
9
|
|
|
10
|
+
/**
|
|
11
|
+
* StreamingCapturePlugin
|
|
12
|
+
* @extends CapturePlugin
|
|
13
|
+
* @classdesc Class for invoking streaming-related methods
|
|
14
|
+
*/
|
|
4
15
|
class StreamingCapturePlugin extends CapturePlugin {
|
|
5
16
|
constructor (plugin, baseUrl = BASE_URL) {
|
|
6
17
|
super(plugin, baseUrl)
|
|
@@ -28,9 +39,9 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
28
39
|
* img.src = await camera.streamUrl()
|
|
29
40
|
* document.body.appendChild(img)
|
|
30
41
|
*/
|
|
31
|
-
async streamUrl (deviceOpt) {
|
|
42
|
+
async streamUrl (streamOpt = {}, deviceOpt) {
|
|
32
43
|
const device = await this.setupDevice(deviceOpt)
|
|
33
|
-
return device.streamUrl()
|
|
44
|
+
return device.streamUrl(streamOpt)
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
/**
|
|
@@ -47,26 +58,8 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
47
58
|
* @see {@link CapturePlugin#streamUrl}
|
|
48
59
|
* @see {@link CapturePlugin#stopFeed}
|
|
49
60
|
*
|
|
50
|
-
* @param {
|
|
51
|
-
*
|
|
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.
|
|
61
|
+
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
|
|
62
|
+
* photo.
|
|
70
63
|
*
|
|
71
64
|
* @param {string|object} [deviceOpt] - Return the frame from either a
|
|
72
65
|
* specific Device ID or a Device Object. The default, if not supplied, is the
|
|
@@ -84,24 +77,39 @@ class StreamingCapturePlugin extends CapturePlugin {
|
|
|
84
77
|
* // Stop the live feed when done getting frames
|
|
85
78
|
* await camera.stopFeed()
|
|
86
79
|
*/
|
|
87
|
-
async getMostRecentFrame (
|
|
88
|
-
|
|
89
|
-
|
|
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))
|
|
90
94
|
case 'blob':
|
|
91
|
-
return await device.frameAsBlob()
|
|
95
|
+
return await device.frameAsBlob(mergedOpt)
|
|
92
96
|
case 'buffer':
|
|
93
|
-
return await blobToBuffer(await device.frameAsBlob())
|
|
97
|
+
return await blobToBuffer(await device.frameAsBlob(mergedOpt))
|
|
94
98
|
case 'base64':
|
|
95
|
-
return await device.frameAsBase64()
|
|
99
|
+
return await device.frameAsBase64(mergedOpt)
|
|
96
100
|
case 'dataurl':
|
|
97
|
-
return DATAURL_JPEG + (await device.frameAsBase64())
|
|
101
|
+
return DATAURL_JPEG + (await device.frameAsBase64(mergedOpt))
|
|
98
102
|
}
|
|
99
|
-
throw new Error(`Unknown image response
|
|
103
|
+
throw new Error(`Unknown image response kind: ${mergedOpt.kind}`)
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Stop the camera's live feed if it is running.
|
|
104
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
|
+
*
|
|
105
113
|
* @method
|
|
106
114
|
* @async
|
|
107
115
|
* @returns {object} Status of the stop operation
|
package/TopazSigGem.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BASE_URL } from './Common.js'
|
|
|
5
5
|
* TopazSigGem
|
|
6
6
|
* @classdesc Convience class for instantiating a Topaz SigGem Signature Tablet
|
|
7
7
|
* Inherits all methods on the {@link SignatureTablet} class.
|
|
8
|
-
*
|
|
8
|
+
* @extends SignatureTablet
|
|
9
9
|
* @see {@link SignatureTablet}
|
|
10
10
|
*/
|
|
11
11
|
class TopazSigGem extends SignatureTablet {
|
package/Verifone.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import SignatureTablet from './SignatureTablet.js'
|
|
2
|
+
import { BASE_URL } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Verifone
|
|
6
|
+
* @classdesc Captures a signature on Verifone device.
|
|
7
|
+
* @extends SignatureTablet
|
|
8
|
+
* @see {@link SignatureTablet}
|
|
9
|
+
*/
|
|
10
|
+
class Verifone extends SignatureTablet {
|
|
11
|
+
/**
|
|
12
|
+
* Instantiate a Verifone Class
|
|
13
|
+
* @constructor
|
|
14
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
15
|
+
* @example
|
|
16
|
+
* const tablet = new Verifone()
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
constructor (baseUrl = BASE_URL) {
|
|
20
|
+
super('capture_signature_verifone', baseUrl)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Not currently supported for this plugin.
|
|
25
|
+
* @throws Not implemented error
|
|
26
|
+
* @example
|
|
27
|
+
* // Not currently supported for this plugin
|
|
28
|
+
* @override
|
|
29
|
+
*/
|
|
30
|
+
async streamUrl () {
|
|
31
|
+
throw new Error('streamUrl() is not implemented for the Verifone Plugin')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Not currently supported for this plugin.
|
|
36
|
+
* @throws Not implemented error
|
|
37
|
+
* @example
|
|
38
|
+
* // Not currently supported for this plugin
|
|
39
|
+
* @override
|
|
40
|
+
*/
|
|
41
|
+
async getMostRecentFrame () {
|
|
42
|
+
throw new Error('getMostRecentFrame() is not implemented for the Verifone Plugin')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Not currently supported for this plugin.
|
|
47
|
+
* @throws Not implemented error
|
|
48
|
+
* @example
|
|
49
|
+
* // Not currently supported for this plugin
|
|
50
|
+
* @override
|
|
51
|
+
*/
|
|
52
|
+
async stopFeed () {
|
|
53
|
+
throw new Error('stopFeed() is not implemented for the Verifone Plugin')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Not currently supported for this plugin.
|
|
58
|
+
* @throws Not implemented error
|
|
59
|
+
* @example
|
|
60
|
+
* // Not currently supported for this plugin
|
|
61
|
+
* @override
|
|
62
|
+
*/
|
|
63
|
+
async displayObjects () {
|
|
64
|
+
throw new Error('displayObjects() is not implemented for the Verifone Plugin')
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default Verifone
|
package/Version.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Scanner from './Scanner.js'
|
|
2
|
+
import { BASE_URL } from './Common.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WindowsScanner
|
|
6
|
+
* @classdesc Convenience class for instantiating a WIA compatible Scanner.
|
|
7
|
+
* Inherits all methods on the {@link Scanner} class.
|
|
8
|
+
* @extends Scanner
|
|
9
|
+
* @see {@link Scanner}
|
|
10
|
+
*/
|
|
11
|
+
class WindowsScanner extends Scanner {
|
|
12
|
+
/**
|
|
13
|
+
* Instantiate a WIA compatible scanner
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {string} [baseURL] - Protocol, domain, and port for the service.
|
|
16
|
+
* @example
|
|
17
|
+
* const scanner = new WindowsScanner()
|
|
18
|
+
* const doc = await camera.scan()
|
|
19
|
+
*/
|
|
20
|
+
constructor (baseUrl = BASE_URL) {
|
|
21
|
+
super('capture_scanner_windows', baseUrl)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default WindowsScanner
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Canon Camera Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<img id="img"/>
|
|
6
|
+
<div>
|
|
7
|
+
<div>
|
|
8
|
+
<label>Rotate</label>
|
|
9
|
+
<input type="number" value="0" id="rotate" min="-360" max="360" step="90"/>
|
|
10
|
+
</div>
|
|
11
|
+
<button type="button" id="capture" title="Capture Image">
|
|
12
|
+
Capture
|
|
13
|
+
</button>
|
|
14
|
+
<button type="button" id="stream" title="Stream Live Feed">
|
|
15
|
+
Stream
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module">
|
|
19
|
+
import CanonCamera from '/sdk/js/CanonCamera.js'
|
|
20
|
+
(async () => {
|
|
21
|
+
const defaultSrc = '/demo/img/empty.jpg'
|
|
22
|
+
const defaultWidth = 400
|
|
23
|
+
const img = document.getElementById('img')
|
|
24
|
+
const capture = document.getElementById('capture')
|
|
25
|
+
const stream = document.getElementById('stream')
|
|
26
|
+
const rotation = document.getElementById('rotate')
|
|
27
|
+
|
|
28
|
+
img.src = defaultSrc
|
|
29
|
+
img.width = defaultWidth
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const camera = new CanonCamera()
|
|
33
|
+
const devices = await camera.devices();
|
|
34
|
+
|
|
35
|
+
if (!devices.length) {
|
|
36
|
+
return alert('No Canon Camera devices found')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Start the first device's live feed and stream it to the img tag
|
|
40
|
+
stream.addEventListener('click', async () => {
|
|
41
|
+
const rotate = parseInt(rotation.value)
|
|
42
|
+
rotation.disabled = true
|
|
43
|
+
stream.disabled = true
|
|
44
|
+
img.src = await camera.streamUrl({rotate})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// Take a full capture and add the image to the page
|
|
48
|
+
capture.addEventListener('click', async () => {
|
|
49
|
+
const rotate = parseInt(rotation.value)
|
|
50
|
+
const capture = document.createElement('img')
|
|
51
|
+
img.src = defaultSrc
|
|
52
|
+
capture.src = await camera.takePhoto({rotate})
|
|
53
|
+
capture.width = defaultWidth
|
|
54
|
+
document.body.appendChild(capture)
|
|
55
|
+
rotation.disabled = false
|
|
56
|
+
stream.disabled = false
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error(e)
|
|
61
|
+
alert(`Error: ${e.message}`)
|
|
62
|
+
}
|
|
63
|
+
})()
|
|
64
|
+
</script>
|
|
65
|
+
</body>
|
|
66
|
+
</html>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Canon Camera Frame Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<div>
|
|
6
|
+
<img id="img"/>
|
|
7
|
+
<div>
|
|
8
|
+
<label>Rotate</label>
|
|
9
|
+
<input type="number" value="0" id="rotate" min="-360" max="360" step="90"/>
|
|
10
|
+
</div>
|
|
11
|
+
<button type="button" id="frame" title="Grab Frame from live feed">
|
|
12
|
+
Get Frame
|
|
13
|
+
</button>
|
|
14
|
+
<button type="button" id="stop" title="Stop live feed">
|
|
15
|
+
Stop Feed
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module">
|
|
19
|
+
import CanonCamera from '/sdk/js/CanonCamera.js'
|
|
20
|
+
(async () => {
|
|
21
|
+
const defaultSrc = '/demo/img/empty.jpg'
|
|
22
|
+
const img = document.getElementById('img')
|
|
23
|
+
const rotation = document.getElementById('rotate')
|
|
24
|
+
const frame = document.getElementById('frame')
|
|
25
|
+
const stop = document.getElementById('stop')
|
|
26
|
+
|
|
27
|
+
img.src = defaultSrc
|
|
28
|
+
img.width = 400
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const camera = new CanonCamera()
|
|
32
|
+
const devices = await camera.devices()
|
|
33
|
+
|
|
34
|
+
if (!devices.length) {
|
|
35
|
+
return alert('No Canon Camera devices found')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Acquiring the first frame will take a few seconds while the camera
|
|
39
|
+
// starts up and begins streaming, subsequent frames will be returned
|
|
40
|
+
// instantaneously
|
|
41
|
+
let lastFrame;
|
|
42
|
+
frame.addEventListener('click', async () => {
|
|
43
|
+
stop.disabled = true
|
|
44
|
+
rotation.disabled = true
|
|
45
|
+
const rotate = parseInt(rotation.value)
|
|
46
|
+
// Cleanup the last frame captured, if any
|
|
47
|
+
if (lastFrame) {
|
|
48
|
+
URL.revokeObjectURL(lastFrame)
|
|
49
|
+
}
|
|
50
|
+
img.src = lastFrame = await camera.getMostRecentFrame({rotate})
|
|
51
|
+
rotation.disabled = false
|
|
52
|
+
stop.disabled = false
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Stop live feed
|
|
56
|
+
stop.addEventListener('click', async () => {
|
|
57
|
+
const result = await camera.stopFeed()
|
|
58
|
+
alert(result.message || result.status)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(e)
|
|
63
|
+
alert(`Error: ${e.message}`)
|
|
64
|
+
}
|
|
65
|
+
})()
|
|
66
|
+
</script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Canon Camera LAN Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<img id="img"/>
|
|
6
|
+
<div>
|
|
7
|
+
<div>
|
|
8
|
+
<label>Rotate</label>
|
|
9
|
+
<input type="number" value="0" id="rotate" min="-360" max="360" step="90"/>
|
|
10
|
+
</div>
|
|
11
|
+
<button type="button" id="capture" title="Capture Image">
|
|
12
|
+
Capture
|
|
13
|
+
</button>
|
|
14
|
+
<button type="button" id="stream" title="Stream Live Feed">
|
|
15
|
+
Stream
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module">
|
|
19
|
+
import CanonCamera from '/sdk/js/CanonCamera.js'
|
|
20
|
+
(async () => {
|
|
21
|
+
const defaultSrc = '/demo/img/empty.jpg'
|
|
22
|
+
const defaultWidth = 400
|
|
23
|
+
const img = document.getElementById('img')
|
|
24
|
+
const capture = document.getElementById('capture')
|
|
25
|
+
const stream = document.getElementById('stream')
|
|
26
|
+
const rotation = document.getElementById('rotate')
|
|
27
|
+
|
|
28
|
+
img.src = defaultSrc
|
|
29
|
+
img.width = defaultWidth
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const defaultURL = 'https://windev2-local.capturebridge.net:9001'
|
|
33
|
+
const url = prompt('Enter remote Base URL', defaultURL)
|
|
34
|
+
const camera = new CanonCamera(url)
|
|
35
|
+
const devices = await camera.devices();
|
|
36
|
+
|
|
37
|
+
if (!devices.length) {
|
|
38
|
+
return alert('No Canon Camera devices found')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Start the first device's live feed and stream it to the img tag
|
|
42
|
+
stream.addEventListener('click', async () => {
|
|
43
|
+
const rotate = parseInt(rotation.value)
|
|
44
|
+
rotation.disabled = true
|
|
45
|
+
stream.disabled = true
|
|
46
|
+
img.src = await camera.streamUrl({rotate})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Take a full capture and add the image to the page
|
|
50
|
+
capture.addEventListener('click', async () => {
|
|
51
|
+
const rotate = parseInt(rotation.value)
|
|
52
|
+
const capture = document.createElement('img')
|
|
53
|
+
img.src = defaultSrc
|
|
54
|
+
capture.src = await camera.takePhoto({rotate})
|
|
55
|
+
capture.width = defaultWidth
|
|
56
|
+
document.body.appendChild(capture)
|
|
57
|
+
rotation.disabled = false
|
|
58
|
+
stream.disabled = false
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(e)
|
|
63
|
+
alert(`Error: ${e.message}`)
|
|
64
|
+
}
|
|
65
|
+
})()
|
|
66
|
+
</script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Canon Camera Minimal Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<script type="module">
|
|
6
|
+
import CanonCamera from '/sdk/js/CanonCamera.js'
|
|
7
|
+
(async () => {
|
|
8
|
+
try {
|
|
9
|
+
|
|
10
|
+
// Instantiate a Canon Camera
|
|
11
|
+
const camera = new CanonCamera()
|
|
12
|
+
|
|
13
|
+
const devices = await camera.devices();
|
|
14
|
+
|
|
15
|
+
if (!devices.length) {
|
|
16
|
+
return alert('No Canon Camera devices found')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Start the device's live feed and stream it to an img tag
|
|
20
|
+
const img = document.createElement('img')
|
|
21
|
+
img.src = await camera.streamUrl()
|
|
22
|
+
img.height = 400
|
|
23
|
+
document.body.appendChild(img)
|
|
24
|
+
|
|
25
|
+
// Demo live feed for a few seconds, take a picture, and update the img tag
|
|
26
|
+
setTimeout(async () => {
|
|
27
|
+
img.src = await camera.takePhoto()
|
|
28
|
+
}, 9000)
|
|
29
|
+
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.error(e)
|
|
32
|
+
alert(`Error: ${e.message}`)
|
|
33
|
+
}
|
|
34
|
+
})()
|
|
35
|
+
</script>
|
|
36
|
+
</body>
|
|
37
|
+
</html>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Mock Camera Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<img id="img" src="/demo/img/empty.jpg"/>
|
|
6
|
+
<div>
|
|
7
|
+
<div>
|
|
8
|
+
<label>Rotate</label>
|
|
9
|
+
<input type="number" value="0" id="rotate" min="-360" max="360" step="90"/>
|
|
10
|
+
</div>
|
|
11
|
+
<button type="button" id="capture" title="Capture Image">
|
|
12
|
+
Capture
|
|
13
|
+
</button>
|
|
14
|
+
<button type="button" id="stream" title="Stream Live Feed">
|
|
15
|
+
Stream
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module">
|
|
19
|
+
import MockCamera from '/sdk/js/MockCamera.js'
|
|
20
|
+
(async () => {
|
|
21
|
+
const defaultSrc = '/demo/img/empty.jpg'
|
|
22
|
+
const defaultWidth = 400
|
|
23
|
+
const img = document.getElementById('img')
|
|
24
|
+
const capture = document.getElementById('capture')
|
|
25
|
+
const stream = document.getElementById('stream')
|
|
26
|
+
const rotation = document.getElementById('rotate')
|
|
27
|
+
|
|
28
|
+
img.src = defaultSrc
|
|
29
|
+
img.width = defaultWidth
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const camera = new MockCamera()
|
|
33
|
+
|
|
34
|
+
// Start the first device's live feed and stream it to the img tag
|
|
35
|
+
stream.addEventListener('click', async () => {
|
|
36
|
+
const rotate = parseInt(rotation.value)
|
|
37
|
+
rotation.disabled = true
|
|
38
|
+
stream.disabled = true
|
|
39
|
+
img.src = await camera.streamUrl({rotate})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Take a full capture and add the image to the page
|
|
43
|
+
capture.addEventListener('click', async () => {
|
|
44
|
+
const rotate = parseInt(rotation.value)
|
|
45
|
+
const capture = document.createElement('img')
|
|
46
|
+
img.src = defaultSrc
|
|
47
|
+
capture.src = await camera.takePhoto({rotate})
|
|
48
|
+
capture.width = defaultWidth
|
|
49
|
+
document.body.appendChild(capture)
|
|
50
|
+
rotation.disabled = false
|
|
51
|
+
stream.disabled = false
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error(e)
|
|
56
|
+
alert(`Error: ${e.message}`)
|
|
57
|
+
}
|
|
58
|
+
})()
|
|
59
|
+
</script>
|
|
60
|
+
</body>
|
|
61
|
+
</html>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Mock Camera Frame Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<div>
|
|
6
|
+
<img id="img"/>
|
|
7
|
+
<div>
|
|
8
|
+
<label>Rotate</label>
|
|
9
|
+
<input type="number" value="0" id="rotate" min="-360" max="360" step="90"/>
|
|
10
|
+
</div>
|
|
11
|
+
<button type="button" id="frame" title="Grab Frame from live feed">
|
|
12
|
+
Get Frame
|
|
13
|
+
</button>
|
|
14
|
+
<button type="button" id="stop" title="Stop live feed">
|
|
15
|
+
Stop Feed
|
|
16
|
+
</button>
|
|
17
|
+
</div>
|
|
18
|
+
<script type="module">
|
|
19
|
+
import MockCamera from '/sdk/js/MockCamera.js'
|
|
20
|
+
(async () => {
|
|
21
|
+
const defaultSrc = '/demo/img/empty.jpg'
|
|
22
|
+
const img = document.getElementById('img')
|
|
23
|
+
const rotation = document.getElementById('rotate')
|
|
24
|
+
const frame = document.getElementById('frame')
|
|
25
|
+
const stop = document.getElementById('stop')
|
|
26
|
+
|
|
27
|
+
img.src = defaultSrc
|
|
28
|
+
img.width = 400
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const camera = new MockCamera()
|
|
32
|
+
const devices = await camera.devices()
|
|
33
|
+
|
|
34
|
+
// Grab a frame from the live feed
|
|
35
|
+
let lastFrame;
|
|
36
|
+
frame.addEventListener('click', async () => {
|
|
37
|
+
stop.disabled = true
|
|
38
|
+
rotation.disabled = true
|
|
39
|
+
const rotate = parseInt(rotation.value)
|
|
40
|
+
// Cleanup the last frame captured, if any
|
|
41
|
+
if (lastFrame) {
|
|
42
|
+
URL.revokeObjectURL(lastFrame)
|
|
43
|
+
}
|
|
44
|
+
img.src = lastFrame = await camera.getMostRecentFrame({rotate})
|
|
45
|
+
document.body.appendChild(frame)
|
|
46
|
+
rotation.disabled = false
|
|
47
|
+
stop.disabled = false
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Stop live feed
|
|
51
|
+
stop.addEventListener('click', async () => {
|
|
52
|
+
const result = await camera.stopFeed()
|
|
53
|
+
alert(result.message || result.status)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error(e)
|
|
58
|
+
alert(`Error: ${e.message}`)
|
|
59
|
+
}
|
|
60
|
+
})()
|
|
61
|
+
</script>
|
|
62
|
+
</body>
|
|
63
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Mock Camera Minimal Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<script type="module">
|
|
6
|
+
import MockCamera from '/sdk/js/MockCamera.js'
|
|
7
|
+
(async () => {
|
|
8
|
+
try {
|
|
9
|
+
|
|
10
|
+
// Instantiate a Mock Camera
|
|
11
|
+
const camera = new MockCamera()
|
|
12
|
+
|
|
13
|
+
// Start the device's live feed and stream it to an img tag
|
|
14
|
+
const img = document.createElement('img')
|
|
15
|
+
img.src = await camera.streamUrl()
|
|
16
|
+
img.height = 400
|
|
17
|
+
document.body.appendChild(img)
|
|
18
|
+
|
|
19
|
+
// Demo live feed for a few seconds, take a picture, and update the img tag
|
|
20
|
+
setTimeout(async () => {
|
|
21
|
+
img.src = await camera.takePhoto()
|
|
22
|
+
}, 9000)
|
|
23
|
+
|
|
24
|
+
} catch (e) {
|
|
25
|
+
console.error(e)
|
|
26
|
+
alert(`Error: ${e.message}`)
|
|
27
|
+
}
|
|
28
|
+
})()
|
|
29
|
+
</script>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Verifone Minimal Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<script type="module">
|
|
6
|
+
import Verifone from '/sdk/js/Verifone.js'
|
|
7
|
+
(async () => {
|
|
8
|
+
try {
|
|
9
|
+
const tablet = new Verifone()
|
|
10
|
+
|
|
11
|
+
const img = document.createElement('img')
|
|
12
|
+
img.src = await tablet.signature({format: 'jpg'})
|
|
13
|
+
await tablet.clear()
|
|
14
|
+
document.body.appendChild(img)
|
|
15
|
+
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(e)
|
|
18
|
+
alert(`Error: ${e.message}`)
|
|
19
|
+
}
|
|
20
|
+
})()
|
|
21
|
+
</script>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head><title>Windows Scanner Example</title></head>
|
|
4
|
+
<body>
|
|
5
|
+
<img id="img"/>
|
|
6
|
+
<script type="module">
|
|
7
|
+
import WindowsScanner from '/sdk/js/WindowsScanner.js'
|
|
8
|
+
(async () => {
|
|
9
|
+
try {
|
|
10
|
+
|
|
11
|
+
const scanner = new WindowsScanner()
|
|
12
|
+
|
|
13
|
+
const devices = await scanner.devices();
|
|
14
|
+
|
|
15
|
+
if (!devices.length) {
|
|
16
|
+
return alert('No Scanner devices found')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let scan = await scanner.scan()
|
|
20
|
+
|
|
21
|
+
document.createElement('img')
|
|
22
|
+
img.src = await scanner.scan()
|
|
23
|
+
document.body.appendChild(img)
|
|
24
|
+
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(e)
|
|
27
|
+
alert(`Error: ${e.message}`)
|
|
28
|
+
}
|
|
29
|
+
})()
|
|
30
|
+
</script>
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|