Skip to content

Commit

Permalink
Merge pull request #226 from ShotaTanemura/fix/room-leave
Browse files Browse the repository at this point in the history
チャットルームを退出時にエラー
  • Loading branch information
libknt authored Oct 20, 2024
2 parents 7f55dc9 + 582f013 commit b247aa3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pong/chat/chat_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def send_initial_messages(self):
self.close()

def disconnect(self, close_code):
logger.info(f"Disconnecting from room: {self.room_name}")
async_to_sync(self.channel_layer.group_discard)(
self.room_group_name, self.channel_name
)
if hasattr(self, "room_group_name"):
async_to_sync(self.channel_layer.group_discard)(
self.room_group_name, self.channel_name
)

def receive(self, text_data):
text_data_json = json.loads(text_data)
Expand Down Expand Up @@ -240,6 +240,7 @@ def receive(self, text_data):
self.user, room, "退出しました。"
)
Rooms.objects.leave_room(self.user, room_id)

users = Rooms.objects.get_users_in_room(room_id)

users = [serialize_user(user) for user in users]
Expand Down
2 changes: 1 addition & 1 deletion pong/chat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_users_in_room(self, room_id):
)
return users
except self.model.DoesNotExist:
raise ValueError("指定された部屋が存在しません")
return []

def leave_room(self, user, room_uuid):
room = self.model.objects.get(uuid=room_uuid)
Expand Down
10 changes: 10 additions & 0 deletions pong/pong/static/pong/components/DirectoryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ export class DirectoryContainer extends Component {
modalRoomName.textContent = room.name;
modal.style.display = "block";

confirmJoinButton.removeEventListener(
"click",
this.eventListeners.confirmJoinButtonListener,
);
cancelJoinButton.removeEventListener(
"click",
this.eventListeners.cancelJoinButtonListener,
);
window.removeEventListener("click", this.eventListeners.modalClickListener);

this.eventListeners.confirmJoinButtonListener = () => {
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
const joinRequest = {
Expand Down
2 changes: 1 addition & 1 deletion pong/reaction_game/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf.urls.static import static
from .views import get_user_match_result

app_name = "realtime_pong_game"
app_name = "reaction_game"
urlpatterns = [
path(
"api/v1/match-result/<str:name>",
Expand Down

0 comments on commit b247aa3

Please sign in to comment.