async def create_trip(self, event): trip = await self._create_trip(event.get('data')) trip_id = f'{trip.id}' trip_data = ReadOnlyTripSerializer(trip).data # Send rider requests to all drivers. await self.channel_layer.group_send(group='drivers', message={ 'type': 'echo.message', 'data': trip_data }) if trip_id not in self.trips: self.trips.add(trip_id) await self.channel_layer.group_add(group=trip_id, channel=self.channel_name) await self.send_json({'type': 'create.trip', 'data': trip_data})
async def update_trip(self, event): trip = await self._update_trip(event.get('data')) trip_id = f'{trip.id}' trip_data = ReadOnlyTripSerializer(trip).data # Send updates to riders that subscribe to this trip. await self.channel_layer.group_send(group=trip_id, message={ 'type': 'echo.message', 'data': trip_data }) if trip_id not in self.trips: self.trips.add(trip_id) await self.channel_layer.group_add(group=trip_id, channel=self.channel_name) await self.send_json({'type': 'update.trip', 'data': trip_data})
async def update_trip(self, event): trip = await self._update_trip(event.get('data')) trip_id = f'{trip.id}' trip_data = ReadOnlyTripSerializer(trip).data # Send updates to riders that subscribe to this trip. await self.channel_layer.group_send(group=trip_id, message={ 'type': 'echo.message', 'data': trip_data }) # Handle add only if trip is not being tracked. # This happens when a driver accepts a request. if trip_id not in self.trips: self.trips.add(trip_id) await self.channel_layer.group_add(group=trip_id, channel=self.channel_name) await self.send_json({'type': 'MESSAGE', 'data': trip_data})