diff --git a/frontend/src/__apps/painel/main.js b/frontend/src/__apps/painel/main.js index 15f421e40..af36705c2 100644 --- a/frontend/src/__apps/painel/main.js +++ b/frontend/src/__apps/painel/main.js @@ -266,18 +266,14 @@ const v = new Vue({ // eslint-disable-line socket.onopen = function (e) { console.log('Connection established') + console.log(e) + socket.send('teste') } socket.onclose = function (e) { console.error('Ws fechou!') } - socket.onmessage = function (e) { - console.log('got to onmessage') - // this.teste = JSON.parse(e.data) - // console.log(this.teste) - } - console.info('Start polling data...') this.pollData() } diff --git a/sapl/painel/consumers.py b/sapl/painel/consumers.py index 19de438e4..190bd358d 100644 --- a/sapl/painel/consumers.py +++ b/sapl/painel/consumers.py @@ -6,6 +6,7 @@ class PainelConsumer(WebsocketConsumer): def connect(self): self.channel_layer.group_add('message', self.channel_name) self.accept() + self.send('Teste') async def disconnect(self, close_code): await self.channel_layer.group_discard('message', self.channel_name) @@ -18,8 +19,8 @@ class PainelConsumer(WebsocketConsumer): self.send(text_data=json.dumps({ 'message': message })) - - async def send(self, event): + + async def send_message (self, event): new_data = event['text'] print(new_data) await self.send(json.dumps(new_data)) \ No newline at end of file diff --git a/sapl/painel/tasks.py b/sapl/painel/tasks.py index 8e3e86fef..3b1dcd212 100644 --- a/sapl/painel/tasks.py +++ b/sapl/painel/tasks.py @@ -25,4 +25,4 @@ def get_cronometro(): json_data = r.json() print(json_data) - async_to_sync(channel_layer.group_send)('message', {'type':'send', 'text': json_data}) + async_to_sync(channel_layer.group_send)('message', {'type':'send_message', 'text': json_data})