Fixed #694: Invalid code example in getting-started

This commit is contained in:
Andrew Godwin 2017-07-02 10:18:28 -07:00
parent 300999770f
commit 8cc2842492

View File

@ -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": json.dumps({
"text": message["text"], "text": message["text"],
"username": message.channel_session["username"] "username": message.channel_session["username"],
}) }),
)
# Connected to websocket.disconnect # Connected to websocket.disconnect
@channel_session @channel_session