diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-05-23 12:35:34 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-05-27 14:13:39 +0200 |
| commit | fa490aab87b341daed7ca3b4b862b376f0018e2a (patch) | |
| tree | a57001357f2539fe66dad4c19b2ff043706f6573 | |
| parent | 5a1906da043d751ab86b3bab5a595838bc50817d (diff) | |
| download | mullvadvpn-fa490aab87b341daed7ca3b4b862b376f0018e2a.tar.xz mullvadvpn-fa490aab87b341daed7ca3b4b862b376f0018e2a.zip | |
Flow in backend.js
| -rw-r--r-- | app/lib/backend.js | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js index 1a0daf005f..d310c6f28d 100644 --- a/app/lib/backend.js +++ b/app/lib/backend.js @@ -1,6 +1,8 @@ +// @flow + import log from 'electron-log'; import Enum from './enum'; -import { EventEmitter } from 'events'; +import EventEmitter from 'events'; import { servers } from '../config'; import Ipc from './ipc'; @@ -80,6 +82,9 @@ import Ipc from './ipc'; */ class BackendError extends Error { + code: number; + title: string; + message: string; constructor(code) { super(''); @@ -112,6 +117,12 @@ class BackendError extends Error { } +type Location = { + latlong: Array<number>, + city: string, + country: string, +}; + /** * Backend implementation * @@ -158,12 +169,14 @@ export default class Backend extends EventEmitter { */ static EventType = new Enum('connect', 'connecting', 'disconnect', 'login', 'logging', 'logout', 'updatedIp', 'updatedLocation', 'updatedReachability'); + _ipc: Ipc; + /** * Creates an instance of Backend. * * @memberOf Backend */ - constructor(ipc) { + constructor(ipc: Ipc) { super(); this._ipc = ipc || new Ipc(undefined); this._registerIpcListeners(); @@ -172,7 +185,7 @@ export default class Backend extends EventEmitter { this._startReachability(); } - setLocation(loc) { + setLocation(loc: string) { log.info('Got connection info to backend', loc); this._ipc = new Ipc(loc); @@ -183,7 +196,7 @@ export default class Backend extends EventEmitter { log.info('Syncing with the backend...'); this._ipc.send('get_ip') - .then( ip => { + .then( (ip: string) => { log.info('Got ip', ip); this.emit(Backend.EventType.updatedIp, ip); }) @@ -192,7 +205,7 @@ export default class Backend extends EventEmitter { }); this._ipc.send('get_location') - .then(location => { + .then((location: Location) => { log.info('Got location', location); const newLocation = { location: location.latlong, @@ -215,7 +228,7 @@ export default class Backend extends EventEmitter { * * @memberOf Backend */ - serverInfo(key) { + serverInfo(key: string) { switch(key) { case 'fastest': return this.fastestServer(); case 'nearest': return this.nearestServer(); @@ -266,7 +279,7 @@ export default class Backend extends EventEmitter { * * @memberOf Backend */ - login(account) { + login(account: string) { log.info('Attempting to login with account number', account); // emit: logging in @@ -324,7 +337,7 @@ export default class Backend extends EventEmitter { * * @memberOf Backend */ - connect(addr) { + connect(addr: string) { // emit: connecting this.emit(Backend.EventType.connecting, addr); |
