mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-05 23:14:53 -06:00
Add reconnection option, prevent autoplay, remove state on disconnect, mobile height adjustment
This commit is contained in:
@@ -26,6 +26,7 @@ const Demo = ({ class: className }: DemoProps) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
audioRef.current = new Audio("/notify.wav");
|
audioRef.current = new Audio("/notify.wav");
|
||||||
audioRef.current.volume = 1;
|
audioRef.current.volume = 1;
|
||||||
|
audioRef.current.autoplay = false;
|
||||||
return () => {
|
return () => {
|
||||||
audioRef.current!.remove();
|
audioRef.current!.remove();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { withBackend } from "@/util";
|
import { withBackend } from "@/util";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import useWebSocket from "react-use-websocket";
|
import useWebSocket, { ReadyState } from "react-use-websocket";
|
||||||
|
|
||||||
export interface Download {
|
export interface Download {
|
||||||
token: number;
|
token: number;
|
||||||
@@ -27,14 +27,22 @@ export interface UseSocketProps {
|
|||||||
notify?: (token: number) => void;
|
notify?: (token: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Status = "connected" | "disconnected" | "connecting";
|
export type Status =
|
||||||
|
| "connecting"
|
||||||
|
| "open"
|
||||||
|
| "closing"
|
||||||
|
| "closed"
|
||||||
|
| "uninstantiated";
|
||||||
|
|
||||||
function useSocket({ notify }: UseSocketProps): UseSocketResult {
|
function useSocket({ notify }: UseSocketProps): UseSocketResult {
|
||||||
const { sendMessage, lastMessage, readyState } = useWebSocket(
|
const { sendMessage, lastMessage, readyState } = useWebSocket(
|
||||||
withBackend(
|
withBackend(
|
||||||
window.location.protocol === "https:" ? "wss://" : "ws://",
|
window.location.protocol === "https:" ? "wss://" : "ws://",
|
||||||
"/ws"
|
"/ws"
|
||||||
)
|
),
|
||||||
|
{
|
||||||
|
shouldReconnect: () => true,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const [id, setId] = useState<number | null>(null);
|
const [id, setId] = useState<number | null>(null);
|
||||||
@@ -44,6 +52,22 @@ function useSocket({ notify }: UseSocketProps): UseSocketResult {
|
|||||||
executables: Executable[];
|
executables: Executable[];
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
const connectionStatus: Status = {
|
||||||
|
[ReadyState.CONNECTING]: "connecting",
|
||||||
|
[ReadyState.OPEN]: "open",
|
||||||
|
[ReadyState.CLOSING]: "closing",
|
||||||
|
[ReadyState.CLOSED]: "closed",
|
||||||
|
[ReadyState.UNINSTANTIATED]: "uninstantiated",
|
||||||
|
}[readyState] as Status;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (readyState === WebSocket.CLOSED || readyState === WebSocket.CLOSING) {
|
||||||
|
setId(null);
|
||||||
|
setDownloads(null);
|
||||||
|
setExecutables(null);
|
||||||
|
}
|
||||||
|
}, [readyState]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
{
|
{
|
||||||
if (lastMessage == null) return;
|
if (lastMessage == null) return;
|
||||||
|
|||||||
@@ -4,15 +4,17 @@ import Demo from "@/components/Demo";
|
|||||||
---
|
---
|
||||||
|
|
||||||
<Base>
|
<Base>
|
||||||
<div class="w-screen h-screen flex flex-col items-center middle">
|
<div class="w-screen min-h-screen flex flex-col items-center middle">
|
||||||
<div
|
<div
|
||||||
class="noise-card rounded-sm relative z-20 border-zinc-700 md:border w-full max-w-[40rem] min-h-[41.25rem] md:mt-16 mb-8 shadow-lg"
|
class="noise-card rounded-sm relative z-20 border-zinc-700 md:border w-full max-w-[40rem] max-sm:h-full min-h-[618.5px] md:mt-16 shadow-lg"
|
||||||
style={{
|
style={{
|
||||||
backgroundPosition:
|
backgroundPosition:
|
||||||
Math.random() * 100 + "px " + Math.random() * 100 + "px",
|
Math.random() * 100 + "px " + Math.random() * 100 + "px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="px-3 pt-4 pb-5 font-inter prose prose-zinc prose-invert">
|
<div
|
||||||
|
class="px-3 pt-4 pb-5 font-inter prose prose-zinc prose-invert h-full"
|
||||||
|
>
|
||||||
<h1
|
<h1
|
||||||
class="text-5xl font-bebas bold text-center mb-3 text-zinc-300"
|
class="text-5xl font-bebas bold text-center mb-3 text-zinc-300"
|
||||||
style={{ textShadow: "0 0 10px rgba(0,0,0,0.7)" }}
|
style={{ textShadow: "0 0 10px rgba(0,0,0,0.7)" }}
|
||||||
|
|||||||
Reference in New Issue
Block a user