mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
26 lines
854 B
Python
26 lines
854 B
Python
import json
|
|
|
|
import tornado.websocket
|
|
from app.classes.shared.console import console
|
|
from app.classes.web.websocket_helper import websocket_helper
|
|
|
|
|
|
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|
|
|
def open(self):
|
|
websocket_helper.addClient(self)
|
|
console.debug('Opened WebSocket connection')
|
|
websocket_helper.broadcast('notification', 'New client connected')
|
|
|
|
def on_message(self, rawMessage):
|
|
|
|
console.debug('Got message from WebSocket connection {}'.format(rawMessage))
|
|
message = json.loads(rawMessage)
|
|
console.debug('Event Type: {}, Data: {}'.format(message['event'], message['data']))
|
|
|
|
def on_close(self):
|
|
websocket_helper.removeClient(self)
|
|
console.debug('Closed WebSocket connection')
|
|
websocket_helper.broadcast('notification', 'Client disconnected')
|
|
|