I am using the Autobahn JS for creating a connection with Wamp WS version 1. The code used for connection is:
ab.connect(serverUrl,function (session) {
sess = session ;
sess.prefix("event", "abc/");
console.log("Connected to " + serverUrl);
sess.subscribe("event:topicDemo",onMessage);
}
},
function(code, reason){
sess = null;
Console.log("Client disconnected");
}
);
Here the connection is established successfully. But I want to use a mechanism in which I would subscribe to the topic after the connection is established. Plus I want to use the session object in future as per the requirement. (In this case ab.connect works asynchronously, due to which the session object cannot be used in future) Is it possible?
Thanks in advance.
The connection stores a session object (
connection.session), then after youronopenevent has finished, you can store a boolean:isConnectionReady = trueAnd I don't know how you want to use the session object in the future, but all you need to do is waiting for
onopenevent, after that, your session object exists until anoncloseevent is emitted (orconnection.isOpen() == false).