fix: correct the gestures bugs, change gestures socket to request/reply
ref: N25B-334
This commit is contained in:
@@ -66,23 +66,19 @@ async def get_available_gesture_tags(request: Request):
|
||||
:param request: The FastAPI request object.
|
||||
:return: A list of available gesture tags.
|
||||
"""
|
||||
sub_socket = Context.instance().socket(zmq.SUB)
|
||||
sub_socket.connect(settings.zmq_settings.internal_sub_address)
|
||||
sub_socket.setsockopt(zmq.SUBSCRIBE, b"get_gestures")
|
||||
|
||||
pub_socket: Socket = request.app.state.endpoints_pub_socket
|
||||
topic = b"send_gestures"
|
||||
req_socket = Context.instance().socket(zmq.REQ)
|
||||
req_socket.connect("tcp://localhost:7788")
|
||||
|
||||
# TODO: Implement a way to get a certain ammount from the UI, rather than everything.
|
||||
amount = None
|
||||
timeout = 5 # seconds
|
||||
|
||||
await pub_socket.send_multipart([topic, amount.to_bytes(4, "big") if amount else b""])
|
||||
await req_socket.send(f"{amount}".encode() if amount else b"None")
|
||||
try:
|
||||
_, body = await asyncio.wait_for(sub_socket.recv_multipart(), timeout=timeout)
|
||||
body = await asyncio.wait_for(req_socket.recv(), timeout=timeout)
|
||||
except TimeoutError:
|
||||
body = b"tags: []"
|
||||
logger.debug("got timeout error fetching gestures")
|
||||
body = '{"tags": []}'
|
||||
logger.debug("Got timeout error fetching gestures.")
|
||||
|
||||
# Handle empty response and JSON decode errors
|
||||
available_tags = []
|
||||
|
||||
Reference in New Issue
Block a user