diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-12 23:45:57 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-12 23:46:30 +0100 |
commit | 89b89e93f3b60c0edca63e648d8e8a37c968de3a (patch) | |
tree | 4fe8236f0a718920d3487b71cc33f9c49eb50ed5 /src/main | |
parent | Lobby vs Game separation (diff) | |
download | seven-wonders-89b89e93f3b60c0edca63e648d8e8a37c968de3a.tar.gz seven-wonders-89b89e93f3b60c0edca63e648d8e8a37c968de3a.tar.bz2 seven-wonders-89b89e93f3b60c0edca63e648d8e8a37c968de3a.zip |
Update frontend POC with new lobby system
Diffstat (limited to 'src/main')
4 files changed, 11 insertions, 10 deletions
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 { diff --git a/src/main/resources/static/app.js b/src/main/resources/static/app.js index 5a3bc38e..dfdcf934 100644 --- a/src/main/resources/static/app.js +++ b/src/main/resources/static/app.js @@ -18,12 +18,12 @@ function connect() { setConnected(true); console.log('Connected: ' + frame); - stompClient.subscribe('/broadcast/games', function (gameId) { + stompClient.subscribe('/topic/games', function (gameId) { console.log("Received new game: " + gameId); addNewGame(gameId.body); }); - stompClient.subscribe('/broadcast/players', function (player) { + stompClient.subscribe('/topic/players', function (player) { console.log("Received new player: " + player); addNewPlayer(JSON.parse(player.body)); }); |