I am trying to grasp the concept of persistant data in django channels. I have searched the reference and other parts but didn't clear my confusion. I would really appreciate if you help me understand better.
consumers.py:
@channel_session def ws_connect(message): # Work out room name from path (ignore slashes) room = message.content['path'].strip("/") # Save room in session and add us to the group message.channel_session['room'] = room Group("chat-%s" % room).add(message.reply_channel)Q.1 In the above line message.channel_session['room'], is the room another property of the message? Like it tells which session the message belongs to?
@channel_session def ws_message(message): Group("chat-%s" % message.channel_session['room']).send({ "text": message['text'], })Q2. In the line Group("chat-%s" % message.channel_session['room']).send({, why are we not using the room variable like in the ws_connect() function, but instead we are using the channels_session?
@channel_session def ws_disconnect(message): Group("chat-%s" % message.channel_session['room']).discard(message.reply_channel)Q3. Same like above, why are we not using the room variable to discard from the group? Also is it not neccesary to remove the room from the session?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B8okoJ70Nba%3Dfw9k-10C3UASXMwFkayR7ApdjTEVg1s23bT-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment