Epoxy Transport setup and working (mostly0

This commit is contained in:
MotorTruck1221 2024-03-06 01:02:13 -07:00
parent fd4c4f6fcb
commit af88c5475b
No known key found for this signature in database
GPG key ID: 06901A625432AC21
3 changed files with 13 additions and 6 deletions

View file

@ -16,7 +16,6 @@
scope: "/~/" scope: "/~/"
}); });
}); });
console.log("Service Worker Registered");
} }
</script> </script>
</head> </head>

View file

@ -1,5 +1,6 @@
import { useState, useEffect } from "preact/hooks"; import { useState, useEffect } from "preact/hooks";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { changeTransport } from "../../util/transports";
import { ToastContainer, toast } from "react-toastify"; import { ToastContainer, toast } from "react-toastify";
interface WispInputProps { interface WispInputProps {
@ -17,10 +18,15 @@ function WispInput(props: WispInputProps) {
} 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) {
finalUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
}
return finalUrl;
} }
function handleChange() { function handleChange() {
const url = validateUrl((document.getElementById("input") 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);
} }
return ( return (
<div> <div>
@ -35,7 +41,7 @@ function WispInput(props: WispInputProps) {
handleChange(); handleChange();
} }
}} }}
id="input" 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" 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"
/> />
<div <div

View file

@ -7,6 +7,7 @@ declare global {
p: any; p: any;
} }
} }
function changeTransport(transport: string, wispUrl: string) { function changeTransport(transport: string, wispUrl: string) {
switch (transport) { switch (transport) {
case "epoxy": case "epoxy":
@ -20,7 +21,8 @@ function changeTransport(transport: string, wispUrl: string) {
} }
} }
//registerRemoteListener(navigator.serviceWorker.controller!); const wispUrl = (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/";
//const p = changeTransport("epoxy", "ws://localhost:5173/wisp/"); registerRemoteListener(navigator.serviceWorker.controller!);
//window.p = p; changeTransport(localStorage.getItem("transport") || "epoxy", localStorage.getItem("wispUrl") || wispUrl);
export { changeTransport }; export { changeTransport };