Excluding message sender
Is there a way to exclude the sender from the message broadcast subscribed to the same context ? Would it be interesting to have this option in the audiences ?
I did some work on this some time ago. But I'm still unsure, if it does not have unwanted side-effect, when mixing different kinds of publishers/subscribers. Please check this branch https://github.com/jrief/django-websocket-redis/tree/exclude-message-sender and tell me, if it fits for you. I would btw. be interested which publishers/subscribers you're using.
Interesting, but indeed sometimes you would need to be self notified.
For a more global behavior I would maybe have given the ability to specify audiences like
groups + not_users or groups + not_session which would allow to include or exclude contexts.
Wouldn't that make the API far too complicate?
How about something simpler, say that the same message is never send back on its counterpart. Say ws4redis receives a message on publish-user, than that message would be sent back on subscribe-session, subscribe-broadcast and subscribe-group (of course, only if desired), but it would not be sent back on subscribe-user.
Please think about it. Something I would like to avoid, is to prefix each message with a unique ID. We certainly need a simple but generic solution for this.
I agree with a simple & generic solution. I'm wondering if user & group are not already too specific. Maybe we should simply try to get closer to the other implementations (I don't know them though)
Maybe we should simply try to get closer to the other implementations (I don't know them though)
Me neither. Anybody here? Please give some hints.
I just found this example where socket.io uses to() & in() to respectively include or exclude the sender.
Hmm, Interesting idea, but I have two problems with it.
How can the client programmatically tell the server how and in what he's interested? With Socket.IO, the client could pass in this execution stack using JS commands, which then are evaluated on the server using eval(). This however is very dangerous and evil.
The second problem is, that the server never talks to itself. It publishes to Redis and Redis triggers a subscription event. Therefore the
socket.on('cursor', function(data) {
socket.broadcast.emit('msg', data);
});
callback doesn't work here.
... but I'm sure, we'll come up with a feasible idea.
Yeah I was also wondering about the same type of question
I was thinking about how to solve this problem: Each message is prefixed with a number consisting of the current threat/greenlet-ID and a message counter, which is increased after publishing a message. This way, duplicate messages can be avoided.
However, if you try to run the chat-demo using the branch exclude-message-sender, it won't work correctly anymore.
I'am still struggling...
@Glideh I just commited a new version on branch exclude-message-sender. I hope this now is a good solution:
There is a message class which wraps messages into a list with versioning information. The first ID ist the FD of the client's websocket. The second ID is a unique value the client can choose himself. For this ID I suggest to use new Date().valueOf(), since it is monotonically increasing and thus well suitable for comparisons against the past. The third item is the payload.
Please check the demo samples and tell me, if they fit your needs.
I just checked your commits on exclude-message-sender.
I'm not enough familiar with Python & websockets to understand the details but I get the idea.
I don't know how to test it though.
Also I don't really understand how can you know from the server which is the client_id to exclude.
I just dropped theses changes. They don't work as expected. Currently the only new feature is that one can choose, if he wants to echo his own message or not.