Updated device to remove unecessary waiting

pull/21/head
Zohaib Rauf 11 months ago
parent d6f6622463
commit 09194721e8

@ -134,6 +134,8 @@ async def message_sender(websocket):
async def websocket_communication(WS_URL): async def websocket_communication(WS_URL):
while True: while True:
try: try:
logging.info(f"Connecting to `{WS_URL}` ...")
headers = {"ngrok-skip-browser-warning": str(80)} if os.getenv('NGROK_AUTHTOKEN') else {} headers = {"ngrok-skip-browser-warning": str(80)} if os.getenv('NGROK_AUTHTOKEN') else {}
async with websockets.connect(WS_URL, extra_headers=headers) as websocket: async with websockets.connect(WS_URL, extra_headers=headers) as websocket:
logging.info("Press the spacebar to start/stop recording. Press ESC to exit.") logging.info("Press the spacebar to start/stop recording. Press ESC to exit.")
@ -191,16 +193,6 @@ if __name__ == "__main__":
async def main(): async def main():
WS_URL = os.getenv('SERVER_CONNECTION_URL') WS_URL = os.getenv('SERVER_CONNECTION_URL')
start_time = time.time()
while WS_URL is None:
if time.time() - start_time > 60:
logging.error("SERVER_CONNECTION_URL environment variable is not set after 1 minute. Exiting...")
raise ValueError("The environment variable SERVER_CONNECTION_URL is not set. Please set it to proceed.")
logging.info("SERVER_CONNECTION_URL environment variable is not set. Waiting...")
await asyncio.sleep(5) # Wait for 5 seconds before checking again
WS_URL = os.getenv('SERVER_CONNECTION_URL')
# Start the WebSocket communication # Start the WebSocket communication
asyncio.create_task(websocket_communication(WS_URL)) asyncio.create_task(websocket_communication(WS_URL))

Loading…
Cancel
Save