Skip to content

Commit

Permalink
#67 - Introducing hacky bus class.
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed May 22, 2012
1 parent 4121344 commit 9b4fb19
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/sockjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var SockJS = function(url, dep_protocols_whitelist, options) {
}
that._base_url = utils.amendUrl(url);
that._server = that._options.server || utils.random_number_string(1000);
that._bus = new EventEmitter(['send', 'close', 'heartbeat']);
if (that._options.protocols_whitelist &&
that._options.protocols_whitelist.length) {
protocols_whitelist = that._options.protocols_whitelist;
Expand Down Expand Up @@ -78,6 +79,7 @@ SockJS.prototype._dispatchOpen = function() {
that._transport_tref = null;
}
that.readyState = SockJS.OPEN;
that._startHeartbeats();
that.dispatchEvent(new SimpleEvent("open"));
} else {
// The server might have been restarted, and lost track of our
Expand All @@ -97,6 +99,7 @@ SockJS.prototype._dispatchHeartbeat = function(data) {
var that = this;
if (that.readyState !== SockJS.OPEN)
return;
that._bus.emit('heartbeat');
that.dispatchEvent(new SimpleEvent('heartbeat', {}));
};

Expand Down Expand Up @@ -133,6 +136,7 @@ SockJS.prototype._didClose = function(code, reason, force) {
}
that.readyState = SockJS.CLOSED;

that._bus.emit('close');
utils.delay(function() {
that.dispatchEvent(close_event);
});
Expand Down

0 comments on commit 9b4fb19

Please sign in to comment.