Skip to content

Commit

Permalink
Load the ICE servers from the new faf-icebreaker API
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Oct 28, 2023
1 parent 3cea443 commit 4001a49
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/faforever/client/api/FafApiAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public Mono<MeResult> getMe() {
.doOnNext(object -> log.trace("Retrieved {} from /me with type MeResult", object));
}

public Mono<IceSession> getIceSession(int gameId) {
return retrieveMonoWithErrorHandling(IceSession.class, apiWebClient.get().uri("/ice/session/game/" + gameId))
.doOnNext(object -> log.trace("Retrieved {} from /ice/session/game/{} with type MeResult", object, gameId));
}

public Mono<Void> uploadFile(String endpoint, Path file, ByteCountListener listener,
java.util.Map<String, java.util.Map<String, ?>> params) {
MultiValueMap<String, Object> multipartContent = createFileMultipart(file, listener);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/faforever/client/api/IceSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.faforever.client.api;

import com.faforever.commons.api.dto.CoturnServer;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.jetbrains.annotations.NotNull;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
public record IceSession(@NotNull String id, @NotNull List<CoturnServer> servers) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faforever.client.fa.relay.ice;

import com.faforever.client.api.FafApiAccessor;
import com.faforever.client.api.IceSession;
import com.faforever.client.mapstruct.IceServerMapper;
import com.faforever.client.preferences.ForgedAlliancePrefs;
import com.faforever.commons.api.dto.CoturnServer;
Expand Down Expand Up @@ -31,9 +32,9 @@ public CompletableFuture<List<CoturnServer>> getActiveCoturns() {
.toFuture();
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/faforever/client/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ private CompletableFuture<Void> startGame(GameParameters gameParameters) {
localReplayPort = port;
return iceAdapter.start(gameParameters.getUid());
})
.thenCompose(adapterPort -> coturnService.getSelectedCoturns()
.thenCompose(adapterPort -> coturnService.getSelectedCoturns(uid)
.thenAccept(iceAdapter::setIceServers)
.thenApply(aVoid -> adapterPort))
.thenApply(adapterPort -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public Map<String, Object> map(CoturnServer coturnServer) {
return Map.of(
"urls", coturnServer.getUrls().stream().map(URI::toString).toList(),
"credential", coturnServer.getCredential(),
"credentialType", coturnServer.getCredentialType(),
"username", coturnServer.getUsername()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TestGetSelectedCoturnsNoActiveSelected() {
otherServer.setId("0");
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer));

List<CoturnServer> servers = instance.getSelectedCoturns().join();
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();

assertEquals(1, servers.size());
assertEquals("0", servers.get(0).getId());
Expand All @@ -68,7 +68,7 @@ public void testGetSelectedCoturnsNoneSelected() {
otherServer.setId("0");
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer));

List<CoturnServer> servers = instance.getSelectedCoturns().join();
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();

assertEquals(1, servers.size());
assertEquals("0", servers.get(0).getId());
Expand All @@ -85,7 +85,7 @@ public void testGetSelectedCoturnsActiveSelected() {
otherServer.setId("1");
when(fafApiAccessor.getMany(any())).thenReturn(Flux.just(otherServer, selectedServer));

List<CoturnServer> servers = instance.getSelectedCoturns().join();
List<CoturnServer> servers = instance.getSelectedCoturns(123).join();

assertEquals(1, servers.size());
assertEquals("1", servers.get(0).getId());
Expand Down

0 comments on commit 4001a49

Please sign in to comment.