diff --git a/Checkfailed.html b/Checkfailed.html index b426924..7decc99 100644 --- a/Checkfailed.html +++ b/Checkfailed.html @@ -1,40 +1,40 @@ - - - - Welcome to nginx! - - - -

Welcome to nginx!

-

- If you see this page, the nginx web server is successfully installed and - working. Further configuration is required. If you are expecting another - page, please check your network or - Refresh this page -

- -

- For online documentation and support please refer to - nginx.org.
- Commercial support is available at - nginx.com. -

- -

Thank you for using nginx.

- - - + + + + Welcome to nginx! + + + +

Welcome to nginx!

+

+ If you see this page, the nginx web server is successfully installed and + working. Further configuration is required. If you are expecting another + page, please check your network or + Refresh this page +

+ +

+ For online documentation and support please refer to + nginx.org.
+ Commercial support is available at + nginx.com. +

+ +

Thank you for using nginx.

+ + + diff --git a/package.json b/package.json index b53d79c..eed348b 100644 --- a/package.json +++ b/package.json @@ -1,62 +1,62 @@ -{ - "name": "nebula", - "private": true, - "type": "module", - "scripts": { - "dev": "concurrently \"vite\" \"bare-server-node --port 8080\"", - "build": "vite build", - "bstart": "npm run build && tsx server.ts", - "start": "tsx server.ts", - "preview": "vite preview", - "format": "prettier --write ." - }, - "dependencies": { - "@fastify/compress": "^6.5.0", - "@fastify/cookie": "^9.3.1", - "@fastify/static": "^6.12.0", - "@mercuryworkshop/bare-mux": "^1.0.4", - "@mercuryworkshop/epoxy-transport": "^1.0.2", - "@nebula-services/bare-server-node": "2.0.1-patch.1", - "@nebula-services/dynamic": "0.7.2-patch.2", - "@titaniumnetwork-dev/ultraviolet": "^3.0.0", - "@types/express": "^4.17.21", - "chalk": "^5.3.0", - "classnames": "^2.5.1", - "compression": "^1.7.4", - "cookie-parser": "^1.4.6", - "crypto-js": "^4.2.0", - "express": "^4.18.3", - "fastify": "^4.26.2", - "framer-motion": "^10.18.0", - "i18next": "^23.10.0", - "i18next-browser-languagedetector": "^7.2.0", - "localforage": "^1.10.0", - "million": "^2.6.4", - "preact": "^10.19.6", - "preact-iso": "^2.4.0", - "preact-render-to-string": "^6.4.0", - "preact-router": "^4.1.2", - "rammerhead": "https://github.com/NebulaServices/rammerhead/releases/download/rammerhead-1.2.41-nebula.8/rammerhead-1.2.41-nebula.7.tgz", - "react-helmet": "^6.1.0", - "react-i18next": "^13.5.0", - "react-icons": "^4.12.0", - "react-toastify": "^9.1.3", - "tsx": "^4.7.1", - "wisp-server-node": "^1.0.1", - "ws": "^8.16.0" - }, - "devDependencies": { - "@preact/preset-vite": "^2.8.1", - "autoprefixer": "^10.4.18", - "concurrently": "^8.2.2", - "eslint": "^8.57.0", - "eslint-config-preact": "^1.3.0", - "postcss": "^8.4.35", - "prettier": "^3.2.5", - "prettier-plugin-tailwindcss": "^0.5.11", - "tailwindcss": "^3.4.1", - "typescript": "^5.3.3", - "vite": "^5.1.4", - "vite-plugin-static-copy": "^1.0.1" - } -} +{ + "name": "nebula", + "private": true, + "type": "module", + "scripts": { + "dev": "concurrently \"vite\" \"bare-server-node --port 8080\"", + "build": "vite build", + "bstart": "npm run build && tsx server.ts", + "start": "tsx server.ts", + "preview": "vite preview", + "format": "prettier --write ." + }, + "dependencies": { + "@fastify/compress": "^6.5.0", + "@fastify/cookie": "^9.3.1", + "@fastify/static": "^6.12.0", + "@mercuryworkshop/bare-mux": "^1.0.4", + "@mercuryworkshop/epoxy-transport": "^1.0.2", + "@nebula-services/bare-server-node": "2.0.1-patch.1", + "@nebula-services/dynamic": "0.7.2-patch.2", + "@titaniumnetwork-dev/ultraviolet": "^3.0.0", + "@types/express": "^4.17.21", + "chalk": "^5.3.0", + "classnames": "^2.5.1", + "compression": "^1.7.4", + "cookie-parser": "^1.4.6", + "crypto-js": "^4.2.0", + "express": "^4.18.3", + "fastify": "^4.26.2", + "framer-motion": "^10.18.0", + "i18next": "^23.10.0", + "i18next-browser-languagedetector": "^7.2.0", + "localforage": "^1.10.0", + "million": "^2.6.4", + "preact": "^10.19.6", + "preact-iso": "^2.4.0", + "preact-render-to-string": "^6.4.0", + "preact-router": "^4.1.2", + "rammerhead": "https://github.com/NebulaServices/rammerhead/releases/download/rammerhead-1.2.41-nebula.8/rammerhead-1.2.41-nebula.7.tgz", + "react-helmet": "^6.1.0", + "react-i18next": "^13.5.0", + "react-icons": "^4.12.0", + "react-toastify": "^9.1.3", + "tsx": "^4.7.1", + "wisp-server-node": "^1.0.1", + "ws": "^8.16.0" + }, + "devDependencies": { + "@preact/preset-vite": "^2.8.1", + "autoprefixer": "^10.4.18", + "concurrently": "^8.2.2", + "eslint": "^8.57.0", + "eslint-config-preact": "^1.3.0", + "postcss": "^8.4.35", + "prettier": "^3.2.5", + "prettier-plugin-tailwindcss": "^0.5.11", + "tailwindcss": "^3.4.1", + "typescript": "^5.3.3", + "vite": "^5.1.4", + "vite-plugin-static-copy": "^1.0.1" + } +} diff --git a/server.ts b/server.ts index eeaf8f5..520cf1c 100644 --- a/server.ts +++ b/server.ts @@ -158,9 +158,8 @@ server.on("upgrade", (req: Request, socket: Socket, head: Head) => { bare.routeUpgrade(req, socket, head); } else if (shouldRouteRh(req)) { routeRhUpgrade(req, socket, head); - } - else if (req.url.endsWith("/wisp/")) { - wisp.routeRequest(req, socket, head); + } else if (req.url.endsWith("/wisp/")) { + wisp.routeRequest(req, socket, head); } }); diff --git a/src/components/Meta.tsx b/src/components/Meta.tsx index acd0a37..82cab45 100644 --- a/src/components/Meta.tsx +++ b/src/components/Meta.tsx @@ -1,88 +1,88 @@ -import { Helmet } from "react-helmet"; -export default function Meta() { - return ( - - - - - - - - - - - - - - - - - - - ); -} +import { Helmet } from "react-helmet"; +export default function Meta() { + return ( + + + + + + + + + + + + + + + + + + + ); +} diff --git a/src/pages/Faq.css b/src/pages/Faq.css index d8570a5..7bc3b6b 100644 --- a/src/pages/Faq.css +++ b/src/pages/Faq.css @@ -1,4 +1,4 @@ -.highlighted { - background-color: var(--navbar-text-color); - transition: background-color 1s ease; -} +.highlighted { + background-color: var(--navbar-text-color); + transition: background-color 1s ease; +} diff --git a/src/pages/Faq.tsx b/src/pages/Faq.tsx index 52dad7e..ab9f08b 100644 --- a/src/pages/Faq.tsx +++ b/src/pages/Faq.tsx @@ -1,51 +1,51 @@ -import { useTranslation } from "react-i18next"; -import { HeaderRoute } from "../components/HeaderRoute"; -import CloakedHead from "../util/CloakedHead"; -import { useEffect } from "preact/hooks"; -import "./Faq.css"; - -export function Faq() { - const { t } = useTranslation(); - - const faqData = t("faq", { returnObjects: true }); - - useEffect(() => { - const hash = window.location.hash.substring(1); - - if (hash) { - const highlightedDiv = document.getElementById(hash); - - if (highlightedDiv) { - highlightedDiv.classList.add("highlighted"); - } - } - }, []); - - return ( - - -
- {Object.values(faqData).map((item, index) => ( -
-

- {item.q} -

-
-

- {item.a}{" "} - {item.h && ( - - {item.h} - - )} -

-
-
- ))} -
-
- ); -} +import { useTranslation } from "react-i18next"; +import { HeaderRoute } from "../components/HeaderRoute"; +import CloakedHead from "../util/CloakedHead"; +import { useEffect } from "preact/hooks"; +import "./Faq.css"; + +export function Faq() { + const { t } = useTranslation(); + + const faqData = t("faq", { returnObjects: true }); + + useEffect(() => { + const hash = window.location.hash.substring(1); + + if (hash) { + const highlightedDiv = document.getElementById(hash); + + if (highlightedDiv) { + highlightedDiv.classList.add("highlighted"); + } + } + }, []); + + return ( + + +
+ {Object.values(faqData).map((item, index) => ( +
+

+ {item.q} +

+
+

+ {item.a}{" "} + {item.h && ( + + {item.h} + + )} +

+
+
+ ))} +
+
+ ); +} diff --git a/src/pages/Settings/BareTest.tsx b/src/pages/Settings/BareTest.tsx index 127c2e3..7dbf6e1 100644 --- a/src/pages/Settings/BareTest.tsx +++ b/src/pages/Settings/BareTest.tsx @@ -1,29 +1,29 @@ -export function BareTest(bareUrl) { - const headers = new Headers({ - "x-bare-url": "https://www.google.com", - "X-Bare-Headers": JSON.stringify({ - Accept: - "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" - }) - }); - - return fetch(bareUrl, { - method: "GET", - headers: headers - }) - .then((response) => { - if ( - response.headers.get("x-bare-status") === "200" || - response.headers.get("x-bare-status") === "302" - ) { - return true; - } else { - // the site is a real site but doesn't act like a bare server - return false; - } - }) - .catch((error) => { - // incase the site doesn't exist - return false; - }); -} +export function BareTest(bareUrl) { + const headers = new Headers({ + "x-bare-url": "https://www.google.com", + "X-Bare-Headers": JSON.stringify({ + Accept: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" + }) + }); + + return fetch(bareUrl, { + method: "GET", + headers: headers + }) + .then((response) => { + if ( + response.headers.get("x-bare-status") === "200" || + response.headers.get("x-bare-status") === "302" + ) { + return true; + } else { + // the site is a real site but doesn't act like a bare server + return false; + } + }) + .catch((error) => { + // incase the site doesn't exist + return false; + }); +} diff --git a/src/pages/Settings/Dropdown.tsx b/src/pages/Settings/Dropdown.tsx index 7a366c2..0c5f86d 100644 --- a/src/pages/Settings/Dropdown.tsx +++ b/src/pages/Settings/Dropdown.tsx @@ -9,7 +9,7 @@ interface Option { const Dropdown = ({ storageKey, options, - refresh, + refresh }: { storageKey: string; options: Option[]; diff --git a/src/pages/Settings/Proxy.tsx b/src/pages/Settings/Proxy.tsx index 5e0a831..5c0764e 100644 --- a/src/pages/Settings/Proxy.tsx +++ b/src/pages/Settings/Proxy.tsx @@ -29,11 +29,12 @@ const Proxy = ({ id, active }) => { { id: "https://bing.com/search?q=%s", label: "Bing" } ]; - const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; + const wispUrl = + (location.protocol === "https:" ? "wss://" : "ws://") + + location.host + + "/wisp/"; //libcurl can be added here when it's stable - const transports = [ - { id: "epoxy", label: "Epoxy" } - ]; + const transports = [{ id: "epoxy", label: "Epoxy" }]; return ( {
-
- Wisp Server -
-
- Enter the url of a Wisp server -
- +
+ Wisp Server +
+
+ Enter the url of a Wisp server +
+
-
- Transport -
-
- Select the transport to use -
- changeTransport(value, wispUrl)} /> +
+ Transport +
+
+ Select the transport to use +
+ changeTransport(value, wispUrl)} + />
diff --git a/src/pages/Settings/ProxyInput.tsx b/src/pages/Settings/ProxyInput.tsx index 77ac484..afbbaa5 100644 --- a/src/pages/Settings/ProxyInput.tsx +++ b/src/pages/Settings/ProxyInput.tsx @@ -1,140 +1,140 @@ -import { useState, useEffect } from "preact/hooks"; -import { set } from "../../util/IDB"; -import { uninstallServiceWorkers } from "../../util/SWHelper"; -import { useTranslation } from "react-i18next"; -import { ToastContainer, toast } from "react-toastify"; - -interface BareInputProps { - placeholder: string; - storageKey: string; -} - -function ProxyInput(props: BareInputProps) { - const { t } = useTranslation(); - const bareServer = localStorage.getItem("bare") || "/bare/"; - const HTTPProxy = localStorage.getItem("HTTPProxy") || ""; - const [inputValue, setInputValue] = useState(HTTPProxy); - - function resetProxy() { - set("HTTPProxy", ""); - localStorage.setItem("HTTPProxy", ""); - uninstallServiceWorkers(); - window.location.reload(); - } - - function validateUrl(url: string) { - let finalUrl = url; - - if (url === null || url === undefined || url === "") { - finalUrl = ""; - return finalUrl; - } - - return finalUrl; - } - function handleChange() { - const proxyUrl = validateUrl( - (document.getElementById("pinput") as HTMLInputElement).value - ); - - if (!(proxyUrl === "")) { - const [proxyIP, proxyPort] = proxyUrl.split(":"); - - fetch(bareServer) - .then((response) => response.json()) - .then((jsonResponse) => { - if (jsonResponse.hasOwnProperty("HTTPProxy")) { - const headers = new Headers({ - "x-bare-url": "https://www.google.com", - "X-Bare-Headers": JSON.stringify({ - Accept: - "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" - }), - "x-bare-proxy-ip": proxyIP, - "x-bare-proxy-port": proxyPort - }); - - return fetch(bareServer + "v3/", { - method: "GET", - headers: headers - }) - .then((response) => { - if ( - response.headers.get("x-bare-status") === "200" || - response.headers.get("x-bare-status") === "302" - ) { - // Success! - set("HTTPProxy", proxyUrl); - localStorage.setItem("HTTPProxy", proxyUrl); - uninstallServiceWorkers(); - window.location.reload(); - return true; - } else { - ( - document.getElementById("pinput") as HTMLInputElement - ).value = localStorage.getItem("HTTPProxy") || ""; - toast(t("settings.httpProxy.badProxy"), { - type: "error" - }); - } - }) - .catch((error) => { - (document.getElementById("pinput") as HTMLInputElement).value = - localStorage.getItem("HTTPProxy") || ""; - toast(t("settings.httpProxy.badProxy"), { - type: "error" - }); - }); - } else { - (document.getElementById("pinput") as HTMLInputElement).value = - localStorage.getItem("HTTPProxy") || ""; - toast(t("settings.httpProxy.badBare"), { - type: "error" - }); - } - }) - .catch((error) => console.error("Error:", error)); - } else { - // reset UV config to have no proxy - set("HTTPProxy", ""); - localStorage.setItem("HTTPProxy", ""); - uninstallServiceWorkers(); - window.location.reload(); - } - } - return ( -
- -
- { - if (event.key === "Enter") { - handleChange(); - } - }} - id="pinput" - className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-sm text-input-text" - /> -
-
- {t("settings.bare.select")} -
-
- {t("settings.httpProxy.reset")} -
-
-
-
- ); -} - -export default ProxyInput; +import { useState, useEffect } from "preact/hooks"; +import { set } from "../../util/IDB"; +import { uninstallServiceWorkers } from "../../util/SWHelper"; +import { useTranslation } from "react-i18next"; +import { ToastContainer, toast } from "react-toastify"; + +interface BareInputProps { + placeholder: string; + storageKey: string; +} + +function ProxyInput(props: BareInputProps) { + const { t } = useTranslation(); + const bareServer = localStorage.getItem("bare") || "/bare/"; + const HTTPProxy = localStorage.getItem("HTTPProxy") || ""; + const [inputValue, setInputValue] = useState(HTTPProxy); + + function resetProxy() { + set("HTTPProxy", ""); + localStorage.setItem("HTTPProxy", ""); + uninstallServiceWorkers(); + window.location.reload(); + } + + function validateUrl(url: string) { + let finalUrl = url; + + if (url === null || url === undefined || url === "") { + finalUrl = ""; + return finalUrl; + } + + return finalUrl; + } + function handleChange() { + const proxyUrl = validateUrl( + (document.getElementById("pinput") as HTMLInputElement).value + ); + + if (!(proxyUrl === "")) { + const [proxyIP, proxyPort] = proxyUrl.split(":"); + + fetch(bareServer) + .then((response) => response.json()) + .then((jsonResponse) => { + if (jsonResponse.hasOwnProperty("HTTPProxy")) { + const headers = new Headers({ + "x-bare-url": "https://www.google.com", + "X-Bare-Headers": JSON.stringify({ + Accept: + "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" + }), + "x-bare-proxy-ip": proxyIP, + "x-bare-proxy-port": proxyPort + }); + + return fetch(bareServer + "v3/", { + method: "GET", + headers: headers + }) + .then((response) => { + if ( + response.headers.get("x-bare-status") === "200" || + response.headers.get("x-bare-status") === "302" + ) { + // Success! + set("HTTPProxy", proxyUrl); + localStorage.setItem("HTTPProxy", proxyUrl); + uninstallServiceWorkers(); + window.location.reload(); + return true; + } else { + ( + document.getElementById("pinput") as HTMLInputElement + ).value = localStorage.getItem("HTTPProxy") || ""; + toast(t("settings.httpProxy.badProxy"), { + type: "error" + }); + } + }) + .catch((error) => { + (document.getElementById("pinput") as HTMLInputElement).value = + localStorage.getItem("HTTPProxy") || ""; + toast(t("settings.httpProxy.badProxy"), { + type: "error" + }); + }); + } else { + (document.getElementById("pinput") as HTMLInputElement).value = + localStorage.getItem("HTTPProxy") || ""; + toast(t("settings.httpProxy.badBare"), { + type: "error" + }); + } + }) + .catch((error) => console.error("Error:", error)); + } else { + // reset UV config to have no proxy + set("HTTPProxy", ""); + localStorage.setItem("HTTPProxy", ""); + uninstallServiceWorkers(); + window.location.reload(); + } + } + return ( +
+ +
+ { + if (event.key === "Enter") { + handleChange(); + } + }} + id="pinput" + className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-sm text-input-text" + /> +
+
+ {t("settings.bare.select")} +
+
+ {t("settings.httpProxy.reset")} +
+
+
+
+ ); +} + +export default ProxyInput; diff --git a/src/pages/Settings/WispInput.tsx b/src/pages/Settings/WispInput.tsx index dec8a8d..d84a79f 100644 --- a/src/pages/Settings/WispInput.tsx +++ b/src/pages/Settings/WispInput.tsx @@ -1,58 +1,66 @@ -import { useState, useEffect } from "preact/hooks"; -import { useTranslation } from "react-i18next"; -import { changeTransport } from "../../util/transports"; -import { ToastContainer, toast } from "react-toastify"; - -interface WispInputProps { - placeholder: string; -} - -function WispInput(props: WispInputProps) { - const { t } = useTranslation(); - const value = localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; - const [inputValue, setInputValue] = useState(value); - function validateUrl(url: string) { - let finalUrl = url; - if (finalUrl.startsWith("http://")) { - finalUrl = finalUrl.replace("http://", "ws://"); - } else if (finalUrl.startsWith("https://")) { - finalUrl = finalUrl.replace("https://", "wss://"); - } - else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) { - finalUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; - } - return finalUrl; - } - function handleChange() { - const url = validateUrl((document.getElementById("wispinput") as HTMLInputElement).value); - localStorage.setItem("wispUrl", url); - changeTransport(localStorage.getItem("transport") || "epoxy", url); - } - return ( -
- -
- { - if (event.key === "Enter") { - handleChange(); - } - }} - id="wispinput" - className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-xl text-input-text" - /> -
- Select -
-
-
- ); -} - -export default WispInput; +import { useState, useEffect } from "preact/hooks"; +import { useTranslation } from "react-i18next"; +import { changeTransport } from "../../util/transports"; +import { ToastContainer, toast } from "react-toastify"; + +interface WispInputProps { + placeholder: string; +} + +function WispInput(props: WispInputProps) { + const { t } = useTranslation(); + const value = + localStorage.getItem("wispUrl") || + (location.protocol === "https:" ? "wss://" : "ws://") + + location.host + + "/wisp/"; + const [inputValue, setInputValue] = useState(value); + function validateUrl(url: string) { + let finalUrl = url; + if (finalUrl.startsWith("http://")) { + finalUrl = finalUrl.replace("http://", "ws://"); + } else if (finalUrl.startsWith("https://")) { + finalUrl = finalUrl.replace("https://", "wss://"); + } else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) { + finalUrl = + (location.protocol === "https:" ? "wss://" : "ws://") + + location.host + + "/wisp/"; + } + return finalUrl; + } + function handleChange() { + const url = validateUrl( + (document.getElementById("wispinput") as HTMLInputElement).value + ); + localStorage.setItem("wispUrl", url); + changeTransport(localStorage.getItem("transport") || "epoxy", url); + } + return ( +
+ +
+ { + if (event.key === "Enter") { + handleChange(); + } + }} + id="wispinput" + className="font-roboto flex h-14 w-56 flex-row rounded-2xl border border-input-border-color bg-input p-4 text-center text-xl text-input-text" + /> +
+ Select +
+
+
+ ); +} + +export default WispInput; diff --git a/src/pages/config.json b/src/pages/config.json index f2ea571..4d20b55 100644 --- a/src/pages/config.json +++ b/src/pages/config.json @@ -1,3 +1,3 @@ -{ - "prod": false -} +{ + "prod": false +} diff --git a/src/util/transports.ts b/src/util/transports.ts index 56f7aa5..1a519d2 100644 --- a/src/util/transports.ts +++ b/src/util/transports.ts @@ -1,40 +1,54 @@ -import { SetTransport, registerRemoteListener } from "@mercuryworkshop/bare-mux"; - - -declare global { - interface Window { - BareMux: any; - p: any; - } -} - -function changeTransport(transport: string, wispUrl: string) { - switch (transport) { - case "epoxy": - localStorage.setItem("transport", "epoxy"); - SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); - break; - //libcurl when supported can be easily added here - //and stuff like bare-as-module3 COULD also be added - default: - SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); - break; - } -} - -function getTransport() { - return localStorage.getItem("transport") || "epoxy"; -} - -function restartTransport() { - changeTransport(getTransport(), localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"); -} - -//restart transport every minute -setInterval(restartTransport, 60000); //60000ms = 60s = 1m - -const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; -registerRemoteListener(navigator.serviceWorker.controller!); -changeTransport(localStorage.getItem("transport") || "epoxy", localStorage.getItem("wispUrl") || wispUrl); - -export { changeTransport, getTransport }; +import { + SetTransport, + registerRemoteListener +} from "@mercuryworkshop/bare-mux"; + +declare global { + interface Window { + BareMux: any; + p: any; + } +} + +function changeTransport(transport: string, wispUrl: string) { + switch (transport) { + case "epoxy": + localStorage.setItem("transport", "epoxy"); + SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); + break; + //libcurl when supported can be easily added here + //and stuff like bare-as-module3 COULD also be added + default: + SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl }); + break; + } +} + +function getTransport() { + return localStorage.getItem("transport") || "epoxy"; +} + +function restartTransport() { + changeTransport( + getTransport(), + localStorage.getItem("wispUrl") || + (location.protocol === "https:" ? "wss://" : "ws://") + + location.host + + "/wisp/" + ); +} + +//restart transport every minute +setInterval(restartTransport, 60000); //60000ms = 60s = 1m + +const wispUrl = + (location.protocol === "https:" ? "wss://" : "ws://") + + location.host + + "/wisp/"; +registerRemoteListener(navigator.serviceWorker.controller!); +changeTransport( + localStorage.getItem("transport") || "epoxy", + localStorage.getItem("wispUrl") || wispUrl +); + +export { changeTransport, getTransport }; diff --git a/vite.config.ts b/vite.config.ts index 3940dd6..c179700 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -25,10 +25,10 @@ export default defineConfig({ // overwrite: false //}, { - //include ALL files types - src: `${epoxyPath}/**/*`, - dest: "epoxy", - overwrite: false + //include ALL files types + src: `${epoxyPath}/**/*`, + dest: "epoxy", + overwrite: false }, { // .replace fixes weird paths on Windows