Skip to content

Instantly share code, notes, and snippets.

@johngrantuk
Created March 29, 2016 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngrantuk/63e43eb5ac92f88cc9c4 to your computer and use it in GitHub Desktop.
Save johngrantuk/63e43eb5ac92f88cc9c4 to your computer and use it in GitHub Desktop.
Django Channel ws_connect consumer
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