Merge branch 'develop' of github.com:thecodingmachine/workadventure

This commit is contained in:
_Bastler
2021-12-16 18:41:44 +01:00
37 changed files with 1566 additions and 347 deletions
+15 -4
View File
@@ -12,6 +12,9 @@ import { userIsConnected } from "../Stores/MenuStore";
import { analyticsClient } from "../Administration/AnalyticsClient";
import { gameManager } from "../Phaser/Game/GameManager";
import { axiosWithRetry } from "./AxiosUtils";
import axios from "axios";
import { isRegisterData } from "../Messages/JsonMessages/RegisterData";
import { isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
class ConnectionManager {
private localUser!: LocalUser;
@@ -126,6 +129,10 @@ class ConnectionManager {
const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then(
(res) => res.data
);
if (!isRegisterData(data)) {
console.error("Invalid data received from /register route. Data: ", data);
throw new Error("Invalid data received from /register route.");
}
this.localUser = new LocalUser(data.userUuid, data.textures, data.email);
this.authToken = data.authToken;
localUserStore.saveUser(this.localUser);
@@ -193,11 +200,13 @@ class ConnectionManager {
analyticsClient.loggedWithSso();
} catch (err) {
console.error(err);
//if user must to be connect in current room or pusher error is not openid provier access error
//try to connected with function loadOpenIDScreen
// if the user must be connected in the current room or if the pusher error is not openid provider access error
// try to connect with function loadOpenIDScreen
if (
this._currentRoom.authenticationMandatory ||
(err.response?.data && err.response.data !== "User cannot to be connected on openid provier")
(axios.isAxiosError(err) &&
err.response?.data &&
err.response.data !== "User cannot to be connected on openid provider")
) {
this.loadOpenIDScreen();
return Promise.reject(new Error("You will be redirect on login page"));
@@ -324,7 +333,9 @@ class ConnectionManager {
}
const { authToken, userUuid, textures, email, username } = await Axios.get(`${PUSHER_URL}/login-callback`, {
params: { code, nonce, token, playUri: this.currentRoom?.key },
}).then((res) => res.data);
}).then((res) => {
return res.data;
});
localUserStore.setAuthToken(authToken);
this.localUser = new LocalUser(userUuid, textures, email);
localUserStore.saveUser(this.localUser);
+19 -10
View File
@@ -5,6 +5,8 @@ import type { CharacterTexture } from "./LocalUser";
import { localUserStore } from "./LocalUserStore";
import axios from "axios";
import { axiosWithRetry } from "./AxiosUtils";
import { isMapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
import { isRoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
export class MapDetail {
constructor(public readonly mapUrl: string, public readonly textures: CharacterTexture[] | undefined) {}
@@ -101,26 +103,33 @@ export class Room {
});
const data = result.data;
if (data.redirectUrl) {
if (isRoomRedirect(data.redirectUrl)) {
return {
redirectUrl: data.redirectUrl as string,
};
} else if (isMapDetailsData(data)) {
console.log("Map ", this.id, " resolves to URL ", data.mapUrl);
this._mapUrl = data.mapUrl;
this._textures = data.textures;
this._group = data.group;
this._authenticationMandatory =
data.authenticationMandatory != null ? data.authenticationMandatory : DISABLE_ANONYMOUS;
this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER;
this._contactPage = data.contactPage || CONTACT_URL;
return new MapDetail(data.mapUrl, data.textures);
} else {
throw new Error("Data received by the /map endpoint of the Pusher is not in a valid format.");
}
console.log("Map ", this.id, " resolves to URL ", data.mapUrl);
this._mapUrl = data.mapUrl;
this._textures = data.textures;
this._group = data.group;
this._authenticationMandatory = data.authenticationMandatory || DISABLE_ANONYMOUS;
this._iframeAuthentication = data.iframeAuthentication || OPID_LOGIN_SCREEN_PROVIDER;
this._contactPage = data.contactPage || CONTACT_URL;
return new MapDetail(data.mapUrl, data.textures);
} catch (e) {
if (axios.isAxiosError(e) && e.response?.status == 401 && e.response?.data === "Token decrypted error") {
console.warn("JWT token sent could not be decrypted. Maybe it expired?");
localUserStore.setAuthToken(null);
window.location.assign("/login");
} else {
} else if (axios.isAxiosError(e)) {
console.error("Error => getMapDetail", e, e.response);
} else {
console.error("Error => getMapDetail", e);
}
throw e;
}
@@ -0,0 +1,2 @@
*
!.gitignore
@@ -1,8 +1,8 @@
import type { Direction } from "../../types";
import type { GameScene } from "../Game/GameScene";
import { touchScreenManager } from "../../Touch/TouchScreenManager";
import { MobileJoystick } from "../Components/MobileJoystick";
import { enableUserInputsStore } from "../../Stores/UserInputStore";
import type { Direction } from "phaser3-rex-plugins/plugins/virtualjoystick.js";
interface UserInputManagerDatum {
keyInstance: Phaser.Input.Keyboard.Key;
+2 -2
View File
@@ -426,7 +426,7 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
// TODO: does it make sense to pop this error when retrying?
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
// Let's try without video constraints
if (constraints.video !== false) {
@@ -444,7 +444,7 @@ export const localStreamStore = derived<Readable<MediaStreamConstraints>, LocalS
console.info("Error. Unable to get microphone and/or camera access.", constraints, e);
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
}
}
+1 -1
View File
@@ -153,7 +153,7 @@ export const screenSharingLocalStreamStore = derived<Readable<MediaStreamConstra
console.info("Error. Unable to share screen.", e);
set({
type: "error",
error: e,
error: e instanceof Error ? e : new Error("An unknown error happened"),
});
}
})();
+1 -1
View File
@@ -7,7 +7,7 @@ class TouchScreenManager {
//found here: https://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript#4819886
detectTouchscreen(): boolean {
return "ontouchstart" in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
}
}
+35 -2
View File
@@ -1,6 +1,39 @@
//import Phaser from "phaser";
declare module "phaser3-rex-plugins/plugins/virtualjoystick.js" {
const content: any; // eslint-disable-line
export default content;
/*const content: any; // eslint-disable-line
export default content;*/
import GameObject = Phaser.GameObjects.GameObject;
import { Scene } from "phaser";
type CursorKey = {
isDown: boolean;
};
export type Direction = "left" | "right" | "up" | "down";
interface CursorKeys extends Record<Direction, CursorKey> {
left: CursorKey;
right: CursorKey;
up: CursorKey;
down: CursorKey;
}
class VirtualJoystick extends GameObject {
constructor(scene: Scene, config: unknown);
enable: boolean;
base: GameObjects.Image;
thumb: GameObjects.Image;
setRadius: (radius: number) => void;
y: number;
x: number;
forceX: number;
forceY: number;
visible: boolean;
createCursorKeys: () => CursorKeys;
}
export default VirtualJoystick;
}
declare module "phaser3-rex-plugins/plugins/gestures-plugin.js" {
const content: any; // eslint-disable-line
-24
View File
@@ -1,27 +1,3 @@
import type Phaser from "phaser";
export type CursorKey = {
isDown: boolean;
};
export type Direction = "left" | "right" | "up" | "down";
export interface CursorKeys extends Record<Direction, CursorKey> {
left: CursorKey;
right: CursorKey;
up: CursorKey;
down: CursorKey;
}
export interface IVirtualJoystick extends Phaser.GameObjects.GameObject {
y: number;
x: number;
forceX: number;
forceY: number;
visible: boolean;
createCursorKeys: () => CursorKeys;
}
export enum Easing {
Linear = "Linear",
QuadEaseIn = "Quad.easeIn",