From 8bbecaa7b798bc429fa17358027307b7da4bdd6d Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 11 Feb 2023 15:28:33 -0600 Subject: [PATCH] protocol detection --- .woodpecker.yml | 2 ++ src/static/index.html | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.woodpecker.yml b/.woodpecker.yml index f02acd8..a3105ab 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -36,6 +36,7 @@ pipeline: - podman login git.mzhang.io --username michael --password $DOCKER_TOKEN - podman push $REPO:$TAG - podman push $REPO:latest + - exit 1 secrets: - DOCKER_TOKEN volumes: @@ -43,3 +44,4 @@ pipeline: when: # event: tag branch: master + diff --git a/src/static/index.html b/src/static/index.html index 3359a57..9a4e1ff 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -34,7 +34,16 @@ // Connect to websocket let roomId = "{{ room_id }}"; - let ws = new WebSocket(`ws://${location.host}/ws/${roomId}`); + let protocol; + switch (location.protocol) { + case "https:": + protocol = "wss:"; + case "http:": + protocol = "ws:"; + default: + throw new Error("L"); + } + let ws = new WebSocket(`${protocol}//${location.host}/ws/${roomId}`); // Relay all messages to terminal ws.addEventListener("message", (msg) => {