Constructor
#
new TWTwainJS(name, companyName, key, twConsole)
Creates an instance of TWTwainJS.
Parameters:
| Name |
Type |
Description |
name |
string
|
The name of the TWTwainJS instance. |
companyName |
string
|
License company name |
key |
string
|
License key |
twConsole |
object
|
The console object to be used for logging. Used only for debugging purposes. |
Members
#
autoReconnect :boolean
Reconnect automatically when the connection to the client is lost, for example because
the client restarted itself after a scanner failure (TWErrorCode.CLIENT_RESTARTING).
The port range given to connectToClient is scanned again, with a growing pause between
rounds, for up to reconnectTimeoutMs. TWEvent.SOCKET_CONNECTION_STATUS_CHANGED is raised
with CLOSED when the connection drops (detail.reconnecting is true) and with CONNECTED once
it is back (detail.reconnected is true); the attempts in between raise nothing. If the
client does not come back in time, TWEvent.TW_ERROR is raised once.
Set it to false when the integration reconnects on its own.
#
id :string
The id of the twTwainJS instance. It is set automatically when the connect method succeeds.
Basic information about the twTwainJS instance.
#
name :string
The name of the TWTwainJS instance.
#
port :number
The port used for the socket communication. It is set automatically when the connect method succeeds.
#
reconnectTimeoutMs :number
How long autoReconnect keeps trying, in milliseconds.
The result of the last scan.
Methods
#
cancelConnect() → {boolean}
Stop looking for the client: the port walk started by connectToClient is abandoned and
its promise is rejected with TWConnectCancelled; a running autoReconnect is cancelled too.
Useful when the user sees that the client is not installed and does not want to wait for
the whole port range. An established connection is not touched.
Returns:
- true when a walk was in progress and has been stopped.
-
Type
-
boolean
#
connectToClient(fromPort, toPort) → {Promise}
Connect to the TWTwain client and open the WebSocket connection trying to
find a first valid port in the from and to range.
If the connection is successful, the onConnected event is raised otherwise No valid socket found is raised.
The same range is used again by autoReconnect if the connection is lost later.
Parameters:
| Name |
Type |
Description |
fromPort |
number
|
The starting port number in client port range. |
toPort |
number
|
The ending port number in client port range. |
Returns:
- A promise that resolves when the connection is successful.
-
Type
-
Promise
#
downloadFile(downloadMode, settings) → {Promise}
Download the specified file in the file format specified in the fileName extension.
For every single file downloaded, TWEvent.SINGLE_FILE_DOWNLOADED is triggered.
Once all the files are downloaded, TWEvent.DOWNLOAD_FINISHED is triggered.
Parameters:
| Name |
Type |
Description |
downloadMode |
TWDownloadMode
|
download mode. Allowed values are TWDownloadMode.LOCAL ("local") or TWDownloadMode.STANDARD ("standard").
Local mode saves the file to the local machine based on TWTwain client settings.
Standard mode uses the browser's download functionality. |
settings |
ScannedFileSettings
|
Scanned file settings. |
Returns:
- Promise object represents the download result.
-
Type
-
Promise
#
getAvailableDevices() → {Promise}
Execute retrieving the available devices and current default device from the client.
Once finished, event TWWEvent.DEVICE_LIST_RETRIEVED is triggered.
Returns:
- Promise object represents the available devices retrieve result.
-
Type
-
Promise
#
getCurrentSettings(capNames, deviceName) → {Promise}
Execute retrieving the current capability values from the client.
Once finished, event TWEvent.CURRENT_SETTINGS_RECEIVED is triggered.
Parameters:
| Name |
Type |
Description |
capNames |
*
|
Array of capability names to retrieve the values for. |
deviceName |
string
|
Name of the device to retrieve the capabilities from. |
Returns:
- Promise object represents the current settings retrieve result.
-
Type
-
Promise
#
getDeviceInfo(deviceName, ignoreCurrentValues) → {Promise}
Open the specified scanner device and reads its capabilities and current values.
Once opened, event TWEvent.DEVICE_INFO_RETRIEVIED is triggered with the device name and capabilities in the detail.
Parameters:
| Name |
Type |
Default |
Description |
deviceName |
string
|
|
Name of the device to open. |
ignoreCurrentValues |
boolean
|
false
|
If true, the current values of the capabilities are not retrieved. It could be good for performance.
Default is false. |
Returns:
- Promise object represents the device info.
-
Type
-
Promise
#
getFile(settings) → {Promise}
Retrieves the specified file(s) in the file format specified in the fileName extension.
For every single file retrieved, TWEvent.SINGLE_FILE_RETRIEVED is triggered.
Once all the files are retrieved, TWEvent.FILE_RETRIEVE_FINISHED is triggered.
Returns:
- Promise object represents the file retrieve result.
-
Type
-
Promise
#
scan(scanSettings) → {Promise}
Execute scanning from the TWTwain client using the specified settings in capability property.
Once the page is scanned, TWEvent.PAGE_SCANNED is triggered.
Once the scanning finishes, TWEvent.SCAN_FINISHED is triggered with scanFinishedStatus set to
TWScanFinishedStatus.SUCCESS if the scanning is successful
or TWScanFinishedStatus.ERROR if the scanning is not successful
or TWScanFinishedStatus.CANCEL if the scanning is cancelled.
A page that fails to reach the browser does not fail the scan: the client keeps every page,
so the resulting file is complete either way. Such a page is requested again automatically
and leaves an empty slot in scanResult.images until it arrives. See ScanResult.missingPages().
The promise is rejected if the connection to the client is lost. There is no timeout, since
with showUI the user may keep the scanner dialog open for as long as they like.
Parameters:
| Name |
Type |
Description |
scanSettings |
ScanSettings
|
Scan settings. |
Returns:
- Promise object represents the scan result.
-
Type
-
Promise