@rscata I see. Thanks for the explanation. I've tested the code below and it works as you described.
Server-side
maxClients = 4;
onInit (options) {
// identify when a new room is being requested
this.create = options.create || false;
}
requestJoin (options) {
if (options.create) {
// creating a new room
let allowed = (options.create == this.create);
// this room is not being "created" anymore.
this.create = false;
return allowed;
} else {
// joining an existing room
return this.clients.length > 0;
}
}
Client-side
// creating a new room
let room = client.join("poker", { create: true })
room.onJoin.add(() => { /* created! */ })
// joining an existing room
let room = client.join("poker")
room.onJoin.add(() => { /* joined! */ })
room.onError.add(() => { /* no rooms available? */ })
I feel it should be easier to achieve this, though.
For next versions of Colyseus, I think it's important to know when a room is being created or is an existing one during onInit
/ requestJoin
(like we're doing ourselves on this.create
)
Let me know if you have any question. Cheers!