Ideas

31 views
Skip to first unread message

Ralph Schaer

unread,
Jul 20, 2018, 4:54:59 AM7/20/18
to Cettia
Hi

Thanks for the great library. Here two things that I'm missing.

There is no send to all except me method. Would be very helpful to have a method that sends messages to all other sockets.
As a workaround I use this. Not sure if that is the correct way to do it.

socket.on("chat", msg -> {
  server.all(skt -> {
     if (skt != socket) {
       skt.send("chat", msg);
     }
  });
});


Would be useful to add key/value pairs to a socket. When you look at the socket.io chat example 
you see that they add custom data (username) to a socket. 


Ralph




Donghwan Kim

unread,
Jul 21, 2018, 12:45:22 AM7/21/18
to Cettia
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 -> {
  String exclude = socket.id();
  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

Ralph Schaer

unread,
Jul 21, 2018, 3:35:11 AM7/21/18
to Cettia

I like the exclude(socket) syntax. 

Would be nice if there is a possibility to exclude a socket by its id and a way to exclude multiple sockets.
server.all().excludeIds("id1", "id2").send("chat", msg);
server.all().exclude(socket1, socket2).send("chat", msg);
server.all().exclude("tag1", "tag2").send("chat", msg);


<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
A remove method would be nice or setting null removes the key/value pair: set("key", null) 

Donghwan Kim

unread,
Jul 21, 2018, 4:31:00 AM7/21/18
to Cettia
> server.all().excludeIds("id1", "id2").send("chat", msg);
> server.all().exclude(socket1, socket2).send("chat", msg);
> server.all().exclude("tag1", "tag2").send("chat", msg);

I like the last signature which excludes multiple tags, but am not convinced yet about 1st and 2nd signatures since we recommend to use tag instead of handling multiple sockets' reference or id, and it's generally safe and not error-prone in clustered environment. Could you give some use cases of 1st and 2nd ones?

> A remove method would be nice or setting null removes the key/value pair: set("key", null) 

Great. I missed it. Let's declare one more method:

- ServerSocket socket.remove(String) in ServerSocket

-- Donghwan 

Ralph Schaer

unread,
Jul 21, 2018, 4:36:12 AM7/21/18
to Cettia
I was just brainstorming, don't have a use case.

Donghwan Kim

unread,
Jul 23, 2018, 9:08:53 AM7/23/18
to Cettia
Sorry for the delay. I've been busy with Asity. I'll get back to this and open issues sometime this week.

-- Donghwan

--
You received this message because you are subscribed to the Google Groups "Cettia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cettia+un...@googlegroups.com.
To post to this group, send email to cet...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cettia/1733fcb4-160a-45a5-b0ae-d7ebcc672265%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Donghwan Kim

unread,
Jul 26, 2018, 8:00:45 AM7/26/18
to Cettia
Hi,

Thanks for your brainstorming. I've just created the following issues:


Feel free to continue discussions. Any form of contributions are welcomed ;)

-- Donghwan

Donghwan Kim

unread,
Aug 6, 2018, 8:59:44 AM8/6/18
to Cettia and Asity
I just announced the roadmap for 1.1 and had to exclude a feature to exclude certain sockets for the 'Release early, release often'. Instead, it will be shipped in 1.2 and send to all except me would be available like this by then:

socket.on("chat", msg -> {
  String exclude = socket.id();
  server.select(skt -> !skt.id().equals(exclude)).send("chat", msg);
});

Thanks,

-- Donghwan

On Thursday, July 26, 2018 at 9:00:45 PM UTC+9, Donghwan Kim wrote:
Hi,

Thanks for your brainstorming. I've just created the following issues:


Feel free to continue discussions. Any form of contributions are welcomed ;)

-- Donghwan


On Mon, Jul 23, 2018 at 10:08 PM Donghwan Kim <flowersi...@gmail.com> wrote:
Sorry for the delay. I've been busy with Asity. I'll get back to this and open issues sometime this week.

-- Donghwan

On Sat, Jul 21, 2018 at 5:36 PM Ralph Schaer <ralph...@gmail.com> wrote:
I was just brainstorming, don't have a use case.


On Saturday, July 21, 2018 at 10:31:00 AM UTC+2, Donghwan Kim wrote:
> server.all().excludeIds("id1", "id2").send("chat", msg);
> server.all().exclude(socket1, socket2).send("chat", msg);
> server.all().exclude("tag1", "tag2").send("chat", msg);

--
You received this message because you are subscribed to the Google Groups "Cettia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cettia+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages