Compare commits

...

1 Commits

Author SHA1 Message Date
Gregoire Parant 41c8372ee8 Manager full room
- Send message at user when the room is full
- Don't close the connexion. The user can navigate in the room but the message send will be never take by the back end.
2020-11-22 11:28:02 +01:00
4 changed files with 48 additions and 12 deletions

View File

@ -165,9 +165,6 @@ export class IoSocketController {
let memberTags: string[] = [];
let memberTextures: CharacterTexture[] = [];
const room = await socketManager.getOrCreateRoom(roomId);
if(room.isFull){
throw new Error('Room is full');
}
if (ADMIN_API_URL) {
try {
const userData = await adminApi.fetchMemberDataByUuid(userUuid);
@ -240,9 +237,26 @@ export class IoSocketController {
open: (ws) => {
// Let's join the room
const client = this.initClient(ws); //todo: into the upgrade instead?
socketManager.handleJoinRoom(client);
//get data information and show messages
const room = socketManager.getRoomById(client.roomId);
if(room && room.isFull){
socketManager.emitSendUserMessage({
userUuid: client.userUuid,
message: `<p style="text-align: center; font-size: 40px;">
Oops, WorkAdventure is a victim of its own success.
</p>
<p style="text-align: center">
You can retry to connect on the platform in a moment.
</p>`,
type: "RoomFull"
}, client);
console.info(`user ${client.userUuid} not connected, room is full`);
return;
}
socketManager.handleJoinRoom(client);
if (ADMIN_API_URL) {
adminApi.fetchMemberDataByUuid(client.userUuid).then((res: FetchMemberDataByUuidResponse) => {
if (!res.messages) {
@ -263,6 +277,13 @@ export class IoSocketController {
},
message: (ws, arrayBuffer, isBinary): void => {
const client = ws as ExSocketInterface;
//permit to stop treatment message when the room is full
const room = socketManager.getRoomById(client.roomId);
if(room && room.isFull){
return;
}
const message = ClientToServerMessage.deserializeBinary(new Uint8Array(arrayBuffer));
if (message.hasViewportmessage()) {

View File

@ -365,6 +365,10 @@ export class SocketManager {
}
}
getRoomById(roomId: string) : GameRoom|undefined {
return this.Worlds.get(roomId)
}
async getOrCreateRoom(roomId: string): Promise<GameRoom> {
//check and create new world for a room
let world = this.Worlds.get(roomId)
@ -658,10 +662,15 @@ export class SocketManager {
client.send(serverToClientMessage.serializeBinary().buffer, true);
}
public emitSendUserMessage(messageToSend: {userUuid: string, message: string, type: string}): ExSocketInterface {
const socket = this.searchClientByUuid(messageToSend.userUuid);
public emitSendUserMessage(messageToSend: {userUuid: string, message: string, type: string},
client?: ExSocketInterface): ExSocketInterface {
let socket = client;
if(!socket){
throw 'socket was not found';
const socketFind = this.searchClientByUuid(messageToSend.userUuid);
if (!socketFind) {
throw 'socket was not found';
}
socket = socketFind;
}
const sendUserMessage = new SendUserMessage();

View File

@ -4,9 +4,9 @@ import {HtmlUtils} from "../WebRtc/HtmlUtils";
let modalTimeOut : NodeJS.Timeout;
export class TypeMessageExt implements TypeMessageInterface{
private nbSecond = 0;
private maxNbSecond = 10;
private titleMessage = 'IMPORTANT !';
protected nbSecond = 0;
protected maxNbSecond = 10;
protected titleMessage = 'IMPORTANT !';
showMessage(message: string, canDeleteMessage: boolean = true): void {
//delete previous modal
@ -37,7 +37,7 @@ export class TypeMessageExt implements TypeMessageInterface{
const p : HTMLParagraphElement = document.createElement('p');
p.id = 'body-report-user'
p.innerText = message;
p.innerHTML = message;
div.appendChild(p);
const mainSectionDiv = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('main-container');
@ -84,4 +84,11 @@ export class Banned extends TypeMessageExt {
showMessage(message: string){
super.showMessage(message, false);
}
}
export class RoomFull extends TypeMessageExt {
showMessage(message: string){
this.maxNbSecond = 30;
super.showMessage(message);
}
}

View File

@ -8,7 +8,6 @@ import Container = Phaser.GameObjects.Container;
import {gameManager} from "../Game/GameManager";
import {ResizableScene} from "./ResizableScene";
import {localUserStore} from "../../Connexion/LocalUserStore";
import {PlayerResourceDescriptionInterface} from "../Entity/Character";
export const CustomizeSceneName = "CustomizeScene";