Hi Ralph,
I saw your cettia-demo repositories at GitHub ;) Thanks for the great example!
> There is no send to all except me method.
That's a really good point. To implement 'send to all except me', we need two things:
1. String id() in ServerSocket as a getter for socket id
2. Sentence exclude(ServerSocket) in Sentence to exclude a given socket from selection
Your workaround should work in non-clustered environment but not work in clustered environment. Because an action to be passed to server.all doesn't implement Serializable and a socket referenced by skt can't be serialized, we can fix it with 1.
socket.on("chat", msg -> {
server.all((Action<ServerSocket> & Serializable) skt -> {
if (!skt.id().equals(exclude)) { skt.send("chat", msg);
}
});
});
Of course, it's boring and lengthy. With 2, it can be concise and fluent like this:
socket.on("chat", msg -> {
server.all().exclude(socket).send("chat", msg);
});
BTW, it would be nice if we can exclude sockets by tag also.
socket.on("chat", msg -> {
server.all().exclude("user:donghwan").send("chat", msg);
});
What do you think about the solution? Let's open an issue when we reach an agreement.
> Would be useful to add key/value pairs to a socket.
These methods should be enough right?
- <T> T get(String name) in ServerSocket as a getter of the key/value pairs
- ServerSocket socket.set(String, Object) as a setter of the key/value pairs
I think we can do something nice with this attribute set in conjunction with lambda or expression, "${username}". Likewise, what do you think about this e.g. method signatures?
Anyway, Thanks for all the ideas. I would like to include them in 1.1.0.
-- Donghwan