Autobahn javascript connection - passing dynamic server

142 Views Asked by At

I am using below javascript code to connect to autobahn server. All these times I was using static ip but now the ip is going to be dynamic. How can I pass dynamic server ip and get autobahn connected dynamically?

var connection = new autobahn.Connection({url: 'ws://<ip>:8080/ws', realm: 'realm1'});

var openSession = null;

connection.onopen = function (session) {
    openSession = session;
    window.JSInterface.isConnected(true);
};

connection.onClose = function(reason, details) {
    openSession = null;
    window.JSInterface.isConnected(false);
}
1

There are 1 best solutions below

0
On

There are to options:

  1. Take a domain name instead of an IP e.g ws://autobahn.de:8080/ws
  2. You have a service where you can fetch the ip an then pass it with a variable for example:

var connectionIP = 8.8.8.8; var connection = new autobahn.Connection({url:'ws://'+connectionIP+':8080/ws', realm: 'realm1'});