From 397344ee4509c626dc70b4afc9fde0e2bc864dbe Mon Sep 17 00:00:00 2001 From: starnakin Date: Sat, 23 Dec 2023 18:47:16 +0100 Subject: [PATCH] matchmaking: add: clear message if normal closure --- frontend/static/js/api/matchmaking.js | 2 +- frontend/static/js/views/MatchMakingView.js | 4 +++- matchmaking/consumers.py | 2 +- transcendence/abstract/AbstractRoom.py | 4 ++-- transcendence/abstract/AbstractRoomMember.py | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/static/js/api/matchmaking.js b/frontend/static/js/api/matchmaking.js index e33ecf9..9649236 100644 --- a/frontend/static/js/api/matchmaking.js +++ b/frontend/static/js/api/matchmaking.js @@ -39,7 +39,7 @@ class MatchMaking onclose(event) { this.stop(); - this.disconnect_func() + this.disconnect_func(event); } async stop() diff --git a/frontend/static/js/views/MatchMakingView.js b/frontend/static/js/views/MatchMakingView.js index bc47559..eb084d3 100644 --- a/frontend/static/js/views/MatchMakingView.js +++ b/frontend/static/js/views/MatchMakingView.js @@ -25,8 +25,10 @@ export default class extends AbstractAuthentifiedView { } } - ondisconnect() + ondisconnect(event) { + if (event.code === 1000) + clear("innerText", ["detail"]) document.getElementById("button").value = "Find a game" } diff --git a/matchmaking/consumers.py b/matchmaking/consumers.py index 2087c54..819ca40 100644 --- a/matchmaking/consumers.py +++ b/matchmaking/consumers.py @@ -38,4 +38,4 @@ class MatchMaking(WebsocketConsumer): waiting_room: WaitingRoom = normal.get(self.mode) waiter: Waiter = waiting_room.get_member_by_socket(self) if (waiter is not None): - waiting_room.remove(waiter) \ No newline at end of file + waiting_room.remove(waiter, 1016) \ No newline at end of file diff --git a/transcendence/abstract/AbstractRoom.py b/transcendence/abstract/AbstractRoom.py index d2c6502..09b202b 100644 --- a/transcendence/abstract/AbstractRoom.py +++ b/transcendence/abstract/AbstractRoom.py @@ -35,9 +35,9 @@ class AbstractRoom: self._member_list.append(waiter) member.accept() - def remove(self, member: AbstractRoomMember): + def remove(self, member: AbstractRoomMember, code: int = 1000): self._member_list.remove(member) - member.disconnect() + member.disconnect(code) def empty(self): for _ in self._member_list: diff --git a/transcendence/abstract/AbstractRoomMember.py b/transcendence/abstract/AbstractRoomMember.py index 1e0b506..0a89b98 100644 --- a/transcendence/abstract/AbstractRoomMember.py +++ b/transcendence/abstract/AbstractRoomMember.py @@ -16,5 +16,5 @@ class AbstractRoomMember: def accept(self): self.socket.accept() - def disconnect(self): - self.socket.disconnect(200) \ No newline at end of file + def disconnect(self, code: int = 1000): + self.socket.disconnect(code) \ No newline at end of file