worlds + fix map update
This commit is contained in:
@@ -3,7 +3,7 @@ import { BaseController } from "./BaseController";
|
||||
import { parse } from "query-string";
|
||||
import { adminApi } from "../Services/AdminApi";
|
||||
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 { socketManager } from "../Services/SocketManager";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
@@ -14,6 +14,7 @@ export class MapController extends BaseController {
|
||||
super();
|
||||
this.App = App;
|
||||
this.getMapUrl();
|
||||
this.getWorlds();
|
||||
}
|
||||
|
||||
// Returns a map mapping map name to file name of the map
|
||||
@@ -51,7 +52,7 @@ export class MapController extends BaseController {
|
||||
return;
|
||||
}
|
||||
|
||||
const mapUrl = roomUrl.protocol + "//" + match[1];
|
||||
const mapUrl = roomUrl.protocol + "//" + match[ 1 ];
|
||||
|
||||
res.writeStatus("200 OK");
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user