|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { SQLiteCloudConfig, SQLiteCloudError, ErrorCallback, ResultsCallback } from './types' |
6 | | -import { parseConnectionString, parseBoolean } from './utilities' |
7 | | - |
8 | | -/** tls.TLSSocket is required to connect using TlsSocketTransport but is only supported in node.js environments */ |
9 | | -let tlsSupported = false |
10 | | -import('tls') |
11 | | - .then(() => { |
12 | | - tlsSupported = true |
13 | | - }) |
14 | | - .catch(() => { |
15 | | - tlsSupported = false |
16 | | - }) |
| 6 | +import { parseConnectionString, parseBoolean, isBrowser, isNode } from './utilities' |
17 | 7 |
|
18 | 8 | /** Default timeout value for queries */ |
19 | 9 | export const DEFAULT_TIMEOUT = 300 * 1000 |
20 | | - |
21 | 10 | /** Default tls connection port */ |
22 | 11 | export const DEFAULT_PORT = 9960 |
23 | 12 |
|
@@ -60,7 +49,7 @@ export class SQLiteCloudConnection { |
60 | 49 | protected connect(callback?: ErrorCallback): this { |
61 | 50 | this.operations.enqueue(done => { |
62 | 51 | // connect using websocket if tls is not supported or if explicitly requested |
63 | | - if (!tlsSupported || this.config?.websocketOptions?.useWebsocket || this.config?.websocketOptions?.gatewayUrl) { |
| 52 | + if (isBrowser || this.config?.useWebsocket || this.config?.gatewayUrl) { |
64 | 53 | // socket.io transport works in both node.js and browser environments and connects via SQLite Cloud Gateway |
65 | 54 | import('./transport-ws') |
66 | 55 | .then(transport => { |
@@ -127,6 +116,7 @@ export class SQLiteCloudConnection { |
127 | 116 | config.sqliteMode = parseBoolean(config.sqliteMode) |
128 | 117 |
|
129 | 118 | if (!config.username || !config.password || !config.host) { |
| 119 | + console.error(`SQLiteCloudConnection.validateConfiguration - missing arguments`, config) |
130 | 120 | throw new SQLiteCloudError('The user, password and host arguments must be specified.', { errorCode: 'ERR_MISSING_ARGS' }) |
131 | 121 | } |
132 | 122 |
|
|
0 commit comments