You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
842 B
32 lines
842 B
4 years ago
|
# coding=utf-8
|
||
|
|
||
2 years ago
|
from .app import socketio
|
||
4 years ago
|
|
||
|
|
||
3 years ago
|
def event_stream(type, action="update", payload=None):
|
||
4 years ago
|
"""
|
||
|
:param type: The type of element.
|
||
|
:type type: str
|
||
3 years ago
|
:param action: The action type of element from update and delete.
|
||
4 years ago
|
:type action: str
|
||
3 years ago
|
:param payload: The payload to send, can be anything
|
||
4 years ago
|
"""
|
||
3 years ago
|
|
||
|
try:
|
||
|
payload = int(payload)
|
||
|
except (ValueError, TypeError):
|
||
|
pass
|
||
|
socketio.emit("data", {"type": type, "action": action, "payload": payload})
|
||
3 years ago
|
|
||
|
|
||
|
def show_message(msg):
|
||
|
event_stream(type="message", payload=msg)
|
||
|
|
||
|
|
||
3 years ago
|
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):
|
||
3 years ago
|
event_stream(type="progress", action="delete", payload=id)
|