diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index ee4f9e00..3d47071c 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index b8299840..5045caab 100644 Binary files a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/settings.py b/osinaweb/osinaweb/settings.py index a43e4b4b..259ccc44 100644 --- a/osinaweb/osinaweb/settings.py +++ b/osinaweb/osinaweb/settings.py @@ -92,10 +92,14 @@ TEMPLATES = [ ASGI_APPLICATION = 'osinaweb.asgi.application' + CHANNEL_LAYERS = { - 'default':{ - "BACKEND": "channels.layers.InMemoryChannelLayer", - } + "default": { + "BACKEND": "channels_redis.core.RedisChannelLayer", + "CONFIG": { + "hosts": [("localhost", 6379)], + }, + }, } diff --git a/osinaweb/static/js/tickets/tickets-room.js b/osinaweb/static/js/tickets/tickets-room.js index 8736bd93..0a794b5e 100644 --- a/osinaweb/static/js/tickets/tickets-room.js +++ b/osinaweb/static/js/tickets/tickets-room.js @@ -63,7 +63,7 @@ function app(socket) { function initializeWebSocket() { const ticketId = document.getElementById('ticketId').textContent.trim(); - const wsUrl = `wss://${window.location.host}/ws/ticketroom/${ticketId}/`; + const wsUrl = `ws://${window.location.host}/ws/ticketroom/${ticketId}/`; const socket = new WebSocket(wsUrl); socket.onopen = () => { diff --git a/osinaweb/support/__pycache__/consumers.cpython-310.pyc b/osinaweb/support/__pycache__/consumers.cpython-310.pyc index 662c87d7..244f82f0 100644 Binary files a/osinaweb/support/__pycache__/consumers.cpython-310.pyc and b/osinaweb/support/__pycache__/consumers.cpython-310.pyc differ diff --git a/osinaweb/support/consumers.py b/osinaweb/support/consumers.py index 9c50761e..702c3af0 100644 --- a/osinaweb/support/consumers.py +++ b/osinaweb/support/consumers.py @@ -11,6 +11,7 @@ import json from django.template.loader import render_to_string from asgiref.sync import async_to_sync + class TicketRoomConsumer(WebsocketConsumer): def connect(self): self.user = self.scope['user'] @@ -172,8 +173,20 @@ class TicketRoomConsumer(WebsocketConsumer): connections = TicketConnection.objects.filter(ticket=self.ticket, terminated_at__isnull=True) event = { 'type': 'user_connection_handler', - 'user': self.user, - 'connections': connections, + 'user': { + 'id': self.user.id, + 'username': self.user.username, + 'first_name': self.user.first_name, + 'last_name': self.user.last_name, + }, + 'connections': [ + { + 'first_name': conn.user.first_name, + 'last_name': conn.user.last_name, + 'image': conn.user.staffprofile.image.url if hasattr(conn.user, 'staffprofile') and conn.user.staffprofile.image else None, + 'date': conn.date.isoformat() if conn.date else None, + } for conn in connections + ] } async_to_sync(self.channel_layer.group_send)( self.ticket_number, event @@ -185,7 +198,10 @@ class TicketRoomConsumer(WebsocketConsumer): 'user': event['user'] } html = render_to_string("details_templates/partials/ticket-online-users.html", context=context) - print('hi') + self.send(text_data=json.dumps({ + 'event_type': 'user_status', + 'html': html + })) diff --git a/osinaweb/support/templates/details_templates/partials/ticket-online-users.html b/osinaweb/support/templates/details_templates/partials/ticket-online-users.html index 0d8b28fc..2c3cfe3b 100644 --- a/osinaweb/support/templates/details_templates/partials/ticket-online-users.html +++ b/osinaweb/support/templates/details_templates/partials/ticket-online-users.html @@ -1,11 +1,11 @@ {% load static %} {% for connection in connections %}