mirror of
https://github.com/LCE-Hub/LCE-Emerald-Launcher.git
synced 2026-09-24 17:11:00 +00:00
feat(lceonline): GET, rewrite relay proxy
This commit is contained in:
@@ -41,7 +41,7 @@ const LceOnlineView = memo(function LceOnlineView({
|
||||
const [incomingReqs, setIncomingReqs] = useState<SocialEntry[]>([]);
|
||||
const [outgoingReqs, setOutgoingReqs] = useState<SocialEntry[]>([]);
|
||||
const invites = invitesProp ?? [];
|
||||
const [isHosting, setIsHosting] = useState(false);
|
||||
const [isHosting, setIsHosting] = useState(lceOnlineService.isHosting);
|
||||
const [isAddingFriend, setIsAddingFriend] = useState(false);
|
||||
const [addFriendUsername, setAddFriendUsername] = useState("");
|
||||
const addFriendInputRef = useRef<HTMLInputElement>(null);
|
||||
@@ -74,6 +74,7 @@ const LceOnlineView = memo(function LceOnlineView({
|
||||
useEffect(() => {
|
||||
return lceOnlineService.onSessionChange(() => {
|
||||
setIsSignedIn(lceOnlineService.signedIn);
|
||||
setIsHosting(lceOnlineService.isHosting);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -137,7 +138,7 @@ const LceOnlineView = memo(function LceOnlineView({
|
||||
const token = lceOnlineService.accessToken ?? "";
|
||||
if (!token) return;
|
||||
TauriService.startHostRelay(token, 25565).catch(() => {});
|
||||
setIsHosting(true);
|
||||
lceOnlineService.isHosting = true;
|
||||
} catch (e: unknown) {
|
||||
setErrorModal(e instanceof Error ? e.message : "Failed to start hosting");
|
||||
}
|
||||
@@ -150,7 +151,7 @@ const LceOnlineView = memo(function LceOnlineView({
|
||||
} catch (e: unknown) {
|
||||
console.warn("Stop hosting failed", e);
|
||||
}
|
||||
setIsHosting(false);
|
||||
lceOnlineService.isHosting = false;
|
||||
};
|
||||
|
||||
const handleAction = async (action: () => Promise<void>) => {
|
||||
|
||||
@@ -34,6 +34,7 @@ export class LceOnlineService {
|
||||
private _session: SessionData | null = null;
|
||||
private baseUrl: string = SOCIAL_BASE_URL;
|
||||
private _listeners: Array<() => void> = [];
|
||||
private _isHosting: boolean = false;
|
||||
constructor() {
|
||||
this.loadSession();
|
||||
}
|
||||
@@ -57,6 +58,15 @@ export class LceOnlineService {
|
||||
return this._session?.account || null;
|
||||
}
|
||||
|
||||
get isHosting(): boolean {
|
||||
return this._isHosting;
|
||||
}
|
||||
|
||||
set isHosting(value: boolean) {
|
||||
this._isHosting = value;
|
||||
this._notify();
|
||||
}
|
||||
|
||||
get displayUsername(): string {
|
||||
if (!this._session) return "Not signed in";
|
||||
return (
|
||||
@@ -220,49 +230,49 @@ export class LceOnlineService {
|
||||
}
|
||||
|
||||
async sendFriendRequest(target: string): Promise<void> {
|
||||
const res = await this.request<string>("POST", "/sendrequest", target);
|
||||
const res = await this.request<string>("GET", `/sendrequest?target=${encodeURIComponent(target)}`);
|
||||
if (typeof res === "string" && res !== "Successfully Sent Friend Request") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async acceptFriendRequest(from: string): Promise<void> {
|
||||
const res = await this.request<string>("POST", "/acceptrequest", from);
|
||||
const res = await this.request<string>("GET", `/acceptrequest?from=${encodeURIComponent(from)}`);
|
||||
if (typeof res === "string" && res !== "1") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async declineFriendRequest(from: string): Promise<void> {
|
||||
const res = await this.request<string>("POST", "/declinerequest", from);
|
||||
const res = await this.request<string>("GET", `/declinerequest?from=${encodeURIComponent(from)}`);
|
||||
if (typeof res === "string" && res !== "1") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async removeFriend(from: string): Promise<void> {
|
||||
const res = await this.request<string>("POST", "/removefriend", from);
|
||||
const res = await this.request<string>("GET", `/removefriend?from=${encodeURIComponent(from)}`);
|
||||
if (typeof res === "string") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async sendInvite(target: string): Promise<void> {
|
||||
const res = await this.request<string>("POST", "/invite", target);
|
||||
const res = await this.request<string>("GET", `/invite?target=${encodeURIComponent(target)}`);
|
||||
if (typeof res === "string" && res !== "Successfully Sent Invite") {
|
||||
throw new Error(res);
|
||||
}
|
||||
}
|
||||
|
||||
async acceptInvite(from: string): Promise<string> {
|
||||
const res = await this.request<string>("POST", "/acceptinvite", from);
|
||||
const res = await this.request<string>("GET", `/acceptinvite?from=${encodeURIComponent(from)}`);
|
||||
if (typeof res !== "string") throw new Error("Failed to accept invite");
|
||||
return res;
|
||||
}
|
||||
|
||||
async declineInvite(from: string): Promise<void> {
|
||||
try {
|
||||
await this.request("POST", "/declineinvite", from);
|
||||
await this.request("GET", `/declineinvite?from=${encodeURIComponent(from)}`);
|
||||
} catch (e: unknown) {
|
||||
const msg = e instanceof Error ? e.message : "";
|
||||
if (msg !== "Successfully Declined Invite") throw e;
|
||||
|
||||
Reference in New Issue
Block a user