worlds + fix map update
This commit is contained in:
parent
7ffbbae731
commit
8cc1584c2e
@ -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
|
||||
@ -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).
|
||||
*/
|
||||
|
@ -34,6 +34,7 @@ import {
|
||||
VariableMessage,
|
||||
ErrorMessage,
|
||||
WorldFullMessage,
|
||||
PositionMessage,
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||
import { ADMIN_API_URL, JITSI_ISS, JITSI_URL, SECRET_JITSI_KEY, PUSHER_FORCE_ROOM_UPDATE } from "../Enum/EnvironmentVariable";
|
||||
@ -249,6 +250,13 @@ export class SocketManager implements ZoneEventListener {
|
||||
|
||||
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();
|
||||
if (viewport === undefined) {
|
||||
throw new Error("Missing viewport in UserMovesMessage");
|
||||
@ -366,13 +374,15 @@ export class SocketManager implements ZoneEventListener {
|
||||
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
||||
//check and create new world for a room
|
||||
let room = this.rooms.get(roomUrl);
|
||||
if (PUSHER_FORCE_ROOM_UPDATE || room === undefined) {
|
||||
if (room === undefined) {
|
||||
room = new PusherRoom(roomUrl, this);
|
||||
if (ADMIN_API_URL) {
|
||||
await this.updateRoomWithAdminData(room);
|
||||
}
|
||||
await room.init();
|
||||
this.rooms.set(roomUrl, room);
|
||||
} else if (PUSHER_FORCE_ROOM_UPDATE && ADMIN_API_URL) {
|
||||
await this.updateRoomWithAdminData(room);
|
||||
}
|
||||
return room;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user