Deleting world when empty.

This commit is contained in:
David Négrier 2020-06-29 19:14:54 +02:00
parent d9e6b501b1
commit 9bdcc9da98
2 changed files with 7 additions and 0 deletions

View File

@ -297,6 +297,9 @@ export class IoSocketController {
const world : World|undefined = this.Worlds.get(Client.roomId);
if(world){
world.leave(Client);
if (world.isEmpty()) {
this.Worlds.delete(Client.roomId);
}
}
//user leave previous room
Client.leave(Client.roomId);

View File

@ -72,6 +72,10 @@ export class World {
this.users.delete(user.userId);
}
public isEmpty(): boolean {
return this.users.size === 0;
}
public updatePosition(socket : Identificable, userPosition: PointInterface): void {
const user = this.users.get(socket.userId);
if(typeof user === 'undefined') {