working websocket communication for recorder states
This commit is contained in:
@@ -4,6 +4,7 @@ import threading
|
||||
from flask_jwt_extended import verify_jwt_in_request, get_current_user, jwt_required, get_jwt_claims, get_jwt_identity
|
||||
from flask_login import current_user
|
||||
from flask_socketio import SocketIO, emit
|
||||
from jwt import ExpiredSignatureError
|
||||
|
||||
from backend import app
|
||||
|
||||
@@ -32,6 +33,9 @@ class WebSocketBase:
|
||||
debug = self.flask_app_context.debug
|
||||
socketio.run(self.flask_app_context, host=host, port=port, debug=debug)
|
||||
|
||||
def send_test_msg(self):
|
||||
socketio.emit('test', "tolle nachricht")
|
||||
|
||||
@staticmethod
|
||||
@socketio.on('connect')
|
||||
def connect_handler():
|
||||
@@ -39,16 +43,45 @@ class WebSocketBase:
|
||||
try:
|
||||
print(verify_jwt_in_request())
|
||||
print(get_jwt_identity())
|
||||
except:
|
||||
except ExpiredSignatureError:
|
||||
logger.info("user is not authenticated! Signature expired.")
|
||||
except Exception as e:
|
||||
logger.info("user is not authenticated!")
|
||||
print(str(e))
|
||||
print(type(e))
|
||||
print("not allowed!!")
|
||||
return False # not allowed here
|
||||
logger.debug("user is authenticated")
|
||||
print("allowed!")
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
@socketio.on('message')
|
||||
def handle_message(message):
|
||||
print('received message: ' + message)
|
||||
|
||||
@staticmethod
|
||||
@socketio.on('json')
|
||||
def handle_json(json):
|
||||
print('received json: ' + str(json))
|
||||
|
||||
@staticmethod
|
||||
def _request_request_recorder_status_update():
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _test_on_msg_func():
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
@socketio.on('update_message_test_blabla')
|
||||
def handle_msg(msg=None):
|
||||
print('received msg: ' + str(msg))
|
||||
socketio.on_event('my event', WebSocketBase._test_on_msg_func, namespace='/')
|
||||
|
||||
@staticmethod
|
||||
@socketio.on_error()
|
||||
def handle_error(self, error):
|
||||
def handle_error(error):
|
||||
logger.error(error)
|
||||
print(error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user