Browse Source

Alterações

Websocket_painel
AlGouvea 3 years ago
parent
commit
81bafe7e87
  1. 8
      frontend/src/__apps/painel/main.js
  2. 3
      sapl/painel/consumers.py
  3. 2
      sapl/painel/tasks.py

8
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()
}

3
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)
@ -19,7 +20,7 @@ class PainelConsumer(WebsocketConsumer):
'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))

2
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})

Loading…
Cancel
Save