Skip to content

Commit

Permalink
Merge branch 'feature/message-websockets' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisoSouza committed Nov 27, 2024
2 parents 9d639f5 + 241d6a0 commit be18482
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nexus/projects/websockets/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ def connect(self):
def receive(self, text_data=None, bytes_data=None):
text_data_json = json.loads(text_data)
message = text_data_json["message"]
message_type = text_data_json["type"]

async_to_sync(self.channel_layer.group_send)(
self.room_group_name,
{
"type": "chat_message",
"message": message
"message": message,
"message_type": message_type,
}
)

def chat_message(self, event):
mtype = {"ping": "pong"}
message = event["message"]
message_type = event["message_type"]

self.send(text_data=json.dumps(
{"type": "ws", "message": message}
{"type": mtype.get(message_type, message_type), "message": message}
))

0 comments on commit be18482

Please sign in to comment.