mirror of https://github.com/interlegis/sapl.git
AlGouvea
3 years ago
3 changed files with 32 additions and 24 deletions
@ -1,26 +1,29 @@ |
|||||
import json |
import json |
||||
from channels.generic.websocket import WebsocketConsumer |
import requests |
||||
|
from channels.generic.websocket import AsyncJsonWebsocketConsumer |
||||
|
|
||||
|
|
||||
class PainelConsumer(WebsocketConsumer): |
|
||||
def connect(self): |
class PainelConsumer(AsyncJsonWebsocketConsumer): |
||||
self.channel_layer.group_add('message', self.channel_name) |
async def connect (self): |
||||
self.accept() |
await self.accept() |
||||
self.send('Teste') |
|
||||
|
|
||||
async def disconnect(self, close_code): |
async def disconnect(self, close_code): |
||||
await self.channel_layer.group_discard('message', self.channel_name) |
pass |
||||
|
|
||||
|
async def receive(self, text_data): |
||||
|
print('Received Message') |
||||
|
|
||||
|
print('Enviando...') |
||||
|
url_dados = 'http://localhost:8000/painel/786/dados' |
||||
|
|
||||
def receive(self, text_data): |
#response = requests.get(url_dados) |
||||
print('receive message') |
#print(response) |
||||
text_data_json = json.loads(text_data) |
|
||||
message = text_data_json['message'] |
|
||||
|
|
||||
self.send(text_data=json.dumps({ |
await self.send_json({ |
||||
'message': message |
'message': 'teste' |
||||
})) |
}) |
||||
|
|
||||
async def send_message (self, event): |
async def send(self, event): |
||||
new_data = event['text'] |
print('Entrou') |
||||
print(new_data) |
|
||||
await self.send(json.dumps(new_data)) |
|
Loading…
Reference in new issue