mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-04-06 02:01:58 +02:00
Merge pull request #552 from SlimeVR/315-gui-show-ip-address
Add server infos request. And show local ip address inside gui settings
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { appWindow } from '@tauri-apps/api/window';
|
||||
import { ReactNode } from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { ReactNode, useEffect, useLayoutEffect, useState } from 'react';
|
||||
import { NavLink, useMatch } from 'react-router-dom';
|
||||
import {
|
||||
RpcMessage,
|
||||
ServerInfosRequestT,
|
||||
ServerInfosResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from '../hooks/websocket-api';
|
||||
import { CloseIcon } from './commons/icon/CloseIcon';
|
||||
import { MaximiseIcon } from './commons/icon/MaximiseIcon';
|
||||
import { MinimiseIcon } from './commons/icon/MinimiseIcon';
|
||||
@@ -14,13 +20,30 @@ export function TopBar({
|
||||
children?: ReactNode;
|
||||
progress?: number;
|
||||
}) {
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
const [localIp, setLocalIp] = useState<string | null>(null);
|
||||
const doesMatchSettings = useMatch({
|
||||
path: '/settings/*',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.ServerInfosRequest, new ServerInfosRequestT());
|
||||
}, []);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.ServerInfosResponse,
|
||||
({ localIp }: ServerInfosResponseT) => {
|
||||
if (localIp) setLocalIp(localIp.toString());
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<div data-tauri-drag-region className="flex gap-2 h-[38px] z-50">
|
||||
<div
|
||||
className="flex px-2 pb-1 mt-3 justify-around z-50"
|
||||
data-tauri-drag-region
|
||||
>
|
||||
<div className="flex gap-1" data-tauri-drag-region>
|
||||
<div className="flex gap-2" data-tauri-drag-region>
|
||||
<NavLink
|
||||
to="/"
|
||||
className="flex justify-around flex-col select-all"
|
||||
@@ -31,13 +54,15 @@ export function TopBar({
|
||||
<div className="flex justify-around flex-col" data-tauri-drag-region>
|
||||
<Typography>SlimeVR</Typography>
|
||||
</div>
|
||||
<div
|
||||
className="mx-2 flex justify-around flex-col text-standard-bold text-status-success bg-status-success bg-opacity-20 rounded-lg px-3"
|
||||
data-tauri-drag-region
|
||||
>
|
||||
<div className="flex justify-around flex-col text-standard-bold text-status-success bg-status-success bg-opacity-20 rounded-lg px-3 select-text">
|
||||
{(__VERSION_TAG__ || __COMMIT_HASH__) +
|
||||
(__GIT_CLEAN__ ? '' : '-dirty')}
|
||||
</div>
|
||||
{doesMatchSettings && (
|
||||
<div className="flex justify-around flex-col text-standard-bold text-status-special bg-status-special bg-opacity-20 rounded-lg px-3 select-text">
|
||||
{localIp || 'unknown local ip'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -21,6 +21,8 @@ import solarxr_protocol.MessageBundle;
|
||||
import solarxr_protocol.datatypes.TransactionId;
|
||||
import solarxr_protocol.rpc.*;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -68,9 +70,29 @@ public class RPCHandler extends ProtocolHandler<RpcMessageHeader>
|
||||
this::onOverlayDisplayModeRequest
|
||||
);
|
||||
|
||||
registerPacketListener(RpcMessage.ServerInfosRequest, this::onServerInfosRequest);
|
||||
|
||||
this.api.server.getAutoBoneHandler().addListener(this);
|
||||
}
|
||||
|
||||
private void onServerInfosRequest(
|
||||
GenericConnection conn,
|
||||
RpcMessageHeader messageHeader
|
||||
) {
|
||||
FlatBufferBuilder fbb = new FlatBufferBuilder(32);
|
||||
|
||||
try {
|
||||
String localIp = InetAddress.getLocalHost().getHostAddress();
|
||||
int response = ServerInfosResponse
|
||||
.createServerInfosResponse(fbb, fbb.createString(localIp));
|
||||
int outbound = this.createRPCMessage(fbb, RpcMessage.ServerInfosResponse, response);
|
||||
fbb.finish(outbound);
|
||||
conn.send(fbb.dataBuffer());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void onOverlayDisplayModeRequest(
|
||||
GenericConnection conn,
|
||||
RpcMessageHeader messageHeader
|
||||
|
||||
Submodule solarxr-protocol updated: ecf32d93da...60059ccc2e
Reference in New Issue
Block a user