Zod EVERYWHERE (#2027)
* Zod EVERYWHERE * Add no-unused-vars rule to eslint in front * Add no-unused-vars rule to eslint in pusher * Add no-unused-vars rule to eslint in back * Remove unused PlayerTexture guards * Fix data providing on room connection Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
This commit is contained in:
@@ -42,4 +42,4 @@ axiosWithRetry.interceptors.response.use((res) => {
|
||||
return res;
|
||||
});
|
||||
|
||||
const interceptorId = rax.attach(axiosWithRetry);
|
||||
rax.attach(axiosWithRetry);
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RoomConnection } from "./RoomConnection";
|
||||
import type { OnConnectInterface, PositionInterface, ViewportInterface } from "./ConnexionModels";
|
||||
import { GameConnexionTypes, urlManager } from "../Url/UrlManager";
|
||||
import { localUserStore } from "./LocalUserStore";
|
||||
import { CharacterTexture, LocalUser } from "./LocalUser";
|
||||
import { LocalUser } from "./LocalUser";
|
||||
import { Room } from "./Room";
|
||||
import { _ServiceWorker } from "../Network/ServiceWorker";
|
||||
import { loginSceneVisibleIframeStore } from "../Stores/LoginSceneStore";
|
||||
@@ -13,7 +13,6 @@ import { analyticsClient } from "../Administration/AnalyticsClient";
|
||||
import { axiosWithRetry } from "./AxiosUtils";
|
||||
import axios from "axios";
|
||||
import { isRegisterData } from "../Messages/JsonMessages/RegisterData";
|
||||
import { isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
import { limitMapStore } from "../Stores/GameStore";
|
||||
import { showLimitRoomModalStore } from "../Stores/ModalStore";
|
||||
import { gameManager } from "../Phaser/Game/GameManager";
|
||||
@@ -73,9 +72,7 @@ class ConnectionManager {
|
||||
|
||||
//Logout user in pusher and hydra
|
||||
const token = localUserStore.getAuthToken();
|
||||
const { authToken } = await Axios.get(`${PUSHER_URL}/logout-callback`, { params: { token } }).then(
|
||||
(res) => res.data
|
||||
);
|
||||
await Axios.get(`${PUSHER_URL}/logout-callback`, { params: { token } }).then((res) => res.data);
|
||||
localUserStore.setAuthToken(null);
|
||||
|
||||
//Go on login page can permit to clear token and start authentication process
|
||||
@@ -139,13 +136,19 @@ class ConnectionManager {
|
||||
//@deprecated
|
||||
else if (this.connexionType === GameConnexionTypes.register) {
|
||||
const organizationMemberToken = urlManager.getOrganizationToken();
|
||||
const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
|
||||
const result = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
|
||||
(res) => res.data
|
||||
);
|
||||
if (!isRegisterData(data)) {
|
||||
console.error("Invalid data received from /register route. Data: ", data);
|
||||
|
||||
const registerDataChecking = isRegisterData.safeParse(result);
|
||||
|
||||
if (!registerDataChecking.success) {
|
||||
console.error("Invalid data received from /register route. Data: ", result);
|
||||
throw new Error("Invalid data received from /register route.");
|
||||
}
|
||||
|
||||
const data = registerDataChecking.data;
|
||||
|
||||
this.localUser = new LocalUser(data.userUuid, data.email);
|
||||
this.authToken = data.authToken;
|
||||
localUserStore.saveUser(this.localUser);
|
||||
@@ -306,9 +309,9 @@ class ConnectionManager {
|
||||
connection.roomJoinedMessageStream.subscribe((connect: OnConnectInterface) => {
|
||||
resolve(connect);
|
||||
});
|
||||
}).catch((err) => {
|
||||
}).catch(() => {
|
||||
// Let's retry in 4-6 seconds
|
||||
return new Promise<OnConnectInterface>((resolve, reject) => {
|
||||
return new Promise<OnConnectInterface>((resolve) => {
|
||||
this.reconnectingTimeout = setTimeout(() => {
|
||||
//todo: allow a way to break recursion?
|
||||
//todo: find a way to avoid recursive function. Otherwise, the call stack will grow indefinitely.
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTe
|
||||
export interface PointInterface {
|
||||
x: number;
|
||||
y: number;
|
||||
direction: string; // TODO: modify this to the enum from ts-proto
|
||||
direction: "up" | "down" | "left" | "right"; // TODO: modify this to the enum from ts-proto
|
||||
moving: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import * as rax from "retry-axios";
|
||||
import Axios from "axios";
|
||||
import { CONTACT_URL, PUSHER_URL, DISABLE_ANONYMOUS, OPID_LOGIN_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
|
||||
import type { CharacterTexture } from "./LocalUser";
|
||||
import { localUserStore } from "./LocalUserStore";
|
||||
import axios from "axios";
|
||||
import { axiosWithRetry } from "./AxiosUtils";
|
||||
@@ -112,11 +109,14 @@ export class Room {
|
||||
data.authenticationMandatory = Boolean(data.authenticationMandatory);
|
||||
}
|
||||
|
||||
if (isRoomRedirect(data)) {
|
||||
const roomRedirectChecking = isRoomRedirect.safeParse(data);
|
||||
const mapDetailsDataChecking = isMapDetailsData.safeParse(data);
|
||||
|
||||
if (roomRedirectChecking.success) {
|
||||
return {
|
||||
redirectUrl: data.redirectUrl,
|
||||
};
|
||||
} else if (isMapDetailsData(data)) {
|
||||
} else if (mapDetailsDataChecking.success) {
|
||||
console.log("Map ", this.id, " resolves to URL ", data.mapUrl);
|
||||
this._mapUrl = data.mapUrl;
|
||||
this._group = data.group;
|
||||
@@ -132,6 +132,9 @@ export class Room {
|
||||
this._loginSceneLogo = data.loginSceneLogo ?? undefined;
|
||||
return new MapDetail(data.mapUrl);
|
||||
} else {
|
||||
console.log(data);
|
||||
console.error("roomRedirectChecking", roomRedirectChecking.error.issues);
|
||||
console.error("mapDetailsDataChecking", mapDetailsDataChecking.error.issues);
|
||||
throw new Error("Data received by the /map endpoint of the Pusher is not in a valid format.");
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -190,7 +190,7 @@ export class RoomConnection implements RoomConnection {
|
||||
|
||||
let interval: ReturnType<typeof setInterval> | undefined = undefined;
|
||||
|
||||
this.socket.onopen = (ev) => {
|
||||
this.socket.onopen = () => {
|
||||
//we manually ping every 20s to not be logged out by the server, even when the game is in background.
|
||||
const pingMessage = PingMessageTsProto.encode({}).finish();
|
||||
interval = setInterval(() => this.socket.send(pingMessage), manualPingDelay);
|
||||
@@ -297,6 +297,7 @@ export class RoomConnection implements RoomConnection {
|
||||
}
|
||||
default: {
|
||||
// Security check: if we forget a "case", the line below will catch the error at compile-time.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const tmp: never = subMessage;
|
||||
}
|
||||
}
|
||||
@@ -477,6 +478,7 @@ export class RoomConnection implements RoomConnection {
|
||||
}
|
||||
default: {
|
||||
// Security check: if we forget a "case", the line below will catch the error at compile-time.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const tmp: never = message;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user