Skip to content

Commit

Permalink
fixup! lib, test: use ping-pong instead of heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
nechaido committed Nov 22, 2017
1 parent 670d725 commit c93dfc0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
9 changes: 3 additions & 6 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Connection extends EventEmitter {

// Send a pong message
//
pong(messageId) {
_pong(messageId) {
if (this._closed) {
return;
}
Expand All @@ -252,10 +252,7 @@ class Connection extends EventEmitter {
if (this._closed) {
return;
}
const pingId = this._nextMessageId;
this.ping(() => {
this.session.unbufferUpTo(pingId);
});
this.ping();
};

this._heartbeatInterval = setInterval(heartbeat, interval);
Expand Down Expand Up @@ -683,7 +680,7 @@ class Connection extends EventEmitter {
//
_processPingMessage(message) {
const messageId = message.ping[0];
this.pong(messageId);
this._pong(messageId);
this.session._onMessageRecieved(messageId);
}

Expand Down
11 changes: 3 additions & 8 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class Session extends Map {

Object.preventExtensions(this);
}

unbufferUpTo(id) {
for (let i = this.guaranteedDeliveredCount + 1; i <= id; i++) {
this.buffer.delete(i);
}
}

_bufferMessage(id, message) {
this.buffer.set(Math.abs(id), message);
this.latestBufferedMessageId = id;
Expand All @@ -53,7 +46,9 @@ class Session extends Map {
if (this.connection) {
this.connection.close();
}
this.unbufferUpTo(recievedCount);
for (let i = this.guaranteedDeliveredCount + 1; i <= recievedCount; i++) {
this.buffer.delete(i);
}
this.connection = newConnection;
this.guaranteedDeliveredCount = recievedCount;
}
Expand Down

0 comments on commit c93dfc0

Please sign in to comment.