diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-05-28 00:30:34 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-05-28 08:13:11 +0200 |
| commit | 3632bdf60ec8021c9d41e40d72a1a37edee5a658 (patch) | |
| tree | fb4a5c93b497705c1d3d3a3e267a2b8f29b6ef30 | |
| parent | f6cc8959a01bb245095f959f6c7ff0be1867e2fa (diff) | |
| download | mullvadvpn-3632bdf60ec8021c9d41e40d72a1a37edee5a658.tar.xz mullvadvpn-3632bdf60ec8021c9d41e40d72a1a37edee5a658.zip | |
Prepare for tests: Allow Ipc to accept a WebSocketFactory
| -rw-r--r-- | app/lib/backend.js | 2 | ||||
| -rw-r--r-- | app/lib/ipc-facade.js | 2 | ||||
| -rw-r--r-- | app/lib/jsonrpc-ws-ipc.js | 6 |
3 files changed, 6 insertions, 4 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index ce7c6d17c3..7cf1d5b043 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -171,7 +171,7 @@ export default class Backend extends EventEmitter { */ constructor(ipc: IpcFacade) { super(); - this._ipc = ipc || new RealIpc(undefined); + this._ipc = ipc || new RealIpc(''); this._registerIpcListeners(); // check for network reachability diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index 03fa4f961a..f344c80d7b 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -25,7 +25,7 @@ export class RealIpc implements IpcFacade { _ipc: JsonRpcWs; - constructor(connectionString: ?string) { + constructor(connectionString: string) { this._ipc = new JsonRpcWs(connectionString); } diff --git a/app/lib/jsonrpc-ws-ipc.js b/app/lib/jsonrpc-ws-ipc.js index 1fdcdf6428..71848e9df6 100644 --- a/app/lib/jsonrpc-ws-ipc.js +++ b/app/lib/jsonrpc-ws-ipc.js @@ -48,12 +48,14 @@ export default class Ipc { _subscriptions: {[string]: (any) => void}; _websocket: WebSocket; _backoff: ReconnectionBackoff; + _websocketFactory: (string) => WebSocket; - constructor(connectionString: ?string) { + constructor(connectionString: string, websocketFactory: ?(string)=>WebSocket) { this._connectionString = connectionString; this._onConnect = []; this._unansweredRequests = {}; this._subscriptions = {}; + this._websocketFactory = websocketFactory || function(connectionString){return new WebSocket(connectionString);}; this._backoff = new ReconnectionBackoff(); this._reconnect(); @@ -170,7 +172,7 @@ export default class Ipc { if (!connectionString) return; log.info('Connecting to websocket', connectionString); - this._websocket = new WebSocket(connectionString); + this._websocket = this._websocketFactory(connectionString); this._websocket.onopen = () => { log.debug('Websocket is connected'); |
