import json from channels.generic.websocket import AsyncWebsocketConsumer class ArriveeConsumer(AsyncWebsocketConsumer): async def connect(self): self.course_id = self.scope['url_route']['kwargs']['course_id'] self.group_name = f'course_{self.course_id}' await self.channel_layer.group_add( self.group_name, self.channel_name ) await self.accept() async def disconnect(self, close_code): await self.channel_layer.group_discard( self.group_name, self.channel_name ) async def receive(self, text_data): # Optionnel : traiter les messages entrants pass async def send_arrivee(self, event): await self.send(text_data=json.dumps(event['data']))