2021-01-19 04:49:51 +00:00
|
|
|
# coding=utf-8
|
|
|
|
|
2020-05-12 12:25:03 +00:00
|
|
|
from app import socketio
|
|
|
|
|
|
|
|
|
2021-05-08 14:25:29 +00:00
|
|
|
def event_stream(type, action="update", payload=None):
|
2020-05-12 12:25:03 +00:00
|
|
|
"""
|
|
|
|
:param type: The type of element.
|
|
|
|
:type type: str
|
2021-05-08 14:25:29 +00:00
|
|
|
:param action: The action type of element from update and delete.
|
2020-05-12 12:25:03 +00:00
|
|
|
:type action: str
|
2021-05-08 14:25:29 +00:00
|
|
|
:param payload: The payload to send, can be anything
|
2020-05-12 12:25:03 +00:00
|
|
|
"""
|
2021-05-08 14:25:29 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
payload = int(payload)
|
|
|
|
except (ValueError, TypeError):
|
|
|
|
pass
|
|
|
|
socketio.emit("data", {"type": type, "action": action, "payload": payload})
|
2021-05-08 18:17:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def show_message(msg):
|
|
|
|
event_stream(type="message", payload=msg)
|
|
|
|
|
|
|
|
|
2021-05-10 23:52:36 +00:00
|
|
|
def show_progress(id, header, name, value, count):
|
|
|
|
event_stream(type="progress", payload={"id": id, "header": header, "name": name, "value": value, "count": count})
|
|
|
|
|
|
|
|
|
|
|
|
def hide_progress(id):
|
|
|
|
event_stream(type="progress", action="delete", payload={"id": id})
|