MISC: Allow using wss for RFA (#1942)

This commit is contained in:
catloversg
2025-02-01 02:07:38 +07:00
committed by GitHub
parent 40c696feb1
commit 822c55574d
3 changed files with 12 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import { GameOptionsPage } from "./GameOptionsPage";
import { isValidConnectionHostname, isValidConnectionPort, Settings } from "../../Settings/Settings";
import { ConnectionBauble } from "./ConnectionBauble";
import { isRemoteFileApiConnectionLive, newRemoteFileApiConnection } from "../../RemoteFileAPI/RemoteFileAPI";
import { OptionSwitch } from "../../ui/React/OptionSwitch";
export const RemoteAPIPage = (): React.ReactElement => {
const [remoteFileApiHostname, setRemoteFileApiHostname] = useState(Settings.RemoteFileApiAddress);
@@ -106,6 +107,12 @@ export const RemoteAPIPage = (): React.ReactElement => {
{portError && <Typography color={Settings.theme.error}>{portError}</Typography>}
</div>
</Tooltip>
<OptionSwitch
checked={Settings.UseWssForRemoteFileApi}
onChange={(newValue) => (Settings.UseWssForRemoteFileApi = newValue)}
text="Use wss"
tooltip={<>Use wss instead of ws when connecting to RFA clients.</>}
/>
<Button disabled={!isValidHostname || !isValidPort} onClick={newRemoteFileApiConnection}>
Connect
</Button>

View File

@@ -2,6 +2,7 @@ import { RFAMessage } from "./MessageDefinitions";
import { RFARequestHandler } from "./MessageHandlers";
import { SnackbarEvents } from "../ui/React/Snackbar";
import { ToastVariant } from "@enums";
import { Settings } from "../Settings/Settings";
function showErrorMessage(address: string, detail: string) {
SnackbarEvents.emit(`Error with websocket ${address}, details: ${detail}`, ToastVariant.ERROR, 5000);
@@ -9,7 +10,6 @@ function showErrorMessage(address: string, detail: string) {
export class Remote {
connection?: WebSocket;
static protocol = "ws";
ipaddr: string;
port: number;
@@ -23,7 +23,7 @@ export class Remote {
}
public startConnection(): void {
const address = Remote.protocol + "://" + this.ipaddr + ":" + this.port;
const address = (Settings.UseWssForRemoteFileApi ? "wss" : "ws") + "://" + this.ipaddr + ":" + this.port;
try {
this.connection = new WebSocket(address);
} catch (error) {

View File

@@ -113,6 +113,8 @@ export const Settings = {
RemoteFileApiAddress: "localhost",
/** Port the Remote File API client will try to connect to. 0 to disable. */
RemoteFileApiPort: 0,
/** Use wss instead of ws when connecting to RFA clients */
UseWssForRemoteFileApi: false,
/** Whether to save the game when the player saves any file. */
SaveGameOnFileSave: true,
/** Whether to hide the confirmation dialog for augmentation purchases. */
@@ -179,7 +181,7 @@ export const Settings = {
hideTrailingDecimalZeros: false,
/** Whether to hide thousands separators. */
hideThousandsSeparator: false,
/** Whether to use engineering notation instead of scientific for exponentials. */
/** Whether to use engineering notation instead of scientific for exponential form. */
useEngineeringNotation: false,
/** Whether to disable suffixes and always use exponential form (scientific or engineering). */
disableSuffixes: false,