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 |
|||
from channels.generic.websocket import WebsocketConsumer |
|||
import requests |
|||
from channels.generic.websocket import AsyncJsonWebsocketConsumer |
|||
|
|||
|
|||
class PainelConsumer(WebsocketConsumer): |
|||
def connect(self): |
|||
self.channel_layer.group_add('message', self.channel_name) |
|||
self.accept() |
|||
self.send('Teste') |
|||
|
|||
class PainelConsumer(AsyncJsonWebsocketConsumer): |
|||
async def connect (self): |
|||
await self.accept() |
|||
|
|||
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): |
|||
print('receive message') |
|||
text_data_json = json.loads(text_data) |
|||
message = text_data_json['message'] |
|||
#response = requests.get(url_dados) |
|||
#print(response) |
|||
|
|||
self.send(text_data=json.dumps({ |
|||
'message': message |
|||
})) |
|||
await self.send_json({ |
|||
'message': 'teste' |
|||
}) |
|||
|
|||
async def send_message (self, event): |
|||
new_data = event['text'] |
|||
print(new_data) |
|||
await self.send(json.dumps(new_data)) |
|||
async def send(self, event): |
|||
print('Entrou') |
|||
|
Loading…
Reference in new issue