How do you limit the number of clients connected to a channel?

Awh, hold on! So the issue is that you set map_size(Presence.list(socket)) < 3 and yet up to 3 clients are able to join, correct?

That’s exactly what’s supposed to happen! Say two clients have already joined, then map_size(...) there is going to return 2. Which makes the statement true, and thus the third client succeeds to join. Say a fourth client then wants to join, map_size is then going to return 3, the statement then renders false and they cannot join.

I guess this solves the misterious issue? :flushed:

1 Like

You’re right! How did I miss it? :sweat_smile:

1 Like

You will still have overflow possible as others mentioned as soon as you go to an additional server. This overflow should be small, depending upon join speed of the clients (i.e. you’d have a tough time reproducing locally I’d bet). Because CRDT is eventually consistent, the only thing you can do is be eventually consistent as well, you’ll have to boot users that overflow if it’s important to you. You can do so by broadcasting a disconnect message, causing the client to reconnect and rejoin channels (getting a denial now that it’s full).

2 Likes