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' |
||||
|
|
||||
|
#response = requests.get(url_dados) |
||||
|
#print(response) |
||||
|
|
||||
def receive(self, text_data): |
await self.send_json({ |
||||
print('receive message') |
'message': 'teste' |
||||
text_data_json = json.loads(text_data) |
}) |
||||
message = text_data_json['message'] |
|
||||
|
|
||||
self.send(text_data=json.dumps({ |
async def send(self, event): |
||||
'message': message |
print('Entrou') |
||||
})) |
|
||||
|
|
||||
async def send_message (self, event): |
|
||||
new_data = event['text'] |
|
||||
print(new_data) |
|
||||
await self.send(json.dumps(new_data)) |
|
Loading…
Reference in new issue