From 1666695bf85a524e50105b8e2e9ebb2c3aada350 Mon Sep 17 00:00:00 2001 From: Zohaib Rauf Date: Sat, 10 Feb 2024 20:00:25 -0800 Subject: [PATCH] Updated --- OS/01/device.py | 5 +++-- OS/01/server.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OS/01/device.py b/OS/01/device.py index 244ef0d..154cc66 100644 --- a/OS/01/device.py +++ b/OS/01/device.py @@ -13,7 +13,6 @@ import ast from pydub import AudioSegment from pydub.playback import play import io -import time import wave import tempfile from datetime import datetime @@ -136,7 +135,7 @@ async def websocket_communication(WS_URL): 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), "User-Agent": "project01"} if os.getenv('NGROK_AUTHTOKEN') else {} async with websockets.connect(WS_URL, extra_headers=headers) as websocket: logging.info("Press the spacebar to start/stop recording. Press ESC to exit.") asyncio.create_task(message_sender(websocket)) @@ -192,6 +191,8 @@ if __name__ == "__main__": # Configuration for WebSocket async def main(): WS_URL = os.getenv('SERVER_CONNECTION_URL') + if not WS_URL: + raise ValueError("The environment variable SERVER_URL is not set. Please set it to proceed.") # Start the WebSocket communication asyncio.create_task(websocket_communication(WS_URL)) diff --git a/OS/01/server.py b/OS/01/server.py index 37b56a4..b40c107 100644 --- a/OS/01/server.py +++ b/OS/01/server.py @@ -254,7 +254,7 @@ if __name__ == "__main__": ngrok_parsed_url = urllib.parse.urlparse(ngrok_listener.url()) # Setup SERVER_URL environment variable for device to use - connection_url = f"ws://{ngrok_parsed_url.hostname}" + connection_url = f"wss://{ngrok_parsed_url.hostname}/" logging.info(f"Ngrok established at {ngrok_parsed_url.geturl()}") logging.info(f"\033[1mSERVER_CONNECTION_URL should be set to \"{connection_url}\"\033[0m")