Hello Ernesto,

We also have code to send websocket messages "to others"
I do store active client list (each page/tab is client)
Every client stores pageId and sessionId

Then I do filtering on pageId+sessionId

This seems to work as expected

On Wed, 3 Apr 2019 at 18:18, Ernesto Reinaldo Barreiro
<reier...@gmail.com> wrote:
>
> Hi,
>
> I have the following use case.
>
> 1- One browser tab sends a text message
> 2- Other browser tabs should receive message (but emitting tab not).
>
> I have done
>
> add(*new *WebSocketBehavior() {
> @Override
> *protected void *onMessage(WebSocketRequestHandler handler, TextMessage
> message) {
> sendNotificationToSession(....)
> }
> });
>
>
>
> *public void *sendNotificationToSession(String sessionId) {
> *if *(com.rometools.utils.Strings.*isEmpty*(sessionId)) {
> *throw new *IllegalArgumentException(*"sessionId cannot be empty"*);
> }
> Application application = Application.*get*(KmsContext.*APP_NAME*);
> privateSendNotificationTo(getRegistry(application).getConnections(application,
> sessionId));
> }
>
>
> *private void *privateSendNotificationTo(Collection<IWebSocketConnection>
> webSocketConnections) {
> String message = toJSON();
> *for*(IWebSocketConnection connection : webSocketConnections) {
> *if *(connection.isOpen()) {
> *try *{
> connection.sendMessage(message);
> } *catch *(IOException e) {
> *log*.error(*"Could not send notification"*, e);
> *//$NON-NLS-1$ *}
> }
> }
> }
>
>
> I see some classes like
>
>
>
>
>
> */**  * A base message for all messages with information about the client
>  */ **public abstract class *AbstractClientMessage *implements *
> IWebSocketMessage
> {
> *private final *String *applicationName*;
> *private final *String *sessionId*;
> *private final *IKey *key*;
>
> *public *AbstractClientMessage(Application application, String sessionId,
> IKey key)
> {
> *this*.*applicationName *= Args.*notNull*(application, *"application"*
> ).getName();
> *this*.*sessionId *= Args.*notNull*(sessionId, *"sessionId"*);
> *this*.*key *= Args.*notNull*(key, *"key"*);
> }
>
> *public *Application getApplication()
> {
> *return *Application.*get*(*applicationName*);
> }
>
> *public *String getSessionId()
> {
> *return **sessionId*;
> }
>
> *public *IKey getKey()
> {
> *return **key*;
> }
>
> }
>
>
> provide IKey as "discriminator" of sending page. But this is neither part
> of IWebSocketMessage nor it is part of IWebSocketConnection... So, I don't
> really know to use to exclude the emitting page. This clearly would be
> possible if both IWebSocketMessage and IWebSocketConnection have a IKey
> getPageKey();
>
>
> Is there a way to do this? Am I missing some essential part?
>
>
> --
> Regards - Ernesto Reinaldo Barreiro



-- 
WBR
Maxim aka solomax

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to