haikal/api/consumers.py
2025-06-22 13:25:54 +03:00

36 lines
1.1 KiB
Python

# from channels.generic.websocket import AsyncWebsocketConsumer
# from api.services import get_car_data
# import json
#
#
# class VINScanConsumer(AsyncWebsocketConsumer):
# def __init__(self, *args, **kwargs):
# super().__init__(args, kwargs)
# self.group_name = None
#
# async def connect(self):
# self.group_name = 'vin_scan_group'
# 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, **kwargs):
# data = json.loads(text_data)
# vin = data['vin']
# get_car_data(vin)
# # Process the VIN as needed, e.g., save to the database
#
# # Send data back to the WebSocket
# await self.send(text_data=json.dumps({
# 'message': 'VIN received',
# 'vin': vin
# }))