diff --git a/lib/session.js b/lib/session.js index 9557900..bf471db 100644 --- a/lib/session.js +++ b/lib/session.js @@ -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; @@ -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); @@ -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); };