Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ You can also access the ``connection`` and ``session`` through the ``$wamp`` ser

```Javascript
$wamp.session;
$wamp.connection;
$wamp.connection();
```

###Interceptors
Expand Down
48 changes: 35 additions & 13 deletions src/angular-wamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,21 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
options = angular.extend({onchallenge: digestWrapper(onchallenge), use_deferred: $q.defer}, options);

connection = new autobahn.Connection(options);
connection.onopen = digestWrapper(function (session, details) {
$log.debug("Congrats! You're connected to the WAMP server!");
$rootScope.$broadcast("$wamp.open", {session: session, details: details});
sessionDeferred.resolve();
});

connection.onclose = digestWrapper(function (reason, details) {
$log.debug("Connection Closed: ", reason, details);
sessionDeferred = $q.defer();
sessionPromise = sessionDeferred.promise;
$rootScope.$broadcast("$wamp.close", {reason: reason, details: details});
});
function bindOpenClose() {
connection.onopen = digestWrapper(function (session, details) {
$log.debug("Congrats! You're connected to the WAMP server!");
$rootScope.$broadcast("$wamp.open", {session: session, details: details});
sessionDeferred.resolve();
});

connection.onclose = digestWrapper(function (reason, details) {
$log.debug("Connection Closed: ", reason, details);
sessionDeferred = $q.defer();
sessionPromise = sessionDeferred.promise;
$rootScope.$broadcast("$wamp.close", {reason: reason, details: details});
});
}
bindOpenClose();

/**
* Subscription object which self manages reconnections
Expand Down Expand Up @@ -363,7 +365,27 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
};

return {
connection: connection,
connection: function(){
return connection;
},
openNewConnection : function(newOptions, open, stopOldConnectionBroadcast) {
//close old connection
if (connection.isOpen) {
connection.close();
//oldConnection.onclose will emit
}
options = newOptions;
options = angular.extend({onchallenge: digestWrapper(onchallenge), use_deferred: $q.defer}, options);
if (stopOldConnectionBroadcast) {
connection.onclose = null;
connection.onopen = null;
}
connection = new autobahn.Connection(options);
bindOpenClose();
if (open) {
connection.open();
}
},
open: function () {
//If using WAMP CRA we need to get the authid before the connection can be opened.
if (options.authmethods && options.authmethods.indexOf('wampcra') !== -1 && !options.authid) {
Expand Down