Skip to content

Commit

Permalink
refactor: remove useless references
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Nov 9, 2023
1 parent f27a6c3 commit 2ffe924
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export class Socket extends EventEmitter {
private packetsFn: Array<() => void>;
private sentCallbackFn: any[];
private cleanupFn: any[];
private checkIntervalTimer;
private upgradeTimeoutTimer;
private pingTimeoutTimer;
private pingIntervalTimer;

Expand Down Expand Up @@ -81,8 +79,6 @@ export class Socket extends EventEmitter {
// see https://github.com/fails-components/webtransport/issues/114
}

this.checkIntervalTimer = null;
this.upgradeTimeoutTimer = null;
this.pingTimeoutTimer = null;
this.pingIntervalTimer = null;

Expand Down Expand Up @@ -265,21 +261,23 @@ export class Socket extends EventEmitter {
this.upgrading = true;

// set transport upgrade timer
this.upgradeTimeoutTimer = setTimeout(() => {
const upgradeTimeoutTimer = setTimeout(() => {
debug("client did not complete upgrade - closing transport");
cleanup();
if ("open" === transport.readyState) {
transport.close();
}
}, this.server.opts.upgradeTimeout);

let checkIntervalTimer;

const onPacket = (packet) => {
if ("ping" === packet.type && "probe" === packet.data) {
debug("got probe ping packet, sending pong");
transport.send([{ type: "pong", data: "probe" }]);
this.emit("upgrading", transport);
clearInterval(this.checkIntervalTimer);
this.checkIntervalTimer = setInterval(check, 100);
clearInterval(checkIntervalTimer);
checkIntervalTimer = setInterval(check, 100);
} else if ("upgrade" === packet.type && this.readyState !== "closed") {
debug("got upgrade packet - upgrading");
cleanup();
Expand Down Expand Up @@ -311,11 +309,8 @@ export class Socket extends EventEmitter {
const cleanup = () => {
this.upgrading = false;

clearInterval(this.checkIntervalTimer);
this.checkIntervalTimer = null;

clearTimeout(this.upgradeTimeoutTimer);
this.upgradeTimeoutTimer = null;
clearInterval(checkIntervalTimer);
clearTimeout(upgradeTimeoutTimer);

transport.removeListener("packet", onPacket);
transport.removeListener("close", onTransportClose);
Expand Down Expand Up @@ -384,9 +379,6 @@ export class Socket extends EventEmitter {
clearTimeout(this.pingIntervalTimer);
clearTimeout(this.pingTimeoutTimer);

clearInterval(this.checkIntervalTimer);
this.checkIntervalTimer = null;
clearTimeout(this.upgradeTimeoutTimer);
// clean writeBuffer in next tick, so developers can still
// grab the writeBuffer on 'close' event
process.nextTick(() => {
Expand Down

0 comments on commit 2ffe924

Please sign in to comment.