Slide 26
Slide 26 text
CONSUMERS
CONSUMERS
COUNTING USERS
COUNTING USERS
class UserCounterConsumer(JsonWebsocketConsumer):
def connection_groups(self, **kwargs):
return 'users',
def connect(self, message, **kwargs):
""" Increment users on connect and notify users """
super().connect(message, **kwargs)
if message.user.is_authenticated:
increment_users(message.user)
msg = {'users': count_users(),}
self.group_send(self.users_group, msg)
def disconnect(self, message, **kwargs):
""" Decrement users on disconnect and notify users """
...