Start working on new server page #202
This commit is contained in:
5 files changed
+161
-107
No files matched your search
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="app-loading">
|
<div class="app-loading">
|
||||||
<img src="./public/assetsStatic/LogoBig.svg" class="app-loading-logo" />
|
<img src="./assetsStatic/LogoBig.svg" class="app-loading-logo" />
|
||||||
</div>
|
</div>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
<svg style="width:0;height:0;position:absolute;" aria-hidden="true" focusable="false">
|
<svg style="width:0;height:0;position:absolute;" aria-hidden="true" focusable="false">
|
||||||
|
|||||||
+5
-11
@@ -98,6 +98,7 @@ import PlaylistTitlePage from "./routes/playlist/index.jsx";
|
|||||||
// Initial custom axios client to use tauri's http module
|
// Initial custom axios client to use tauri's http module
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
|
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
|
||||||
|
import { useApi } from "./utils/store/api.js";
|
||||||
|
|
||||||
export const axiosClient = axios.create({
|
export const axiosClient = axios.create({
|
||||||
adapter: axiosTauriApiAdapter,
|
adapter: axiosTauriApiAdapter,
|
||||||
@@ -170,12 +171,6 @@ const AnimationWrapper = () => {
|
|||||||
function App() {
|
function App() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
document
|
|
||||||
.querySelector(".app-loading")
|
|
||||||
.setAttribute("style", "display:none");
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const [serverReachable, setServerReachable] = useState(true);
|
const [serverReachable, setServerReachable] = useState(true);
|
||||||
|
|
||||||
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
|
const [playbackDataLoading] = usePlaybackDataLoadStore((state) => [
|
||||||
@@ -486,6 +481,10 @@ function App() {
|
|||||||
path="/"
|
path="/"
|
||||||
element={<LogicalRoutes />}
|
element={<LogicalRoutes />}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="/login"
|
||||||
|
element={<LoginLogicalRoutes />}
|
||||||
|
/>
|
||||||
|
|
||||||
<Route path="/home" element={<Home />} />
|
<Route path="/home" element={<Home />} />
|
||||||
<Route
|
<Route
|
||||||
@@ -569,11 +568,6 @@ function App() {
|
|||||||
path="/player"
|
path="/player"
|
||||||
element={<VideoPlayer />}
|
element={<VideoPlayer />}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
|
||||||
path="/login"
|
|
||||||
element={<LoginLogicalRoutes />}
|
|
||||||
/>
|
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+3
-3
@@ -5,8 +5,6 @@ import ReactDOM from "react-dom/client";
|
|||||||
|
|
||||||
import { BrowserRouter as Router } from "react-router-dom";
|
import { BrowserRouter as Router } from "react-router-dom";
|
||||||
|
|
||||||
import { invoke } from "@tauri-apps/api/tauri";
|
|
||||||
|
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
|
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
@@ -37,5 +35,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
// This will wait for the window to load, but you could
|
// This will wait for the window to load, but you could
|
||||||
// run this function on whatever trigger you want
|
// run this function on whatever trigger you want
|
||||||
console.info("Initial render complete");
|
console.info("Initial render complete");
|
||||||
invoke("close_splashscreen");
|
document
|
||||||
|
.querySelector(".app-loading")
|
||||||
|
.setAttribute("style", "display:none");
|
||||||
});
|
});
|
||||||
@@ -15,6 +15,7 @@ import Grid from "@mui/material/Grid";
|
|||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import SvgIcon from "@mui/material/SvgIcon";
|
import SvgIcon from "@mui/material/SvgIcon";
|
||||||
import Container from "@mui/material/Container";
|
import Container from "@mui/material/Container";
|
||||||
|
import LinearProgress from "@mui/material/LinearProgress";
|
||||||
|
|
||||||
import { mdiChevronRight } from "@mdi/js";
|
import { mdiChevronRight } from "@mdi/js";
|
||||||
|
|
||||||
@@ -30,9 +31,13 @@ import { v4 as uuidv4 } from "uuid";
|
|||||||
|
|
||||||
// SCSS
|
// SCSS
|
||||||
import "./server.module.scss";
|
import "./server.module.scss";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { axiosClient } from "../../../App.jsx";
|
import { axiosClient } from "../../../App.jsx";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { useApi } from "../../../utils/store/api.js";
|
||||||
|
import { RecommendedServerDiscovery } from "@jellyfin/sdk/lib/discovery/recommended-server-discovery.js";
|
||||||
|
import { MdiInformation } from "../../../components/icons/mdiInformation.jsx";
|
||||||
|
import { yellow } from "@mui/material/colors";
|
||||||
|
|
||||||
export const ServerList = () => {
|
export const ServerList = () => {
|
||||||
const [renderServerList, setRenderServerList] = useState(false);
|
const [renderServerList, setRenderServerList] = useState(false);
|
||||||
@@ -62,7 +67,7 @@ export const ServerList = () => {
|
|||||||
// localStorage.setItem("servers", serverList);
|
// localStorage.setItem("servers", serverList);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ServerList = (props) => {
|
const ServerLists = (props) => {
|
||||||
const startRender = props.startRender;
|
const startRender = props.startRender;
|
||||||
if (startRender) {
|
if (startRender) {
|
||||||
return serverList.map((item, index) => {
|
return serverList.map((item, index) => {
|
||||||
@@ -128,106 +133,79 @@ export const ServerList = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ServerSetup = (props) => {
|
export const ServerSetup = () => {
|
||||||
const sdk = new Jellyfin({
|
/**
|
||||||
clientInfo: {
|
* @type {[import("@jellyfin/sdk").Api, function, Jellyfin]}
|
||||||
name: "JellyPlayer",
|
*/
|
||||||
version: appVer,
|
const [api, createApi, jellyfin] = useApi((state) => [
|
||||||
},
|
state.api,
|
||||||
deviceInfo: {
|
state.createApi,
|
||||||
name: "JellyPlayer",
|
state.jellyfin,
|
||||||
id: uuidv4(),
|
]);
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [serverIp, setServerIp] = useState("");
|
const [serverIp, setServerIp] = useState("");
|
||||||
const [checkingServer, setServerCheckState] = useState(false);
|
|
||||||
|
|
||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const checkServer = useMutation({
|
||||||
|
mutationFn: async () => {
|
||||||
const usersAvailable = async () => {};
|
const servers =
|
||||||
const addServer = async () => {
|
await jellyfin.discovery.getRecommendedServerCandidates(
|
||||||
event.emit("create-jellyfin-api", serverIp);
|
serverIp,
|
||||||
let sysInfo = await getSystemApi(window.api).getPublicSystemInfo();
|
);
|
||||||
sysInfo = sysInfo.data;
|
const bestServer = jellyfin.discovery.findBestServer(servers);
|
||||||
|
return bestServer;
|
||||||
// Set Server Config to Tauri store
|
},
|
||||||
sysInfo.Ip = serverIp;
|
onSuccess: (bestServer) => {
|
||||||
setServer(sysInfo);
|
if (bestServer) {
|
||||||
};
|
console.info(bestServer);
|
||||||
const checkServer = async () => {
|
enqueueSnackbar("Client added successfully", {
|
||||||
setServerCheckState(true);
|
variant: "success",
|
||||||
try {
|
});
|
||||||
const result = await axiosClient.get(`${serverIp}/System/Ping`);
|
createApi(bestServer.address, null);
|
||||||
if (result.data == "Jellyfin Server") {
|
navigate("/login");
|
||||||
event.emit("create-jellyfin-api", serverIp);
|
}
|
||||||
let sysInfo = await getSystemApi(
|
},
|
||||||
window.api,
|
onError: (err) => {
|
||||||
).getPublicSystemInfo();
|
console.error(err);
|
||||||
sysInfo = sysInfo.data;
|
enqueueSnackbar(`${err}`, { variant: "error" });
|
||||||
sysInfo.Ip = serverIp;
|
enqueueSnackbar("Something went wrong", { variant: "error" });
|
||||||
setServer(sysInfo);
|
},
|
||||||
const users = await getUserApi(window.api).getPublicUsers();
|
onSettled: (bestServer) => {
|
||||||
if (users.data.length >= 1) {
|
console.log(bestServer);
|
||||||
navigate("/login/users");
|
if (!bestServer) {
|
||||||
} else {
|
|
||||||
navigate("/login/manual");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
enqueueSnackbar(
|
enqueueSnackbar(
|
||||||
"The provided ip address doesn't seem point to a Jellyfin server.",
|
`Provided server address is not a Jellyfin server.`,
|
||||||
{ variant: "error" },
|
{
|
||||||
|
variant: "error",
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
},
|
||||||
console.log(error);
|
});
|
||||||
enqueueSnackbar("Unable to verfiy server address.", {
|
|
||||||
variant: "error",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setServerCheckState(false);
|
|
||||||
return "";
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAddServer = () => {
|
|
||||||
// setLoading(true);
|
|
||||||
// let data;
|
|
||||||
// fetch(`${serverIp}/System/Ping`, {
|
|
||||||
// body: JSON.stringify(data),
|
|
||||||
// })
|
|
||||||
// .then((res) => res.json())
|
|
||||||
// .then((data) => {
|
|
||||||
// if (data == "Jellyfin Server") {
|
|
||||||
// addServer();
|
|
||||||
// setLoading(false);
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// enqueueSnackbar(
|
|
||||||
// "The server address does not seem be a jellyfin server",
|
|
||||||
// { variant: "error" },
|
|
||||||
// );
|
|
||||||
// setLoading(false);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch((error) => {
|
|
||||||
// setLoading(false);
|
|
||||||
// enqueueSnackbar(
|
|
||||||
// "Unable to verify whether the give address is a valid Jellyfin server",
|
|
||||||
// { variant: "error" },
|
|
||||||
// );
|
|
||||||
// console.error(error);
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Container maxWidth="sm" className={"centered serverContainer"}>
|
<LinearProgress
|
||||||
|
sx={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
opacity: checkServer.isLoading ? 1 : 0,
|
||||||
|
transition: "opacity 350ms",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Container
|
||||||
|
maxWidth="sm"
|
||||||
|
className={"centered serverContainer"}
|
||||||
|
style={{
|
||||||
|
opacity: checkServer.isLoading ? "0.5" : "1",
|
||||||
|
transition: "opacity 350ms",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
spacing={2}
|
spacing={2}
|
||||||
@@ -247,7 +225,6 @@ export const ServerSetup = (props) => {
|
|||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setServerIp(event.target.value);
|
setServerIp(event.target.value);
|
||||||
}}
|
}}
|
||||||
helperText="Add your server adddress with https:// or http://. Eg: https://demo.jellyfin.org"
|
|
||||||
></TextField>
|
></TextField>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xl={5} md={6} sx={{ width: "100%" }}>
|
<Grid item xl={5} md={6} sx={{ width: "100%" }}>
|
||||||
@@ -255,18 +232,39 @@ export const ServerSetup = (props) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{ width: "100%" }}
|
sx={{ width: "100%" }}
|
||||||
size="large"
|
size="large"
|
||||||
loading={checkingServer}
|
loading={checkServer.isLoading}
|
||||||
endIcon={
|
endIcon={
|
||||||
<SvgIcon>
|
<SvgIcon>
|
||||||
<path d={mdiChevronRight}></path>
|
<path d={mdiChevronRight}></path>
|
||||||
</SvgIcon>
|
</SvgIcon>
|
||||||
}
|
}
|
||||||
loadingPosition="end"
|
loadingPosition="end"
|
||||||
onClick={() => checkServer()}
|
onClick={checkServer.mutate}
|
||||||
>
|
>
|
||||||
Add Server
|
Add Server
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xl={5}
|
||||||
|
md={6}
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 1,
|
||||||
|
opacity: 0.6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MdiInformation
|
||||||
|
sx={{
|
||||||
|
color: yellow[700],
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography variant="subtitle1">
|
||||||
|
Example: https://demo.jellyfin.org/stable
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Container>
|
</Container>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/** @format */
|
||||||
|
import { create } from "zustand";
|
||||||
|
import { Api, Jellyfin } from "@jellyfin/sdk";
|
||||||
|
import { version as appVer } from "../../../package.json";
|
||||||
|
|
||||||
|
// Initial custom axios client to use tauri's http module
|
||||||
|
import axios from "axios";
|
||||||
|
import axiosTauriApiAdapter from "axios-tauri-api-adapter";
|
||||||
|
import { v4 as uuidv4 } from "uuid";
|
||||||
|
|
||||||
|
export const axiosClient = axios.create({
|
||||||
|
adapter: axiosTauriApiAdapter,
|
||||||
|
headers: { "Access-Control-Allow-Origin": "*" },
|
||||||
|
timeout: 60000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const deviceId = localStorage.getItem("deviceId");
|
||||||
|
|
||||||
|
if (!deviceId) {
|
||||||
|
localStorage.setItem("deviceId", uuidv4());
|
||||||
|
}
|
||||||
|
|
||||||
|
// event.on("create-jellyfin-api", (serverAddress) => {
|
||||||
|
// window.api = ;
|
||||||
|
// // window.api = jellyfin.createApi(serverAddress);
|
||||||
|
// });
|
||||||
|
// event.on("set-api-accessToken", (serverAddress) => {
|
||||||
|
// window.api = jellyfin.createApi(
|
||||||
|
// serverAddress,
|
||||||
|
// sessionStorage.getItem("accessToken"),
|
||||||
|
// axiosClient,
|
||||||
|
// );
|
||||||
|
// // });
|
||||||
|
|
||||||
|
const jellyfin = new Jellyfin({
|
||||||
|
clientInfo: {
|
||||||
|
name: "JellyPlayer",
|
||||||
|
version: appVer,
|
||||||
|
},
|
||||||
|
deviceInfo: {
|
||||||
|
name: "JellyPlayer",
|
||||||
|
id: deviceId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import("@jellyfin/sdk").Api} Api
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const useApi = create((set) => ({
|
||||||
|
/**
|
||||||
|
* @type {Api}
|
||||||
|
*/
|
||||||
|
api: null,
|
||||||
|
deviceId: localStorage.getItem("deviceId"),
|
||||||
|
jellyfin: jellyfin,
|
||||||
|
createApi: (serverAddress, accessToken) =>
|
||||||
|
set((state) => ({
|
||||||
|
...state,
|
||||||
|
api: jellyfin.createApi(serverAddress, accessToken, axiosClient),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
Reference in new issue
Block a user