Skip to content

Commit

Permalink
Merge branch 'feature/websockets' into feature/scene-triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdgeisler committed Nov 24, 2022
2 parents 68e0fcf + 055189d commit e60b7d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.function.Consumer;

@Component
public class ClientApi extends AbstractClientApi {
Expand Down Expand Up @@ -88,7 +89,7 @@ public Mono<Map> dump() {
.bodyToMono(Map.class);
}

public void websocket() {
public void websocket(final Consumer<String> consumer) {
final String token;
final String authorizationHeader;
final HttpClient httpClient;
Expand All @@ -103,10 +104,10 @@ public void websocket() {
.headers(headers -> headers.add(HttpHeaders.AUTHORIZATION, authorizationHeader))
.keepAlive(true);
client = new ReactorNettyWebSocketClient(httpClient);
client.execute(URI.create(String.format("https://%s:%d/v1/", hostname, port)), session ->
client.execute(URI.create(String.format("https://%s:%d/v1/", this.hostname, this.port)), session ->
session.receive()
.map(WebSocketMessage::getPayloadAsText)
.doOnNext(message -> log.debug("Received websocket message: {}", message))
.doOnNext(consumer)
.repeat()
.then()
).block();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import reactor.core.publisher.Flux;

/**
* Lists all known devices
* Opens a websocket
*/
@SpringBootApplication
@ComponentScan(basePackageClasses = {DirigeraApi.class})
Expand All @@ -25,7 +24,7 @@ public CommandLineRunner run(final DirigeraApi api, final ClientApi capi) {
return (String... args) -> {
api.pairIfRequired().block(); // pair gateway if required

capi.websocket();
capi.websocket(message -> log.debug("Received websocket message: {}", message));
};
}

Expand Down

0 comments on commit e60b7d0

Please sign in to comment.