You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
28 lines
1.0 KiB
import json |
|
from update.views import cinema_update_status |
|
from channels.generic.websocket import WebsocketConsumer |
|
|
|
|
|
class UpdateConsumer(WebsocketConsumer): |
|
def connect(self): |
|
self.accept() |
|
self.send('你已经连接成功') |
|
|
|
def receive(self, text_data=None, bytes_data=None): |
|
if text_data is None: |
|
self.send('你发了啥') |
|
else: |
|
data = json.loads(text_data) |
|
if data.get('msg', False): |
|
if data['msg'] == 'ping': |
|
self.send(json.dumps({'msg': 'pong'})) |
|
if data.get('finish', False): |
|
ip = data['finish'] |
|
if cinema_update_status.get(ip): |
|
del cinema_update_status[ip] |
|
print(cinema_update_status.get(ip, None)) |
|
if data.get('ip', False): |
|
ip = data['ip'] |
|
self.send(json.dumps({'status': {'ip': ip, 'result': cinema_update_status.get(ip, None)}})) |
|
else: |
|
self.send(text_data)
|
|
|