I wish to limit the number of users in a room to 2 because I am making a socket game were two palyers can play a tic-tack-toe or a connect-4 game so I a trying to find some way of limiting only 2 players in one room.
Down below is my comsumers.py
from channels.generic.websocket import WebsocketConsumer
from asgiref.sync import async_to_sync
import json
class GameRoom(WebsocketConsumer):
def connect(self):
self.room_name = self.scope['url_route']['kwargs']['room_code']
self.room_group_name = 'room_%s' % self.room_name
print(self.room_group_name)
async_to_sync(self.channel_layer.group_add)(
self.room_group_name,
self.channel_name
)
self.accept()
I have removed some of the less necessary methods from this question