mirror of
https://github.com/django/daphne.git
synced 2025-08-04 10:30:08 +03:00
Fixed #694: Invalid code example in getting-started
This commit is contained in:
parent
300999770f
commit
8cc2842492
|
@ -396,9 +396,9 @@ name in the path of your WebSocket request and a query string with your username
|
||||||
message.reply_channel.send({"accept": True})
|
message.reply_channel.send({"accept": True})
|
||||||
# Parse the query string
|
# Parse the query string
|
||||||
params = parse_qs(message.content["query_string"])
|
params = parse_qs(message.content["query_string"])
|
||||||
if "username" in params:
|
if b"username" in params:
|
||||||
# Set the username in the session
|
# Set the username in the session
|
||||||
message.channel_session["username"] = params["username"]
|
message.channel_session["username"] = params[b"username"][0].decode("utf8")
|
||||||
# Add the user to the room_name group
|
# Add the user to the room_name group
|
||||||
Group("chat-%s" % room_name).add(message.reply_channel)
|
Group("chat-%s" % room_name).add(message.reply_channel)
|
||||||
else:
|
else:
|
||||||
|
@ -408,10 +408,12 @@ name in the path of your WebSocket request and a query string with your username
|
||||||
# Connected to websocket.receive
|
# Connected to websocket.receive
|
||||||
@channel_session
|
@channel_session
|
||||||
def ws_message(message, room_name):
|
def ws_message(message, room_name):
|
||||||
Group("chat-%s" % room_name).send({
|
Group("chat-%s" % room_name).send(
|
||||||
"text": message["text"],
|
"text": json.dumps({
|
||||||
"username": message.channel_session["username"]
|
"text": message["text"],
|
||||||
})
|
"username": message.channel_session["username"],
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
# Connected to websocket.disconnect
|
# Connected to websocket.disconnect
|
||||||
@channel_session
|
@channel_session
|
||||||
|
|
Loading…
Reference in New Issue
Block a user