From 82daecb939ca7e7dca3b214071f6387e393afd52 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Mon, 4 Apr 2016 18:33:59 -0400 Subject: [PATCH] refactor(link): store remote attach/detach in link.remote --- lib/link.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/link.js b/lib/link.js index c2d6733..0587973 100644 --- a/lib/link.js +++ b/lib/link.js @@ -14,7 +14,7 @@ function Link(session, handle, linkPolicy) { this.policy = linkPolicy; this.session = session; this.handle = handle; - this.remoteHandle = undefined; + this.remote = { handle: undefined }; this._onAttach = []; if (this.policy && this.policy.reattach) { @@ -148,8 +148,10 @@ Link.prototype._attachReceived = function(attachFrame) { this.linkSM.attachReceived(); // process params. - this.remoteHandle = attachFrame.handle; - this.session._linksByRemoteHandle[this.remoteHandle] = this; + this.remote.handle = attachFrame.handle; + this.remote.attach = attachFrame; + + this.session._linksByRemoteHandle[this.remote.handle] = this; debug(this.name + ': attached CH=[' + this.session.channel + '=>' + attachFrame.channel + '], Handle=[' + this.handle + '=>' + attachFrame.handle + ']'); this.emit(Link.Attached, this); @@ -199,9 +201,10 @@ Link.prototype._detached = function(frame) { this.emit(Link.ErrorReceived, u.wrapProtocolError(frame.error)); } - if (this.remoteHandle !== undefined) { - delete this.session._linksByRemoteHandle[this.remoteHandle]; - this.remoteHandle = undefined; + this.remote.detach = frame; + if (this.remote.handle !== undefined) { + delete this.session._linksByRemoteHandle[this.remote.handle]; + this.remote.handle = undefined; } this.emit(Link.Detached, { closed: frame.closed, error: u.wrapProtocolError(frame.error) });