Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from channels.generic.websockets import JsonWebsocketConsumer
- class MyConsumer(JsonWebsocketConsumer):
- # Set to True if you want it, else leave it out
- strict_ordering = True
- def connection_groups(self, **kwargs):
- """
- Called to return the list of groups to automatically add/remove
- this connection to/from.
- """
- person_name = self.message.channel_session['username']
- player = Player.objects.get(user__username=person_name)
- game_name = player.game.name
- return [game_name]
- @channel_token_auth
- def connect(self, message, **kwargs):
- """
- Perform things on connection start
- """
- message.reply_channel.send({"accept": True})
- @channel_session
- def receive(self, content, **kwargs):
- """
- Called when a message is received with decoded JSON content
- """
- # Simple echo
- self.send({'text': 'You can not send messages'})
- def disconnect(self, message, **kwargs):
- """
- Perform things on connection close
- """
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement