0

I got this as below from backend developer:

 session.publish('com.test.temp', [
        temp,
        humidity,
        componentId,
        componentType
     ], {}, { exclude_me: true });

So I succeed in a handshake with the server using WebSocket:

 var ws = new WebSocket('ws://1server address','example.json');

  ws.onopen = function () {
      console.log('websocket is connected ...')

      ws.send('connected')
  }

  ws.onmessage = function (ev) {
      console.log(ev);
  }

But I could not see any data in the console.log(ev)

How can I get JSON data from the server??

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Gil
  • 105
  • 2
  • 5
  • 12

1 Answers1

0

I find a way to get data from the crossbar.

I was supposed to use autobahn library.

This is my solution:

var connection = new autobahn.Connection({ url : 'server url', realm: 'realm1'
});

connection.onopen = function (session) {

console.log('websocket is connected ...')

session.subscribe('com.example.example', function(message) {
 console.log(message);

 }

}

connection.open();

I hope this answer will be helpful to someone.

Gil
  • 105
  • 2
  • 5
  • 12