praneel
praneel

Reputation: 241

Autobahn javascript connection - passing dynamic server

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);
}

Upvotes: 0

Views: 138

Answers (1)

Willi Pasternak
Willi Pasternak

Reputation: 486

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'});

Upvotes: 1

Related Questions