summaryrefslogtreecommitdiff
path: root/src/main/resources/static/app.js
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-18 01:22:47 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-18 01:22:47 +0100
commitdeff1187c52191f211cd66c917b1ee94c9499dfc (patch)
tree5670ad2d389c8d810f6f963aa099d36d0d846423 /src/main/resources/static/app.js
parentAdd proper logging and validation (diff)
downloadseven-wonders-deff1187c52191f211cd66c917b1ee94c9499dfc.tar.gz
seven-wonders-deff1187c52191f211cd66c917b1ee94c9499dfc.tar.bz2
seven-wonders-deff1187c52191f211cd66c917b1ee94c9499dfc.zip
Improve LobbyController errors and logs
Diffstat (limited to 'src/main/resources/static/app.js')
-rw-r--r--src/main/resources/static/app.js49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/main/resources/static/app.js b/src/main/resources/static/app.js
index dfdcf934..b1881357 100644
--- a/src/main/resources/static/app.js
+++ b/src/main/resources/static/app.js
@@ -18,14 +18,20 @@ function connect() {
setConnected(true);
console.log('Connected: ' + frame);
- stompClient.subscribe('/topic/games', function (gameId) {
- console.log("Received new game: " + gameId);
- addNewGame(gameId.body);
+ stompClient.subscribe('/user/queue/errors', function (msg) {
+ console.error(msg.body);
});
- stompClient.subscribe('/topic/players', function (player) {
- console.log("Received new player: " + player);
- addNewPlayer(JSON.parse(player.body));
+ stompClient.subscribe('/topic/games', function (msg) {
+ var game = JSON.parse(msg.body);
+ console.log("Received new game: " + game);
+ addNewGame(game);
+ });
+
+ stompClient.subscribe('/user/queue/join-game', function (msg) {
+ var game = JSON.parse(msg.body);
+ console.log("Joined game: " + game);
+ addNewPlayer(game);
});
});
}
@@ -38,20 +44,26 @@ function disconnect() {
console.log("Disconnected");
}
-function sendCreateGame() {
- stompClient.send("/app/lobby/create-game", {}, "");
+function sendCreateGame(gameName, playerName) {
+ stompClient.send("/app/lobby/create-game", {}, JSON.stringify({
+ 'gameName': gameName,
+ 'playerName': playerName
+ }));
}
-function sendJoinGame(gameId) {
- stompClient.send("/app/lobby/join-game", {},
- JSON.stringify({'gameId': gameId, 'playerName': $("#player-name-field").val()}));
+function sendJoinGame(gameName, playerName) {
+ stompClient.send("/app/lobby/join-game", {}, JSON.stringify({
+ 'gameName': gameName,
+ 'playerName': playerName
+ }));
}
-function addNewGame(gameId) {
- console.log(gameId);
- $("#game-list-content").append('<tr><td>' + gameId + '</td><td><button id="join-' + gameId + '" type="submit">Join</button></td></tr>');
- $("#join-" + gameId).click(function () {
- sendJoinGame(gameId);
+function addNewGame(game) {
+ console.log(game);
+ $("#game-list-content").append('<tr><td>' + game.name + '</td><td><button id="join-' + game.id +
+ '" type="submit">Join</button></td></tr>');
+ $("#join-" + game.id).click(function () {
+ sendJoinGame(game.name, $("#player-name-field").val());
});
}
@@ -70,9 +82,6 @@ $(function () {
disconnect();
});
$("#create-game").click(function () {
- sendCreateGame();
- });
- $("#join-game").click(function () {
- sendJoinGame();
+ sendCreateGame($("#game-name-field").val(), $("#player-name-field").val());
});
}); \ No newline at end of file
bgstack15