diff --git a/frontend/static/js/views/MatchMakingView.js b/frontend/static/js/views/MatchMakingView.js index d9f4fb5..bc47559 100644 --- a/frontend/static/js/views/MatchMakingView.js +++ b/frontend/static/js/views/MatchMakingView.js @@ -19,7 +19,7 @@ export default class extends AbstractAuthentifiedView { { let nb_players = document.getElementById("nb_players-input").value - await client.matchmaking.start(this.display_data, this.ondisconnect, nb_players); + await client.matchmaking.start(this.onreceive.bind(this), this.ondisconnect.bind(this), nb_players); document.getElementById("button").value = "Stop matchmaking" } @@ -30,6 +30,16 @@ export default class extends AbstractAuthentifiedView { document.getElementById("button").value = "Find a game" } + onreceive(data) + { + if (data.detail === "game_found") + { + navigateTo(`/games/${data.game_id}`); + return; + } + this.display_data(data) + } + display_data(data) { clear("innerText", ["detail"]); diff --git a/matchmaking/consumers.py b/matchmaking/consumers.py index 1b6fbbf..f47d73d 100644 --- a/matchmaking/consumers.py +++ b/matchmaking/consumers.py @@ -32,7 +32,7 @@ class MatchMaking(WebsocketConsumer): print(len(waiting_room), "/", self.mode, [len(waiting_room),self.mode]) if (len(waiting_room) == self.mode): game_id: int = GameModel().create(waiting_room.get_users_id()) - waiting_room.broadcast({"detail": "Game found !", "game_id": game_id}) + waiting_room.broadcast("game_found", {"game_id": game_id}) waiting_room.clear() def disconnect(self, close_code):