feat(api/ws.py): WebSoket
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
from app import app
|
||||||
|
from flask_socketio import SocketIO, emit
|
||||||
|
from loguru import logger as log
|
||||||
|
#from module.db.repositories.robot_reposytory import update_robot get_by_id get_all
|
||||||
|
#from module.db.repositories.inventory_repository import get_all as getRecords
|
||||||
|
ws = socketIO(app)
|
||||||
|
|
||||||
|
@ws.on('connect')
|
||||||
|
def is_connect():
|
||||||
|
log.info('client is connected')
|
||||||
|
|
||||||
|
@ws.on('disconnect')
|
||||||
|
def is_disconnect():
|
||||||
|
log.info('client is disconnected')
|
||||||
|
|
||||||
|
@ws.on('robot_update')
|
||||||
|
def robotUpdate():
|
||||||
|
robots = get_all()
|
||||||
|
emit('response', jsonify({"type": "robot_update", "data": {robots.toJSON()}})
|
||||||
|
|
||||||
|
@ws.on('inventory_alert')
|
||||||
|
def robotUpdate():
|
||||||
|
records = getRecords()
|
||||||
|
emit('response', jsonify({"type": "inventory_alert", "data": {records.toJSON()}})
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user