Skip to content

Commit

Permalink
refactor(link): store remote attach/detach in link.remote
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Apr 4, 2016
1 parent c585b1a commit 82daecb
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) });
Expand Down

0 comments on commit 82daecb

Please sign in to comment.