diff options
| author | David Lönnhager <david.l@mullvad.net> | 2022-07-06 13:22:37 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-07-11 13:51:26 +0200 |
| commit | f7a3a5a6d33faa6ea6efc397ed2b7455e40e279c (patch) | |
| tree | 659b6dcb9cacac24dd66fe7f3fda174fb1822eae /gui/src/main | |
| parent | 0c3a1f9d9aa8f35f33549c99c3d312f4ebc93f3b (diff) | |
| download | mullvadvpn-f7a3a5a6d33faa6ea6efc397ed2b7455e40e279c.tar.xz mullvadvpn-f7a3a5a6d33faa6ea6efc397ed2b7455e40e279c.zip | |
Return RelayList object instead of a stream in proto file
Diffstat (limited to 'gui/src/main')
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index a868208ac2..310a9a5c83 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -246,17 +246,10 @@ export class DaemonRpc { } } - public getRelayLocations(): Promise<IRelayList> { + public async getRelayLocations(): Promise<IRelayList> { if (this.isConnected) { - return new Promise((resolve, reject) => { - const relayLocations: IRelayListCountry[] = []; - const stream = this.client.getRelayLocations(new Empty()); - stream.on('data', (country: grpcTypes.RelayListCountry) => - relayLocations.push(convertFromRelayListCountry(country.toObject())), - ); - stream.on('end', () => resolve({ countries: relayLocations })); - stream.on('close', reject); - }); + const response = await this.callEmpty<grpcTypes.RelayList>(this.client.getRelayLocations); + return convertFromRelayList(response); } else { throw noConnectionError; } @@ -711,6 +704,16 @@ function liftConstraint<T>(constraint: Constraint<T> | undefined): T | undefined return undefined; } +function convertFromRelayList(relayList: grpcTypes.RelayList): IRelayList { + return { + countries: relayList + .getCountriesList() + .map((country: grpcTypes.RelayListCountry) => + convertFromRelayListCountry(country.toObject()), + ), + }; +} + function convertFromRelayListCountry( country: grpcTypes.RelayListCountry.AsObject, ): IRelayListCountry { @@ -1160,15 +1163,7 @@ function convertFromDaemonEvent(data: grpcTypes.DaemonEvent): DaemonEvent { const relayList = data.getRelayList(); if (relayList !== undefined) { - return { - relayList: { - countries: relayList - .getCountriesList() - ?.map((country: grpcTypes.RelayListCountry) => - convertFromRelayListCountry(country.toObject()), - ), - }, - }; + return { relayList: convertFromRelayList(relayList) }; } const deviceConfig = data.getDevice(); |
