summaryrefslogtreecommitdiffhomepage
path: root/app/lib/backend.js
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-07-06 12:48:52 +0200
committerErik Larkö <erik@mullvad.net>2017-07-07 10:13:17 +0200
commit00a09cd164be3d2a24cd4634b594c278c8c24da9 (patch)
tree10e62d195603fb8cc940fad2068475d4c1009ec6 /app/lib/backend.js
parent35f2a91585f4c94de2e4668eab99890fa50c22a9 (diff)
downloadmullvadvpn-00a09cd164be3d2a24cd4634b594c278c8c24da9.tar.xz
mullvadvpn-00a09cd164be3d2a24cd4634b594c278c8c24da9.zip
The Backend class is no longer an EventEmitter
Diffstat (limited to 'app/lib/backend.js')
-rw-r--r--app/lib/backend.js44
1 files changed, 9 insertions, 35 deletions
diff --git a/app/lib/backend.js b/app/lib/backend.js
index da2bc60613..9c5b2ed064 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -94,7 +94,7 @@ export class Backend {
this._ipc.getIp()
.then( ip => {
log.info('Got ip', ip);
- this._emit('updatedIp', ip);
+ this._store.dispatch(connectionActions.connectionChange({ clientIp: ip }));
})
.catch(e => {
log.info('Failed syncing with the backend', e);
@@ -108,7 +108,7 @@ export class Backend {
country: location.country,
city: location.city
};
- this._emit('updatedLocation', newLocation, null);
+ this._store.dispatch(accountActions.loginChange(newLocation));
})
.catch(e => {
log.info('Failed getting new location', e);
@@ -147,9 +147,6 @@ export class Backend {
login(accountNumber: string) {
log.info('Attempting to login with account number', accountNumber);
- // emit: logging in
- this._emit('logging', { accountNumber: accountNumber }, null);
-
this._store.dispatch(accountActions.loginChange({
accountNumber: accountNumber,
status: 'connecting',
@@ -166,10 +163,6 @@ export class Backend {
}).then( accountData => {
log.info('Log in complete');
- this._emit('login', {
- paidUntil: accountData.paid_until,
- }, undefined);
-
this._store.dispatch(accountActions.loginChange({
status: 'ok',
paidUntil: accountData.paid_until,
@@ -190,8 +183,6 @@ export class Backend {
status: 'failed',
error: err,
}));
-
- this._emit('login', {}, err);
});
}
@@ -200,8 +191,6 @@ export class Backend {
// @TODO: What does it mean for a logout to be successful or failed?
this._ipc.setAccount('')
.then(() => {
- // emit event
- this._emit('logout');
this._store.dispatch(accountActions.loginChange({
status: 'none',
@@ -222,8 +211,6 @@ export class Backend {
connect(addr: string) {
- // emit: connecting
- this._emit('connecting', addr);
this._store.dispatch(connectionActions.connectionChange({
status: 'connecting',
serverAddress: addr,
@@ -236,7 +223,6 @@ export class Backend {
})
.catch(e => {
log.info('Failed connecting to', addr, e);
- this._emit('connect', undefined, e);
this._store.dispatch(connectionActions.connectionChange({
status: 'disconnected',
}));
@@ -257,15 +243,19 @@ export class Backend {
* with proper backend integration.
*/
_startReachability() {
- window.addEventListener('online', () => this._emit('updatedReachability', true));
+ window.addEventListener('online', () => {
+ this._store.dispatch(connectionActions.connectionChange({ isOnline: true }));
+ });
window.addEventListener('offline', () => {
// force disconnect since there is no real connection anyway.
this.disconnect();
- this._emit('updatedReachability', false);
+ this._store.dispatch(connectionActions.connectionChange({ isOnline: false }));
});
// update online status in background
- setTimeout(() => this._emit('updatedReachability', navigator.onLine), 0);
+ setTimeout(() => {
+ this._store.dispatch(connectionActions.connectionChange({ isOnline: navigator.onLine }));
+ }, 0);
}
_registerIpcListeners() {
@@ -292,20 +282,4 @@ export class Backend {
throw new Error('Unknown backend state: ' + backendState);
}
}
-
- on(event: EventType, listener: Function) {
- this._eventEmitter.on(event, listener);
- }
-
- once(event: EventType, listener: Function) {
- this._eventEmitter.once(event, listener);
- }
-
- off(event: EventType, listener: Function) {
- this._eventEmitter.removeListener(event, listener);
- }
-
- _emit(event: EventType, ...args:Array<any>): boolean {
- return this._eventEmitter.emit(event, ...args);
- }
}