Skip to content

Commit

Permalink
chore: include Engine.IO client v4
Browse files Browse the repository at this point in the history
The ping-pong mechanism has been reverted (server now sends a ping and
expects a pong from the client), so we cannot compute the latency like
we did in previous versions.

Release notes: https://github.com/socketio/engine.io-client/releases/tag/4.0.0
  • Loading branch information
darrachequesne committed Oct 6, 2020
1 parent f2f4a4c commit be8c314
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 49 deletions.
7 changes: 0 additions & 7 deletions build/manager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export declare class Manager extends Emitter {
private _reconnectionDelayMax;
private _timeout;
private connecting;
private lastPing;
private encoding;
private packetBuffer;
private encoder;
Expand Down Expand Up @@ -118,12 +117,6 @@ export declare class Manager extends Emitter {
* @api private
*/
onping(): void;
/**
* Called upon a packet.
*
* @api private
*/
onpong(): void;
/**
* Called with data.
*
Expand Down
12 changes: 0 additions & 12 deletions build/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class Manager extends component_emitter_1.default {
this.nsps = {};
this.subs = [];
this.connecting = [];
this.lastPing = null;
this.packetBuffer = [];
if (uri && "object" === typeof uri) {
opts = uri;
Expand Down Expand Up @@ -337,7 +336,6 @@ class Manager extends component_emitter_1.default {
const socket = this.engine;
this.subs.push(on_1.on(socket, "data", component_bind_1.default(this, "ondata")));
this.subs.push(on_1.on(socket, "ping", component_bind_1.default(this, "onping")));
this.subs.push(on_1.on(socket, "pong", component_bind_1.default(this, "onpong")));
this.subs.push(on_1.on(socket, "error", component_bind_1.default(this, "onerror")));
this.subs.push(on_1.on(socket, "close", component_bind_1.default(this, "onclose")));
this.subs.push(on_1.on(this.decoder, "decoded", component_bind_1.default(this, "ondecoded")));
Expand All @@ -348,17 +346,8 @@ class Manager extends component_emitter_1.default {
* @api private
*/
onping() {
this.lastPing = Date.now();
this.emitAll("ping");
}
/**
* Called upon a packet.
*
* @api private
*/
onpong() {
this.emitAll("pong", Date.now() - this.lastPing);
}
/**
* Called with data.
*
Expand Down Expand Up @@ -476,7 +465,6 @@ class Manager extends component_emitter_1.default {
}
this.packetBuffer = [];
this.encoding = false;
this.lastPing = null;
this.decoder.destroy();
}
/**
Expand Down
13 changes: 0 additions & 13 deletions lib/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class Manager extends Emitter {
private _timeout: any;

private connecting: Array<Socket> = [];
private lastPing: number = null;
private encoding: boolean;
private packetBuffer: Array<any> = [];
private encoder: Encoder;
Expand Down Expand Up @@ -363,7 +362,6 @@ export class Manager extends Emitter {
const socket = this.engine;
this.subs.push(on(socket, "data", bind(this, "ondata")));
this.subs.push(on(socket, "ping", bind(this, "onping")));
this.subs.push(on(socket, "pong", bind(this, "onpong")));
this.subs.push(on(socket, "error", bind(this, "onerror")));
this.subs.push(on(socket, "close", bind(this, "onclose")));
this.subs.push(on(this.decoder, "decoded", bind(this, "ondecoded")));
Expand All @@ -375,19 +373,9 @@ export class Manager extends Emitter {
* @api private
*/
onping() {
this.lastPing = Date.now();
this.emitAll("ping");
}

/**
* Called upon a packet.
*
* @api private
*/
onpong() {
this.emitAll("pong", Date.now() - this.lastPing);
}

/**
* Called with data.
*
Expand Down Expand Up @@ -515,7 +503,6 @@ export class Manager extends Emitter {

this.packetBuffer = [];
this.encoding = false;
this.lastPing = null;

this.decoder.destroy();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"component-bind": "1.0.0",
"component-emitter": "~1.3.0",
"debug": "~3.1.0",
"engine.io-client": "~3.4.0",
"engine.io-client": "~4.0.0",
"has-binary2": "~1.0.2",
"indexof": "0.0.1",
"parseqs": "0.0.6",
Expand Down
16 changes: 0 additions & 16 deletions test/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ describe("socket", function () {
}, 300);
});

it("should ping and pong with latency", (done) => {
const socket = io({ forceNew: true });
socket.on("connect", () => {
let pinged;
socket.once("ping", () => {
pinged = true;
});
socket.once("pong", (ms) => {
expect(pinged).to.be(true);
expect(ms).to.be.a("number");
socket.disconnect();
done();
});
});
});

it("should change socket.id upon reconnection", (done) => {
const socket = io({ forceNew: true });
socket.on("connect", () => {
Expand Down

0 comments on commit be8c314

Please sign in to comment.