Skip to content

Commit

Permalink
fix(session): unmap session when connection is updated (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
princjef authored and pierreca committed Jan 31, 2018
1 parent 06de584 commit e61b5ff
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/session.js
Expand Up @@ -150,6 +150,13 @@ var stateMachine = function(session) {
*/
function Session(conn) {
Session.super_.call(this);

var self = this;
this.sm = new StateMachine(stateMachine(this));
this.sm.bind(function(event, oldState, newState) {
debug('stateChange(' + self.remoteChannel + '):', oldState, '=>', newState, ', reason:', event);
});

this.setMaxListeners(100);
this.connection = conn;
this.mapped = false;
Expand All @@ -160,12 +167,6 @@ function Session(conn) {
this._receiverLinks = {};
this._linksByRemoteHandle = {};
this._disposed = false;

var self = this;
this.sm = new StateMachine(stateMachine(this));
this.sm.bind(function(event, oldState, newState) {
debug('stateChange(' + self.remoteChannel + '):', oldState, '=>', newState, ', reason:', event);
});
}

util.inherits(Session, EventEmitter);
Expand All @@ -191,6 +192,14 @@ Object.defineProperty(Session.prototype, 'disposed', {
get: function() { return this._disposed; }
});

Object.defineProperty(Session.prototype, 'connection', {
get: function() { return this._connection; },
set: function(value) {
this._connection = value;
this.sm.disconnected();
}
});

Session.prototype.begin = function(sessionPolicy) {
this.sm.begin(sessionPolicy);
};
Expand Down

0 comments on commit e61b5ff

Please sign in to comment.