Formatting
This commit is contained in:
parent
69823802f5
commit
8f531aff11
14 changed files with 568 additions and 541 deletions
|
|
@ -158,8 +158,7 @@ server.on("upgrade", (req: Request, socket: Socket, head: Head) => {
|
||||||
bare.routeUpgrade(req, socket, head);
|
bare.routeUpgrade(req, socket, head);
|
||||||
} else if (shouldRouteRh(req)) {
|
} else if (shouldRouteRh(req)) {
|
||||||
routeRhUpgrade(req, socket, head);
|
routeRhUpgrade(req, socket, head);
|
||||||
}
|
} else if (req.url.endsWith("/wisp/")) {
|
||||||
else if (req.url.endsWith("/wisp/")) {
|
|
||||||
wisp.routeRequest(req, socket, head);
|
wisp.routeRequest(req, socket, head);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ interface Option {
|
||||||
const Dropdown = ({
|
const Dropdown = ({
|
||||||
storageKey,
|
storageKey,
|
||||||
options,
|
options,
|
||||||
refresh,
|
refresh
|
||||||
}: {
|
}: {
|
||||||
storageKey: string;
|
storageKey: string;
|
||||||
options: Option[];
|
options: Option[];
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,12 @@ const Proxy = ({ id, active }) => {
|
||||||
{ id: "https://bing.com/search?q=%s", label: "Bing" }
|
{ 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
|
//libcurl can be added here when it's stable
|
||||||
const transports = [
|
const transports = [{ id: "epoxy", label: "Epoxy" }];
|
||||||
{ id: "epoxy", label: "Epoxy" }
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|
@ -108,7 +109,12 @@ const Proxy = ({ id, active }) => {
|
||||||
<div className="text-md p-4 font-bold text-input-text">
|
<div className="text-md p-4 font-bold text-input-text">
|
||||||
Select the transport to use
|
Select the transport to use
|
||||||
</div>
|
</div>
|
||||||
<Dropdown storageKey="transport" options={transports} refresh={false} onChange={(value) => changeTransport(value, wispUrl)} />
|
<Dropdown
|
||||||
|
storageKey="transport"
|
||||||
|
options={transports}
|
||||||
|
refresh={false}
|
||||||
|
onChange={(value) => changeTransport(value, wispUrl)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex h-96 w-96 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
<div className="flex h-96 w-96 flex-col flex-wrap content-center items-center rounded-lg border border-input-border-color bg-lighter p-2 text-center">
|
||||||
<div className="p-2 text-3xl font-bold text-input-text">
|
<div className="p-2 text-3xl font-bold text-input-text">
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ interface WispInputProps {
|
||||||
|
|
||||||
function WispInput(props: WispInputProps) {
|
function WispInput(props: WispInputProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const value = localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
|
const value =
|
||||||
|
localStorage.getItem("wispUrl") ||
|
||||||
|
(location.protocol === "https:" ? "wss://" : "ws://") +
|
||||||
|
location.host +
|
||||||
|
"/wisp/";
|
||||||
const [inputValue, setInputValue] = useState(value);
|
const [inputValue, setInputValue] = useState(value);
|
||||||
function validateUrl(url: string) {
|
function validateUrl(url: string) {
|
||||||
let finalUrl = url;
|
let finalUrl = url;
|
||||||
|
|
@ -17,14 +21,18 @@ function WispInput(props: WispInputProps) {
|
||||||
finalUrl = finalUrl.replace("http://", "ws://");
|
finalUrl = finalUrl.replace("http://", "ws://");
|
||||||
} else if (finalUrl.startsWith("https://")) {
|
} else if (finalUrl.startsWith("https://")) {
|
||||||
finalUrl = finalUrl.replace("https://", "wss://");
|
finalUrl = finalUrl.replace("https://", "wss://");
|
||||||
}
|
} else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) {
|
||||||
else if (finalUrl === "" || finalUrl === null || finalUrl === undefined) {
|
finalUrl =
|
||||||
finalUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
|
(location.protocol === "https:" ? "wss://" : "ws://") +
|
||||||
|
location.host +
|
||||||
|
"/wisp/";
|
||||||
}
|
}
|
||||||
return finalUrl;
|
return finalUrl;
|
||||||
}
|
}
|
||||||
function handleChange() {
|
function handleChange() {
|
||||||
const url = validateUrl((document.getElementById("wispinput") as HTMLInputElement).value);
|
const url = validateUrl(
|
||||||
|
(document.getElementById("wispinput") as HTMLInputElement).value
|
||||||
|
);
|
||||||
localStorage.setItem("wispUrl", url);
|
localStorage.setItem("wispUrl", url);
|
||||||
changeTransport(localStorage.getItem("transport") || "epoxy", url);
|
changeTransport(localStorage.getItem("transport") || "epoxy", url);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { SetTransport, registerRemoteListener } from "@mercuryworkshop/bare-mux";
|
import {
|
||||||
|
SetTransport,
|
||||||
|
registerRemoteListener
|
||||||
|
} from "@mercuryworkshop/bare-mux";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|
@ -27,14 +29,26 @@ function getTransport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function restartTransport() {
|
function restartTransport() {
|
||||||
changeTransport(getTransport(), localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/");
|
changeTransport(
|
||||||
|
getTransport(),
|
||||||
|
localStorage.getItem("wispUrl") ||
|
||||||
|
(location.protocol === "https:" ? "wss://" : "ws://") +
|
||||||
|
location.host +
|
||||||
|
"/wisp/"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//restart transport every minute
|
//restart transport every minute
|
||||||
setInterval(restartTransport, 60000); //60000ms = 60s = 1m
|
setInterval(restartTransport, 60000); //60000ms = 60s = 1m
|
||||||
|
|
||||||
const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
|
const wispUrl =
|
||||||
|
(location.protocol === "https:" ? "wss://" : "ws://") +
|
||||||
|
location.host +
|
||||||
|
"/wisp/";
|
||||||
registerRemoteListener(navigator.serviceWorker.controller!);
|
registerRemoteListener(navigator.serviceWorker.controller!);
|
||||||
changeTransport(localStorage.getItem("transport") || "epoxy", localStorage.getItem("wispUrl") || wispUrl);
|
changeTransport(
|
||||||
|
localStorage.getItem("transport") || "epoxy",
|
||||||
|
localStorage.getItem("wispUrl") || wispUrl
|
||||||
|
);
|
||||||
|
|
||||||
export { changeTransport, getTransport };
|
export { changeTransport, getTransport };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue