SOCKJS reply upon SOCKET_CREATED event

187 views Asked by At

I am connection through Vertx eventbus (SockJS to my Java based backend. Everything work fine, However, I cannot find a way to send an initial message.

Is there a way to send back data when SockJS bridge receives SOCKET_CREATED to the sockjs browser side?

Thank you.

2

There are 2 answers

1
MattSizzle On

Taken from their documentation:

if (event.type() == SOCKET_CREATED || event.type() == SOCKET_CLOSED)
{
     //...
     vertx.eventBus().publish("fromServer", jmsg.toJSONString());
}

Your event instantiation may be different, but that would be how you check for the specific event and run code after it has occurred

2
Shasha On

You can check this code , where I'm using EventBus.

Here is the Reference code

this.eventBus = new EventBus(this.URL);
this.eventBus.onopen = (e) => {
       this._opened = true;
        console.log("open connection");
        this.callHandlers('open', e);
        this.eventBus.publish("http://localhost:8082", "USER LOGIN INFO");

        this.eventBus.registerHandler("http://localhost:8081/pushNotification", function (error, message) {
           console.log(message.body);


        //$("<div title='Basic dialog'>Test   message</div>").dialog();

  });
}
this.eventBus.onclose = (e) => {
    this.callHandlers('close', e);
  }
}