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?
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 theroomanother 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 thews_connect()function, but instead we are using thechannels_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?
Wow, from the creator himself! Thank you.Just so we're clear, message.channel_session['key'] is the same as request.session['key'], did I get you correctly?
And there's just this another confusion, why can't we us "text": message.content['text'], but instead its "text": message['text']?