0

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.

Shvalb
  • 1,835
  • 2
  • 30
  • 60

2 Answers2

1

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

MattSizzle
  • 3,145
  • 1
  • 22
  • 42
  • That's great, but that's the easy part, How do you accept it in the Javascript client side? – Shvalb Jan 03 '17 at 18:15
0

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);
  }
}
Community
  • 1
  • 1
Shasha
  • 669
  • 1
  • 8
  • 26