Create and send close message
# TODO - Show error or wait room
This commit is contained in:
parent
326c2e4183
commit
7ac4a2b849
17 changed files with 700 additions and 1846 deletions
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"tsc": "tsc",
|
||||
"dev": "ts-node-dev --respawn ./server.ts",
|
||||
"prod": "tsc && node ./dist/server.js",
|
||||
"prod": "tsc && node --max-old-space-size=4096 ./dist/server.js",
|
||||
"profile": "tsc && node --prof ./dist/server.js",
|
||||
"test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
|
||||
"lint": "node_modules/.bin/eslint src/ . --ext .ts",
|
||||
|
|
|
@ -162,11 +162,13 @@ export class IoSocketController {
|
|||
|
||||
let memberTags: string[] = [];
|
||||
let memberTextures: CharacterTexture[] = [];
|
||||
|
||||
const room = await socketManager.getOrCreateRoom(roomId);
|
||||
if (room.isFull()) {
|
||||
//TODO http return status
|
||||
/*if (room.isFull()) {
|
||||
res.writeStatus("503").end('Too many users');
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
try {
|
||||
const userData = await adminApi.fetchMemberDataByUuid(userUuid);
|
||||
//console.log('USERDATA', userData)
|
||||
|
@ -234,27 +236,37 @@ export class IoSocketController {
|
|||
},
|
||||
/* Handlers */
|
||||
open: (ws) => {
|
||||
// Let's join the room
|
||||
const client = this.initClient(ws); //todo: into the upgrade instead?
|
||||
socketManager.handleJoinRoom(client);
|
||||
resetPing(client);
|
||||
(async () => {
|
||||
// Let's join the room
|
||||
const client = this.initClient(ws); //todo: into the upgrade instead?
|
||||
socketManager.handleJoinRoom(client);
|
||||
resetPing(client);
|
||||
|
||||
//get data information and shwo messages
|
||||
adminApi.fetchMemberDataByUuid(client.userUuid).then((res: FetchMemberDataByUuidResponse) => {
|
||||
if (!res.messages) {
|
||||
//if room is full, emit redirect room message
|
||||
const room = await socketManager.getOrCreateRoom(client.roomId);
|
||||
if (room.isFull) {
|
||||
socketManager.emitCloseMessage(client.userUuid, 302);
|
||||
return;
|
||||
}
|
||||
res.messages.forEach((c: unknown) => {
|
||||
const messageToSend = c as { type: string, message: string };
|
||||
socketManager.emitSendUserMessage({
|
||||
userUuid: client.userUuid,
|
||||
type: messageToSend.type,
|
||||
message: messageToSend.message
|
||||
})
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.error('fetchMemberDataByUuid => err', err);
|
||||
});
|
||||
|
||||
//get data information and shwo messages
|
||||
try {
|
||||
const res: FetchMemberDataByUuidResponse = await adminApi.fetchMemberDataByUuid(client.userUuid);
|
||||
if (!res.messages) {
|
||||
return;
|
||||
}
|
||||
res.messages.forEach((c: unknown) => {
|
||||
const messageToSend = c as { type: string, message: string };
|
||||
socketManager.emitSendUserMessage({
|
||||
userUuid: client.userUuid,
|
||||
type: messageToSend.type,
|
||||
message: messageToSend.message
|
||||
})
|
||||
});
|
||||
}catch(err) {
|
||||
console.error('fetchMemberDataByUuid => err', err);
|
||||
};
|
||||
})();
|
||||
},
|
||||
message: (ws, arrayBuffer, isBinary): void => {
|
||||
const client = ws as ExSocketInterface;
|
||||
|
|
|
@ -85,7 +85,7 @@ export class MapController extends BaseController{
|
|||
res.writeStatus('404').end('No room found');
|
||||
return;
|
||||
}
|
||||
res.writeStatus("200").end(world.isFull() ? '1':'0');
|
||||
res.writeStatus("200").end(world.isFull ? '1':'0');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
|||
import {Movable} from "_Model/Movable";
|
||||
import {extractDataFromPrivateRoomId, extractRoomSlugPublicRoomId, isRoomAnonymous} from "./RoomIdentifier";
|
||||
import {arrayIntersect} from "../Services/ArrayHelper";
|
||||
import {MAX_USERS_PER_ROOM} from "_Enum/EnvironmentVariable";
|
||||
import {MAX_USERS_PER_ROOM} from "../Enum/EnvironmentVariable";
|
||||
|
||||
export type ConnectCallback = (user: User, group: Group) => void;
|
||||
export type DisconnectCallback = (user: User, group: Group) => void;
|
||||
|
@ -180,7 +180,7 @@ export class GameRoom {
|
|||
}
|
||||
}
|
||||
|
||||
isFull() : boolean {
|
||||
get isFull() : boolean {
|
||||
return this.getUsers().size > MAX_USERS_PER_ROOM;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,4 +117,8 @@ export class Group implements Movable {
|
|||
this.leave(user);
|
||||
}
|
||||
}
|
||||
|
||||
get getSize(){
|
||||
return this.users.size;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ import {
|
|||
QueryJitsiJwtMessage,
|
||||
SendJitsiJwtMessage,
|
||||
CharacterLayerMessage,
|
||||
SendUserMessage
|
||||
SendUserMessage,
|
||||
CloseMessage
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Model/Websocket/PointInterface";
|
||||
import {User} from "../Model/User";
|
||||
|
@ -130,6 +131,7 @@ export class SocketManager {
|
|||
userJoinedMessage.setPosition(ProtobufUtils.toPositionMessage(player.position));
|
||||
|
||||
roomJoinedMessage.addUser(userJoinedMessage);
|
||||
roomJoinedMessage.setTagList(client.tags);
|
||||
} else if (thing instanceof Group) {
|
||||
const groupUpdateMessage = new GroupUpdateMessage();
|
||||
groupUpdateMessage.setGroupid(thing.getId());
|
||||
|
@ -493,6 +495,7 @@ export class SocketManager {
|
|||
const groupUpdateMessage = new GroupUpdateMessage();
|
||||
groupUpdateMessage.setGroupid(group.getId());
|
||||
groupUpdateMessage.setPosition(pointMessage);
|
||||
groupUpdateMessage.setGroupsize(group.getSize);
|
||||
|
||||
const subMessage = new SubMessage();
|
||||
subMessage.setGroupupdatemessage(groupUpdateMessage);
|
||||
|
@ -692,6 +695,24 @@ export class SocketManager {
|
|||
return socket;
|
||||
}
|
||||
|
||||
public emitCloseMessage(userUuid: string, status: number): ExSocketInterface {
|
||||
const socket = this.searchClientByUuid(userUuid);
|
||||
if(!socket){
|
||||
throw 'socket was not found';
|
||||
}
|
||||
|
||||
const closeMessage = new CloseMessage();
|
||||
closeMessage.setStatus(status);
|
||||
|
||||
const serverToClientMessage = new ServerToClientMessage();
|
||||
serverToClientMessage.setClosemessage(closeMessage);
|
||||
|
||||
if (!socket.disconnecting) {
|
||||
socket.send(serverToClientMessage.serializeBinary().buffer, true);
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the characterLayers received from the front (as an array of string) with the custom textures from the back.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue