Skip to content

Commit 99b4e4e

Browse files
committed
Load the ICE servers from the new faf-icebreaker API
1 parent 3cea443 commit 99b4e4e

File tree

7 files changed

+34
-15
lines changed

7 files changed

+34
-15
lines changed

src/main/java/com/faforever/client/api/FafApiAccessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ public Mono<MeResult> getMe() {
157157
.doOnNext(object -> log.trace("Retrieved {} from /me with type MeResult", object));
158158
}
159159

160+
public Mono<IceSession> getIceSession(int gameId) {
161+
return retrieveMonoWithErrorHandling(IceSession.class, apiWebClient.get().uri("/ice/session/game/" + gameId))
162+
.doOnNext(object -> log.trace("Retrieved {} from /ice/session/game/{} with type MeResult", object, gameId));
163+
}
164+
160165
public Mono<Void> uploadFile(String endpoint, Path file, ByteCountListener listener,
161166
java.util.Map<String, java.util.Map<String, ?>> params) {
162167
MultiValueMap<String, Object> multipartContent = createFileMultipart(file, listener);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.faforever.client.api;
2+
3+
import com.faforever.commons.api.dto.CoturnServer;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
import java.util.List;
8+
9+
@JsonIgnoreProperties(ignoreUnknown = true)
10+
public record IceSession(@NotNull String id, @NotNull List<CoturnServer> servers) {
11+
}

src/main/java/com/faforever/client/fa/relay/ice/CoturnService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.faforever.client.fa.relay.ice;
22

33
import com.faforever.client.api.FafApiAccessor;
4+
import com.faforever.client.api.IceSession;
45
import com.faforever.client.mapstruct.IceServerMapper;
56
import com.faforever.client.preferences.ForgedAlliancePrefs;
67
import com.faforever.commons.api.dto.CoturnServer;
@@ -31,9 +32,9 @@ public CompletableFuture<List<CoturnServer>> getActiveCoturns() {
3132
.toFuture();
3233
}
3334

34-
public CompletableFuture<List<CoturnServer>> getSelectedCoturns() {
35-
ElideNavigatorOnCollection<CoturnServer> navigator = ElideNavigator.of(CoturnServer.class).collection();
36-
Flux<CoturnServer> coturnServerFlux = fafApiAccessor.getMany(navigator);
35+
public CompletableFuture<List<CoturnServer>> getSelectedCoturns(int gameId) {
36+
Flux<CoturnServer> coturnServerFlux = fafApiAccessor.getIceSession(gameId)
37+
.flatMapIterable(IceSession::servers);
3738

3839
Set<String> preferredCoturnIds = forgedAlliancePrefs.getPreferredCoturnIds();
3940

src/main/java/com/faforever/client/game/GameService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ private CompletableFuture<Void> startGame(GameParameters gameParameters) {
665665
localReplayPort = port;
666666
return iceAdapter.start(gameParameters.getUid());
667667
})
668-
.thenCompose(adapterPort -> coturnService.getSelectedCoturns()
668+
.thenCompose(adapterPort -> coturnService.getSelectedCoturns(uid)
669669
.thenAccept(iceAdapter::setIceServers)
670670
.thenApply(aVoid -> adapterPort))
671671
.thenApply(adapterPort -> {

src/main/java/com/faforever/client/mapstruct/IceServerMapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public Map<String, Object> map(CoturnServer coturnServer) {
1414
return Map.of(
1515
"urls", coturnServer.getUrls().stream().map(URI::toString).toList(),
1616
"credential", coturnServer.getCredential(),
17-
"credentialType", coturnServer.getCredentialType(),
1817
"username", coturnServer.getUsername()
1918
);
2019
}

src/test/java/com/faforever/client/fa/relay/ice/CoturnServiceTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.faforever.client.fa.relay.ice;
22

33
import com.faforever.client.api.FafApiAccessor;
4+
import com.faforever.client.api.IceSession;
45
import com.faforever.client.mapstruct.IceServerMapper;
56
import com.faforever.client.mapstruct.MapperSetup;
67
import com.faforever.client.preferences.ForgedAlliancePrefs;
@@ -14,11 +15,13 @@
1415
import org.mockito.Mock;
1516
import org.mockito.Spy;
1617
import reactor.core.publisher.Flux;
18+
import reactor.core.publisher.Mono;
1719

1820
import java.util.List;
1921

2022
import static org.junit.jupiter.api.Assertions.assertEquals;
2123
import static org.mockito.ArgumentMatchers.any;
24+
import static org.mockito.ArgumentMatchers.anyInt;
2225
import static org.mockito.ArgumentMatchers.argThat;
2326
import static org.mockito.Mockito.verify;
2427
import static org.mockito.Mockito.when;
@@ -53,26 +56,26 @@ public void TestGetSelectedCoturnsNoActiveSelected() {
5356

5457
CoturnServer otherServer = new CoturnServer();
5558
otherServer.setId("0");
56-
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer));
59+
when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer))));
5760

58-
List<CoturnServer> servers = instance.getSelectedCoturns().join();
61+
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();
5962

6063
assertEquals(1, servers.size());
6164
assertEquals("0", servers.get(0).getId());
62-
verify(fafApiAccessor).getMany(argThat(ElideMatchers.hasDtoClass(CoturnServer.class)));
65+
verify(fafApiAccessor).getIceSession(123);
6366
}
6467

6568
@Test
6669
public void testGetSelectedCoturnsNoneSelected() {
6770
CoturnServer otherServer = new CoturnServer();
6871
otherServer.setId("0");
69-
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer));
72+
when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer))));
7073

71-
List<CoturnServer> servers = instance.getSelectedCoturns().join();
74+
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();
7275

7376
assertEquals(1, servers.size());
7477
assertEquals("0", servers.get(0).getId());
75-
verify(fafApiAccessor).getMany(argThat(ElideMatchers.hasDtoClass(CoturnServer.class)));
78+
verify(fafApiAccessor).getIceSession(123);
7679
}
7780

7881
@Test
@@ -83,12 +86,12 @@ public void testGetSelectedCoturnsActiveSelected() {
8386
otherServer.setId("0");
8487
CoturnServer selectedServer = new CoturnServer();
8588
otherServer.setId("1");
86-
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer, selectedServer));
89+
when(fafApiAccessor.getIceSession(anyInt())).thenReturn(Mono.just(new IceSession("someSessionId", List.of(otherServer, selectedServer))));
8790

88-
List<CoturnServer> servers = instance.getSelectedCoturns().join();
91+
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();
8992

9093
assertEquals(1, servers.size());
9194
assertEquals("1", servers.get(0).getId());
92-
verify(fafApiAccessor).getMany(argThat(ElideMatchers.hasDtoClass(CoturnServer.class)));
95+
verify(fafApiAccessor).getIceSession(123);
9396
}
9497
}

src/test/java/com/faforever/client/game/GameServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void setUp() throws Exception {
186186

187187
when(fxApplicationThreadExecutor.asScheduler()).thenReturn(Schedulers.immediate());
188188
when(fafServerAccessor.getEvents(GameInfo.class)).thenReturn(testPublisher.flux());
189-
when(coturnService.getSelectedCoturns()).thenReturn(completedFuture(List.of()));
189+
when(coturnService.getSelectedCoturns(anyInt())).thenReturn(completedFuture(List.of()));
190190
when(preferencesService.isValidGamePath()).thenReturn(true);
191191
when(fafServerAccessor.connectionStateProperty()).thenReturn(new SimpleObjectProperty<>());
192192
when(replayServer.start(anyInt(), any())).thenReturn(completedFuture(LOCAL_REPLAY_PORT));

0 commit comments

Comments
 (0)