emile 10 months ago
parent ec96530ee9
commit 38d673b89b

Binary file not shown.

@ -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)],
},
},
}

@ -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 = () => {

@ -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
}))

@ -1,11 +1,11 @@
{% load static %}
{% for connection in connections %}
<div class="w-[35px] h-[35px] rounded-full {% if not forloop.first %} -ml-5 {% endif %} ">
{% if connection.user.staffprofile.image %}
<img src="{{ connection.user.staffprofile.image.url }}" class="w-full h-full rounded-full object-cover">
{% if connection.image %}
<img src="{{ connection.image}}" class="w-full h-full rounded-full object-cover">
{% else %}
<div class="w-full h-full border border-osiblue bg-osiblue text-white uppercase rounded-full flex justify-center items-center p-1 shadow-md">
{{ connection.user.first_name.0 }}{{ connection.user.last_name.0 }}
{{ connection.first_name.0 }}{{ connection.last_name.0 }}
</div>
{% endif %}
</div>

Loading…
Cancel
Save