Merge branch 'develop' of github.com:thecodingmachine/workadventure into feat/follow-woka
This commit is contained in:
commit
368a115b4c
93 changed files with 4017 additions and 2405 deletions
|
@ -1,20 +1,10 @@
|
|||
import { ADMIN_API_TOKEN, ADMIN_API_URL, ADMIN_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable";
|
||||
import Axios from "axios";
|
||||
import { GameRoomPolicyTypes } from "_Model/PusherRoom";
|
||||
import { CharacterTexture } from "./AdminApi/CharacterTexture";
|
||||
import { MapDetailsData } from "./AdminApi/MapDetailsData";
|
||||
import { RoomRedirect } from "./AdminApi/RoomRedirect";
|
||||
|
||||
export interface AdminApiData {
|
||||
roomUrl: string;
|
||||
email: string | null;
|
||||
mapUrlStart: string;
|
||||
tags: string[];
|
||||
policy_type: number;
|
||||
userUuid: string;
|
||||
messages?: unknown[];
|
||||
textures: CharacterTexture[];
|
||||
}
|
||||
import { CharacterTexture } from "../Messages/JsonMessages/CharacterTexture";
|
||||
import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData";
|
||||
import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||
import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData";
|
||||
|
||||
export interface AdminBannedData {
|
||||
is_banned: boolean;
|
||||
|
@ -78,6 +68,10 @@ class AdminApi {
|
|||
const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, {
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
||||
});
|
||||
if (!isAdminApiData(res.data)) {
|
||||
console.error("Message received from /api/login-url is not in the expected format. Message: ", res.data);
|
||||
throw new Error("Message received from /api/login-url is not in the expected format.");
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
|
@ -89,6 +83,10 @@ class AdminApi {
|
|||
const res = await Axios.get(ADMIN_API_URL + "/api/check-user/" + organizationMemberToken, {
|
||||
headers: { Authorization: `${ADMIN_API_TOKEN}` },
|
||||
});
|
||||
if (!isAdminApiData(res.data)) {
|
||||
console.error("Message received from /api/check-user is not in the expected format. Message: ", res.data);
|
||||
throw new Error("Message received from /api/check-user is not in the expected format.");
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isCharacterTexture = new tg.IsInterface()
|
||||
.withProperties({
|
||||
id: tg.isNumber,
|
||||
level: tg.isNumber,
|
||||
url: tg.isString,
|
||||
rights: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export type CharacterTexture = tg.GuardedType<typeof isCharacterTexture>;
|
|
@ -1,23 +0,0 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
import { GameRoomPolicyTypes } from "_Model/PusherRoom";
|
||||
import { isCharacterTexture } from "./CharacterTexture";
|
||||
import { isAny, isNumber } from "generic-type-guard";
|
||||
|
||||
/*const isNumericEnum =
|
||||
<T extends { [n: number]: string }>(vs: T) =>
|
||||
(v: any): v is T =>
|
||||
typeof v === "number" && v in vs;*/
|
||||
|
||||
export const isMapDetailsData = new tg.IsInterface()
|
||||
.withProperties({
|
||||
roomSlug: tg.isOptional(tg.isString), // deprecated
|
||||
mapUrl: tg.isString,
|
||||
policy_type: isNumber, //isNumericEnum(GameRoomPolicyTypes),
|
||||
tags: tg.isArray(tg.isString),
|
||||
textures: tg.isArray(isCharacterTexture),
|
||||
contactPage: tg.isUnion(tg.isString, tg.isUndefined),
|
||||
authenticationMandatory: tg.isUnion(tg.isBoolean, tg.isUndefined),
|
||||
})
|
||||
.get();
|
||||
|
||||
export type MapDetailsData = tg.GuardedType<typeof isMapDetailsData>;
|
|
@ -1,8 +0,0 @@
|
|||
import * as tg from "generic-type-guard";
|
||||
|
||||
export const isRoomRedirect = new tg.IsInterface()
|
||||
.withProperties({
|
||||
redirectUrl: tg.isString,
|
||||
})
|
||||
.get();
|
||||
export type RoomRedirect = tg.GuardedType<typeof isRoomRedirect>;
|
|
@ -1,4 +1,4 @@
|
|||
const EventEmitter = require("events");
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
const clientJoinEvent = "clientJoin";
|
||||
const clientLeaveEvent = "clientLeave";
|
||||
|
|
|
@ -37,6 +37,7 @@ import {
|
|||
VariableMessage,
|
||||
ErrorMessage,
|
||||
WorldFullMessage,
|
||||
PlayerDetailsUpdatedMessage,
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY } from "../Enum/EnvironmentVariable";
|
||||
|
@ -50,14 +51,15 @@ import { GroupDescriptor, UserDescriptor, ZoneEventListener } from "_Model/Zone"
|
|||
import Debug from "debug";
|
||||
import { ExAdminSocketInterface } from "_Model/Websocket/ExAdminSocketInterface";
|
||||
import { WebSocket } from "uWebSockets.js";
|
||||
import { isRoomRedirect } from "./AdminApi/RoomRedirect";
|
||||
import { CharacterTexture } from "./AdminApi/CharacterTexture";
|
||||
import { isRoomRedirect } from "../Messages/JsonMessages/RoomRedirect";
|
||||
import { CharacterTexture } from "../Messages/JsonMessages/CharacterTexture";
|
||||
|
||||
const debug = Debug("socket");
|
||||
|
||||
interface AdminSocketRoomsList {
|
||||
[index: string]: number;
|
||||
}
|
||||
|
||||
interface AdminSocketUsersList {
|
||||
[index: string]: boolean;
|
||||
}
|
||||
|
@ -297,6 +299,16 @@ export class SocketManager implements ZoneEventListener {
|
|||
emitInBatch(listener, subMessage);
|
||||
}
|
||||
|
||||
onPlayerDetailsUpdated(
|
||||
playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage,
|
||||
listener: ExSocketInterface
|
||||
): void {
|
||||
const subMessage = new SubMessage();
|
||||
subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage);
|
||||
|
||||
emitInBatch(listener, subMessage);
|
||||
}
|
||||
|
||||
onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void {
|
||||
const subMessage = new SubMessage();
|
||||
subMessage.setErrormessage(errorMessage);
|
||||
|
@ -372,11 +384,7 @@ export class SocketManager implements ZoneEventListener {
|
|||
debug("Leaving room %s.", socket.roomId);
|
||||
|
||||
room.leave(socket);
|
||||
if (room.isEmpty()) {
|
||||
room.close();
|
||||
this.rooms.delete(socket.roomId);
|
||||
debug("Room %s is empty. Deleting.", socket.roomId);
|
||||
}
|
||||
this.deleteRoomIfEmpty(room);
|
||||
} else {
|
||||
console.error("Could not find the GameRoom the user is leaving!");
|
||||
}
|
||||
|
@ -395,6 +403,21 @@ export class SocketManager implements ZoneEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private deleteRoomIfEmpty(room: PusherRoom): void {
|
||||
if (room.isEmpty()) {
|
||||
room.close();
|
||||
this.rooms.delete(room.roomUrl);
|
||||
debug("Room %s is empty. Deleting.", room.roomUrl);
|
||||
}
|
||||
}
|
||||
|
||||
public deleteRoomIfEmptyFromId(roomUrl: string): void {
|
||||
const room = this.rooms.get(roomUrl);
|
||||
if (room) {
|
||||
this.deleteRoomIfEmpty(room);
|
||||
}
|
||||
}
|
||||
|
||||
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
||||
//check and create new world for a room
|
||||
let room = this.rooms.get(roomUrl);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue