worlds + fix map update
This commit is contained in:
@@ -3,7 +3,7 @@ import { BaseController } from "./BaseController";
|
|||||||
import { parse } from "query-string";
|
import { parse } from "query-string";
|
||||||
import { adminApi } from "../Services/AdminApi";
|
import { adminApi } from "../Services/AdminApi";
|
||||||
import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
|
||||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
import { PusherRoom, GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||||
import { MapDetailsData } from "../Services/AdminApi/MapDetailsData";
|
import { MapDetailsData } from "../Services/AdminApi/MapDetailsData";
|
||||||
import { socketManager } from "../Services/SocketManager";
|
import { socketManager } from "../Services/SocketManager";
|
||||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||||
@@ -14,6 +14,7 @@ export class MapController extends BaseController {
|
|||||||
super();
|
super();
|
||||||
this.App = App;
|
this.App = App;
|
||||||
this.getMapUrl();
|
this.getMapUrl();
|
||||||
|
this.getWorlds();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a map mapping map name to file name of the map
|
// Returns a map mapping map name to file name of the map
|
||||||
@@ -51,7 +52,7 @@ export class MapController extends BaseController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
const mapUrl = roomUrl.protocol + "//" + match[ 1 ];
|
||||||
|
|
||||||
res.writeStatus("200 OK");
|
res.writeStatus("200 OK");
|
||||||
this.addCorsHeaders(res);
|
this.addCorsHeaders(res);
|
||||||
@@ -95,4 +96,61 @@ export class MapController extends BaseController {
|
|||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getWorlds() {
|
||||||
|
this.App.options("/worlds", (res: HttpResponse, req: HttpRequest) => {
|
||||||
|
this.addCorsHeaders(res);
|
||||||
|
|
||||||
|
res.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.App.get("/worlds", async (res: HttpResponse, req: HttpRequest) => {
|
||||||
|
res.onAborted(() => {
|
||||||
|
console.warn("/message request was aborted");
|
||||||
|
});
|
||||||
|
const { userIdentify, token } = parse(req.getQuery());
|
||||||
|
try {
|
||||||
|
//verify connected by token
|
||||||
|
if (token != undefined) {
|
||||||
|
try {
|
||||||
|
const authTokenData: AuthTokenData = jwtTokenManager.verifyJWTToken(token as string, false);
|
||||||
|
if (authTokenData.hydraAccessToken == undefined) {
|
||||||
|
throw Error("Token cannot to be check on Hydra");
|
||||||
|
}
|
||||||
|
|
||||||
|
const worlds: Map<String, PusherRoom> = socketManager.getWorlds();
|
||||||
|
|
||||||
|
const result: any = {};
|
||||||
|
|
||||||
|
for (const room of worlds.values()) {
|
||||||
|
result[room.roomUrl] = room.getListeners().size;
|
||||||
|
/*
|
||||||
|
for (const listener of room.getListeners()) {
|
||||||
|
const position: any = {};
|
||||||
|
position.name = listener.name;
|
||||||
|
position.roomId = listener.roomId;
|
||||||
|
position.position = listener.position;
|
||||||
|
position.viewport = listener.viewport;
|
||||||
|
result.push(position);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
.writeStatus("200 OK")
|
||||||
|
.writeHeader("Content-Type", "application/json")
|
||||||
|
.end(
|
||||||
|
JSON.stringify(result)
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return this.errorToResponse(error, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("getWorlds => ERROR", error);
|
||||||
|
this.errorToResponse(error, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ export class PusherRoom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getListeners(): Set<ExSocketInterface> {
|
||||||
|
return this.listeners;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection to the back server to track global messages relative to this room (like variable changes).
|
* Creates a connection to the back server to track global messages relative to this room (like variable changes).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
VariableMessage,
|
VariableMessage,
|
||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
WorldFullMessage,
|
WorldFullMessage,
|
||||||
|
PositionMessage,
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||||
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY, PUSHER_FORCE_ROOM_UPDATE } from "../Enum/EnvironmentVariable";
|
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY, PUSHER_FORCE_ROOM_UPDATE } from "../Enum/EnvironmentVariable";
|
||||||
@@ -53,10 +54,10 @@ import { CharacterTexture } from "./AdminApi/CharacterTexture";
|
|||||||
const debug = Debug("socket");
|
const debug = Debug("socket");
|
||||||
|
|
||||||
interface AdminSocketRoomsList {
|
interface AdminSocketRoomsList {
|
||||||
[index: string]: number;
|
[ index: string ]: number;
|
||||||
}
|
}
|
||||||
interface AdminSocketUsersList {
|
interface AdminSocketUsersList {
|
||||||
[index: string]: boolean;
|
[ index: string ]: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AdminSocketData {
|
export interface AdminSocketData {
|
||||||
@@ -249,6 +250,13 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
|
|
||||||
client.backConnection.write(pusherToBackMessage);
|
client.backConnection.write(pusherToBackMessage);
|
||||||
|
|
||||||
|
const position = userMovesMessage.getPosition();
|
||||||
|
if (position === undefined) {
|
||||||
|
throw new Error("Missing position in UserMovesMessage");
|
||||||
|
}
|
||||||
|
// update position
|
||||||
|
client.position = ProtobufUtils.toPointInterface(position);
|
||||||
|
|
||||||
const viewport = userMovesMessage.getViewport();
|
const viewport = userMovesMessage.getViewport();
|
||||||
if (viewport === undefined) {
|
if (viewport === undefined) {
|
||||||
throw new Error("Missing viewport in UserMovesMessage");
|
throw new Error("Missing viewport in UserMovesMessage");
|
||||||
@@ -366,13 +374,15 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
||||||
//check and create new world for a room
|
//check and create new world for a room
|
||||||
let room = this.rooms.get(roomUrl);
|
let room = this.rooms.get(roomUrl);
|
||||||
if (PUSHER_FORCE_ROOM_UPDATE || room === undefined) {
|
if (room === undefined) {
|
||||||
room = new PusherRoom(roomUrl, this);
|
room = new PusherRoom(roomUrl, this);
|
||||||
if (ADMIN_API_URL) {
|
if (ADMIN_API_URL) {
|
||||||
await this.updateRoomWithAdminData(room);
|
await this.updateRoomWithAdminData(room);
|
||||||
}
|
}
|
||||||
await room.init();
|
await room.init();
|
||||||
this.rooms.set(roomUrl, room);
|
this.rooms.set(roomUrl, room);
|
||||||
|
} else if (PUSHER_FORCE_ROOM_UPDATE && ADMIN_API_URL) {
|
||||||
|
await this.updateRoomWithAdminData(room);
|
||||||
}
|
}
|
||||||
return room;
|
return room;
|
||||||
}
|
}
|
||||||
@@ -625,7 +635,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
if (playGlobalMessageEvent.getBroadcasttoworld()) {
|
if (playGlobalMessageEvent.getBroadcasttoworld()) {
|
||||||
tabUrlRooms = await adminApi.getUrlRoomsFromSameWorld(clientRoomUrl);
|
tabUrlRooms = await adminApi.getUrlRoomsFromSameWorld(clientRoomUrl);
|
||||||
} else {
|
} else {
|
||||||
tabUrlRooms = [clientRoomUrl];
|
tabUrlRooms = [ clientRoomUrl ];
|
||||||
}
|
}
|
||||||
|
|
||||||
const roomMessage = new AdminRoomMessage();
|
const roomMessage = new AdminRoomMessage();
|
||||||
|
|||||||
Reference in New Issue
Block a user