-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (31 loc) · 1.13 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const openapiInclude = require('./openapiIncludeAsync');
const host = 'server.name'; // Deephaven server URL
const credentials = { username: 'user', token: 'pass', type: 'password' };
const apiFileName = 'irisapi.nocache.js'; // Only change if the file name changes on the server
let client;
start();
async function start() {
try {
await openapiInclude(`https://${host}/irisapi/${apiFileName}`, apiFileName);
const wsUrl = `wss://${host}/socket`;
client = new iris.Client(wsUrl);
client.addEventListener(iris.Client.EVENT_CONNECT, async () => {
await client.login(credentials);
console.log('logged in');
// Do things with Deephaven!
});
client.addEventListener(iris.Client.EVENT_RECONNECT, async () => {
console.log('reconnected and already authenticated');
});
client.addEventListener(iris.Client.EVENT_RECONNECT_AUTH_FAILED, async () => {
console.log('need to reauth');
start();
})
client.addEventListener(iris.Client.EVENT_DISCONNECT, () => {
console.log('disconnected');
setTimeout(start, 30000);
});
} catch(err) {
console.error(err);
}
}