From 89b89e93f3b60c0edca63e648d8e8a37c968de3a Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 12 Dec 2016 23:45:57 +0100 Subject: Update frontend POC with new lobby system --- src/main/java/org/luxons/sevenwonders/WebSocketConfig.java | 2 +- .../org/luxons/sevenwonders/controllers/LobbyController.java | 11 ++++++----- .../org/luxons/sevenwonders/controllers/TestController.java | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/luxons/sevenwonders/WebSocketConfig.java b/src/main/java/org/luxons/sevenwonders/WebSocketConfig.java index bbe91c16..b0613e79 100644 --- a/src/main/java/org/luxons/sevenwonders/WebSocketConfig.java +++ b/src/main/java/org/luxons/sevenwonders/WebSocketConfig.java @@ -13,7 +13,7 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry config) { // prefixes for all subscriptions - config.enableSimpleBroker("/broadcast", "/queue", "/topic"); + config.enableSimpleBroker("/queue", "/topic"); config.setUserDestinationPrefix("/user"); // prefix for all calls from clients diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java index 8e4f93c1..705e6ef2 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java @@ -15,7 +15,7 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.stereotype.Controller; @Controller -//@MessageMapping("/lobby") +@MessageMapping("/lobby") public class LobbyController { private final GameDefinitionLoader gameDefinitionLoader; @@ -32,21 +32,22 @@ public class LobbyController { } @MessageMapping("/create-game") - @SendTo("/broadcast/games") + @SendTo("/topic/games") public String createGame(SimpMessageHeaderAccessor headerAccessor) throws Exception { System.out.println("Received message: " + headerAccessor.getSessionId()); Thread.sleep(1000); // simulated delay - String id = String.valueOf(lastGameId++); + long newId = lastGameId++; + String id = String.valueOf(newId); System.out.println("Creating game " + id); - Lobby lobby = new Lobby(lastGameId, gameDefinitionLoader.getGameDefinition()); + Lobby lobby = new Lobby(newId, gameDefinitionLoader.getGameDefinition()); lobbies.put(id, lobby); return id; } @MessageMapping("/join-game") - @SendTo("/broadcast/players") + @SendTo("/topic/players") public Player joinGame(SimpMessageHeaderAccessor headerAccessor, JoinGameAction joinAction) throws Exception { Thread.sleep(1000); // simulated delay diff --git a/src/main/java/org/luxons/sevenwonders/controllers/TestController.java b/src/main/java/org/luxons/sevenwonders/controllers/TestController.java index 06ebbdf3..0fd9e0c1 100644 --- a/src/main/java/org/luxons/sevenwonders/controllers/TestController.java +++ b/src/main/java/org/luxons/sevenwonders/controllers/TestController.java @@ -52,8 +52,8 @@ public class TestController { return "success test5"; } - // sent to the caller user if he subscribed to /user/queue/test5 - // other subscribers of /user/queue/test5 are NOT notified + // sent to the caller user if he subscribed to /user/queue/test6 + // other subscribers of /user/queue/test6 are NOT notified @MessageMapping("/test6") // TODO public String test6(SimpMessageHeaderAccessor headerAccessor) throws Exception { -- cgit