Created
March 29, 2016 15:10
-
-
Save johngrantuk/63e43eb5ac92f88cc9c4 to your computer and use it in GitHub Desktop.
Django Channel ws_connect consumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from channels import Group | |
def ws_connect(message): | |
print("Someone connected.") | |
path = message['path'] # i.e. /sensor/ | |
if path == b’/sensor/': | |
print("Adding new user to sensor group") | |
Group(“sensor").add(message.reply_channel) # Adds user to group for broadcast | |
message.reply_channel.send({ # Reply to individual directly | |
"text": "You're connected to sensor group :) ", | |
}) | |
else: | |
print("Strange connector!!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment