diff --git a/keyserver/src/socket/tunnelbroker-socket.js b/keyserver/src/socket/tunnelbroker-socket.js --- a/keyserver/src/socket/tunnelbroker-socket.js +++ b/keyserver/src/socket/tunnelbroker-socket.js @@ -37,7 +37,11 @@ heartbeatTimeoutID: ?TimeoutID; oneTimeKeysPromise: ?Promise; - constructor(socketURL: string, initMessage: ConnectionInitializationMessage) { + constructor( + socketURL: string, + initMessage: ConnectionInitializationMessage, + onClose: () => mixed, + ) { const socket = new WebSocket(socketURL); socket.on('open', () => { @@ -54,6 +58,7 @@ this.connected = false; this.stopHeartbeatTimeout(); console.error('Connection to Tunnelbroker closed'); + onClose(); }); socket.on('error', (error: Error) => { diff --git a/keyserver/src/socket/tunnelbroker.js b/keyserver/src/socket/tunnelbroker.js --- a/keyserver/src/socket/tunnelbroker.js +++ b/keyserver/src/socket/tunnelbroker.js @@ -2,6 +2,7 @@ import type { ConnectionInitializationMessage } from 'lib/types/tunnelbroker/session-types.js'; import { getCommConfig } from 'lib/utils/comm-config.js'; +import sleep from 'lib/utils/sleep.js'; import TunnelbrokerSocket from './tunnelbroker-socket.js'; import { type IdentityInfo } from '../user/identity.js'; @@ -43,7 +44,13 @@ deviceType: 'keyserver', }; - new TunnelbrokerSocket(tbConnectionInfo.url, initMessage); + const createNewTunnelbrokerSocket = () => { + new TunnelbrokerSocket(tbConnectionInfo.url, initMessage, async () => { + await sleep(3000); + createNewTunnelbrokerSocket(); + }); + }; + createNewTunnelbrokerSocket(); } export { createAndMaintainTunnelbrokerWebsocket };