From a0cc46cfc00e11fdf7635f20fee3cf9989e42281 Mon Sep 17 00:00:00 2001 From: Tom Chapin Date: Sat, 17 Feb 2024 22:27:58 -0800 Subject: [PATCH] Adding localtunnel support --- 01OS/.env.example | 4 ++-- 01OS/01OS/server/server.py | 2 +- 01OS/README.md | 5 +++++ 01OS/start.sh | 7 ++++++- 01OS/tunnel.sh | 14 ++++++++++---- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/01OS/.env.example b/01OS/.env.example index dd48b0d..f6b726d 100644 --- a/01OS/.env.example +++ b/01OS/.env.example @@ -18,8 +18,8 @@ PIPER_VOICE_NAME="en_US-lessac-medium.onnx" # If SERVER_START, this is where we'll serve the server. # If CLIENT_START, this is where the client expects the server to be. -# SERVER_CONNECTION_URL=wss://localhost:8000/ -SERVER_CONNECTION_URL=wss://localhost:8000/ +# SERVER_CONNECTION_URL=ws://localhost:8000/ +SERVER_CONNECTION_URL=ws://localhost:8000/ SERVER_START=True CLIENT_START=True diff --git a/01OS/01OS/server/server.py b/01OS/01OS/server/server.py index 24d88f0..c6e128f 100644 --- a/01OS/01OS/server/server.py +++ b/01OS/01OS/server/server.py @@ -289,7 +289,7 @@ if __name__ == "__main__": asyncio.create_task(put_kernel_messages_into_queue(from_computer)) # Start the server - logger.info("Starting `server.py`... on wss://localhost:" + str(SERVER_LOCAL_PORT)) + logger.info("Starting `server.py`... on localhost:" + str(SERVER_LOCAL_PORT)) config = Config(app, host="localhost", port=SERVER_LOCAL_PORT, lifespan='on') server = Server(config) diff --git a/01OS/README.md b/01OS/README.md index 9b773c8..a16ccb3 100644 --- a/01OS/README.md +++ b/01OS/README.md @@ -11,6 +11,11 @@ pip install 01OS **Expose an 01 server publically:** +We are currently using localtunnel to handle the creation of public tunnel endpoints. + +Note: You will need to install Node and the localtunnel tool before this will work correctly: +```npm install -g localtunnel``` + ```bash 01 --server --expose # This will print a URL that a client can point to. ``` diff --git a/01OS/start.sh b/01OS/start.sh index de886e9..adcd852 100755 --- a/01OS/start.sh +++ b/01OS/start.sh @@ -56,7 +56,12 @@ fi # Check if "--expose" is passed as an argument if [[ "$@" == *"--expose"* ]]; then - export TUNNEL_START="True" + if [[ "$SERVER_START" != "True" ]]; then + echo "Error: Start script must be started with --serve for tunneling to work." + exit 1 + else + export TUNNEL_START="True" + fi fi # Check if "--clear-local" is passed as an argument diff --git a/01OS/tunnel.sh b/01OS/tunnel.sh index 0f50c0d..2c7138a 100755 --- a/01OS/tunnel.sh +++ b/01OS/tunnel.sh @@ -1,8 +1,14 @@ #!/usr/bin/env bash -echo "Starting up localhost.run tunnel..." -ssh -o StrictHostKeyChecking=no -R 80:localhost:8000 nokey@localhost.run 2>&1 | while IFS= read -r line; do - if [[ "$line" =~ https://([a-zA-Z0-9]+\.lhr\.life) ]]; then - echo "Your free localhost.run tunnel is now active. Please set your client SERVER_CONNECTION_URL env var to: \"wss://${BASH_REMATCH[1]}\"" +# Get the SERVER_PORT environment variable, but default to 8000 +SERVER_LOCAL_PORT=${SERVER_LOCAL_PORT:-8000} + +echo "Starting up localtunnel service for port $SERVER_LOCAL_PORT on localhost..." + +npx localtunnel --port $SERVER_LOCAL_PORT | while IFS= read -r line; do + if [[ "$line" == "your url is: https://"* ]]; then + echo "Tunnel is up!" + echo "Please set your client env variable for SERVER_CONNECTION_URL=wss://${line:21}" + break fi done