Making a round of improvement to log messages
Also, bootstraping a new LocalAdmin service to mock the AdminApi in the pusher
This commit is contained in:
parent
7968c4ad7b
commit
952a5bd87c
@ -6,6 +6,7 @@ import { parse } from "query-string";
|
|||||||
import { openIDClient } from "../Services/OpenIDClient";
|
import { openIDClient } from "../Services/OpenIDClient";
|
||||||
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
import { DISABLE_ANONYMOUS } from "../Enum/EnvironmentVariable";
|
||||||
import { RegisterData } from "../Messages/JsonMessages/RegisterData";
|
import { RegisterData } from "../Messages/JsonMessages/RegisterData";
|
||||||
|
import { adminService } from "../Services/AdminService";
|
||||||
|
|
||||||
export interface TokenInterface {
|
export interface TokenInterface {
|
||||||
userUuid: string;
|
userUuid: string;
|
||||||
@ -166,10 +167,11 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
|
|
||||||
//Get user data from Admin Back Office
|
//Get user data from Admin Back Office
|
||||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||||
const resUserData = await this.getUserByUserIdentifier(
|
const resUserData = await adminService.fetchMemberDataByUuid(
|
||||||
authTokenData.identifier,
|
authTokenData.identifier,
|
||||||
playUri as string,
|
playUri as string,
|
||||||
IPAddress
|
IPAddress,
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (authTokenData.accessToken == undefined) {
|
if (authTokenData.accessToken == undefined) {
|
||||||
@ -221,7 +223,7 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
|
|
||||||
//Get user data from Admin Back Office
|
//Get user data from Admin Back Office
|
||||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||||
const data = await this.getUserByUserIdentifier(email, playUri as string, IPAddress);
|
const data = await adminService.fetchMemberDataByUuid(email, playUri as string, IPAddress, []);
|
||||||
|
|
||||||
return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
|
return res.json({ ...data, authToken, username: userInfo?.username, locale: userInfo?.locale });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -430,34 +432,4 @@ export class AuthenticateController extends BaseHttpController {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param email
|
|
||||||
* @param playUri
|
|
||||||
* @param IPAddress
|
|
||||||
* @return FetchMemberDataByUuidResponse|object
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
private async getUserByUserIdentifier(
|
|
||||||
email: string,
|
|
||||||
playUri: string,
|
|
||||||
IPAddress: string
|
|
||||||
): Promise<FetchMemberDataByUuidResponse | object> {
|
|
||||||
let data: FetchMemberDataByUuidResponse = {
|
|
||||||
email: email,
|
|
||||||
userUuid: email,
|
|
||||||
tags: [],
|
|
||||||
messages: [],
|
|
||||||
visitCardUrl: null,
|
|
||||||
textures: [],
|
|
||||||
userRoomToken: undefined,
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
data = await adminApi.fetchMemberDataByUuid(email, playUri, IPAddress, []);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("openIDCallback => fetchMemberDataByUuid", err);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { ADMIN_API_TOKEN, ADMIN_API_URL, ADMIN_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_TOKEN, ADMIN_API_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
|
||||||
import Axios, { AxiosResponse } from "axios";
|
import Axios, { AxiosResponse } from "axios";
|
||||||
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
import { isMapDetailsData, MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||||
import { isRoomRedirect, RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
import { isRoomRedirect, RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||||
import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||||
import * as tg from "generic-type-guard";
|
import * as tg from "generic-type-guard";
|
||||||
import { isNumber } from "generic-type-guard";
|
|
||||||
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
import { isWokaDetail } from "../Messages/JsonMessages/PlayerTextures";
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
|
import { AdminInterface } from "./AdminInterface";
|
||||||
|
|
||||||
export interface AdminBannedData {
|
export interface AdminBannedData {
|
||||||
is_banned: boolean;
|
is_banned: boolean;
|
||||||
@ -30,7 +30,7 @@ const isFetchMemberDataByUuidResponse = new tg.IsInterface()
|
|||||||
|
|
||||||
export type FetchMemberDataByUuidResponse = tg.GuardedType<typeof isFetchMemberDataByUuidResponse>;
|
export type FetchMemberDataByUuidResponse = tg.GuardedType<typeof isFetchMemberDataByUuidResponse>;
|
||||||
|
|
||||||
class AdminApi {
|
class AdminApi implements AdminInterface {
|
||||||
/**
|
/**
|
||||||
* @var playUri: is url of the room
|
* @var playUri: is url of the room
|
||||||
* @var userId: can to be undefined or email or uuid
|
* @var userId: can to be undefined or email or uuid
|
||||||
@ -60,7 +60,7 @@ class AdminApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchMemberDataByUuid(
|
async fetchMemberDataByUuid(
|
||||||
userIdentifier: string | null,
|
userIdentifier: string,
|
||||||
playUri: string,
|
playUri: string,
|
||||||
ipAddress: string,
|
ipAddress: string,
|
||||||
characterLayers: string[]
|
characterLayers: string[]
|
||||||
|
10
pusher/src/Services/AdminInterface.ts
Normal file
10
pusher/src/Services/AdminInterface.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||||
|
|
||||||
|
export interface AdminInterface {
|
||||||
|
fetchMemberDataByUuid(
|
||||||
|
userIdentifier: string,
|
||||||
|
playUri: string,
|
||||||
|
ipAddress: string,
|
||||||
|
characterLayers: string[]
|
||||||
|
): Promise<FetchMemberDataByUuidResponse>;
|
||||||
|
}
|
5
pusher/src/Services/AdminService.ts
Normal file
5
pusher/src/Services/AdminService.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
|
||||||
|
import { adminApi } from "./AdminApi";
|
||||||
|
import { localAdmin } from "./LocalAdmin";
|
||||||
|
|
||||||
|
export const adminService = ADMIN_API_URL ? adminApi : localAdmin;
|
26
pusher/src/Services/LocalAdmin.ts
Normal file
26
pusher/src/Services/LocalAdmin.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { FetchMemberDataByUuidResponse } from "./AdminApi";
|
||||||
|
import { AdminInterface } from "./AdminInterface";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A local class mocking a real admin if no admin is configured.
|
||||||
|
*/
|
||||||
|
class LocalAdmin implements AdminInterface {
|
||||||
|
fetchMemberDataByUuid(
|
||||||
|
userIdentifier: string,
|
||||||
|
playUri: string,
|
||||||
|
ipAddress: string,
|
||||||
|
characterLayers: string[]
|
||||||
|
): Promise<FetchMemberDataByUuidResponse> {
|
||||||
|
return Promise.resolve({
|
||||||
|
email: userIdentifier,
|
||||||
|
userUuid: userIdentifier,
|
||||||
|
tags: [],
|
||||||
|
messages: [],
|
||||||
|
visitCardUrl: null,
|
||||||
|
textures: [],
|
||||||
|
userRoomToken: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const localAdmin = new LocalAdmin();
|
@ -123,7 +123,13 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("end", () => {
|
.on("end", () => {
|
||||||
console.warn("Admin connection lost to back server");
|
console.warn(
|
||||||
|
"Admin connection lost to back server '" +
|
||||||
|
apiClient.getChannel().getTarget() +
|
||||||
|
"' for room '" +
|
||||||
|
roomId +
|
||||||
|
"'"
|
||||||
|
);
|
||||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||||
if (!client.disconnecting) {
|
if (!client.disconnecting) {
|
||||||
this.closeWebsocketConnection(client, 1011, "Admin Connection lost to back server");
|
this.closeWebsocketConnection(client, 1011, "Admin Connection lost to back server");
|
||||||
@ -131,7 +137,14 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
console.log("A user left");
|
console.log("A user left");
|
||||||
})
|
})
|
||||||
.on("error", (err: Error) => {
|
.on("error", (err: Error) => {
|
||||||
console.error("Error in connection to back server:", err);
|
console.error(
|
||||||
|
"Error in connection to back server '" +
|
||||||
|
apiClient.getChannel().getTarget() +
|
||||||
|
"' for room '" +
|
||||||
|
roomId +
|
||||||
|
"':",
|
||||||
|
err
|
||||||
|
);
|
||||||
if (!client.disconnecting) {
|
if (!client.disconnecting) {
|
||||||
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
||||||
}
|
}
|
||||||
@ -188,7 +201,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
joinRoomMessage.addCharacterlayer(characterLayerMessage);
|
joinRoomMessage.addCharacterlayer(characterLayerMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Calling joinRoom");
|
console.log("Calling joinRoom '" + client.roomId + "'");
|
||||||
const apiClient = await apiClientRepository.getClient(client.roomId);
|
const apiClient = await apiClientRepository.getClient(client.roomId);
|
||||||
const streamToPusher = apiClient.joinRoom();
|
const streamToPusher = apiClient.joinRoom();
|
||||||
clientEventsEmitter.emitClientJoin(client.userUuid, client.roomId);
|
clientEventsEmitter.emitClientJoin(client.userUuid, client.roomId);
|
||||||
@ -216,7 +229,13 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("end", () => {
|
.on("end", () => {
|
||||||
console.warn("Connection lost to back server");
|
console.warn(
|
||||||
|
"Connection lost to back server '" +
|
||||||
|
apiClient.getChannel().getTarget() +
|
||||||
|
"' for room '" +
|
||||||
|
client.roomId +
|
||||||
|
"'"
|
||||||
|
);
|
||||||
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
// Let's close the front connection if the back connection is closed. This way, we can retry connecting from the start.
|
||||||
if (!client.disconnecting) {
|
if (!client.disconnecting) {
|
||||||
this.closeWebsocketConnection(client, 1011, "Connection lost to back server");
|
this.closeWebsocketConnection(client, 1011, "Connection lost to back server");
|
||||||
@ -224,7 +243,14 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
console.log("A user left");
|
console.log("A user left");
|
||||||
})
|
})
|
||||||
.on("error", (err: Error) => {
|
.on("error", (err: Error) => {
|
||||||
console.error("Error in connection to back server:", err);
|
console.error(
|
||||||
|
"Error in connection to back server '" +
|
||||||
|
apiClient.getChannel().getTarget() +
|
||||||
|
"' for room '" +
|
||||||
|
client.roomId +
|
||||||
|
"':",
|
||||||
|
err
|
||||||
|
);
|
||||||
if (!client.disconnecting) {
|
if (!client.disconnecting) {
|
||||||
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
this.closeWebsocketConnection(client, 1011, "Error while connecting to back server");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user