From fc5dc6b91e07151564fcfa13eb1b248468bf818a Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 31 Mar 2021 09:41:21 +0200 Subject: [PATCH 1/3] refactor: use ES6 syntax in tests --- test/arraybuffer/index.js | 2 +- test/arraybuffer/polling.js | 44 +++++----- test/arraybuffer/ws.js | 48 +++++------ test/binary-fallback.js | 14 +-- test/blob/index.js | 2 +- test/blob/polling.js | 36 ++++---- test/blob/ws.js | 54 ++++++------ test/connection.js | 94 ++++++++++---------- test/engine.io-client.js | 34 ++++---- test/index.js | 2 +- test/socket.js | 10 +-- test/support/env.js | 2 +- test/support/server.js | 24 +++--- test/transport.js | 152 ++++++++++++++++----------------- test/transports/polling-xhr.js | 24 +++--- test/xmlhttprequest.js | 56 ++++++------ 16 files changed, 299 insertions(+), 299 deletions(-) diff --git a/test/arraybuffer/index.js b/test/arraybuffer/index.js index 9daadf990..4208b3ce8 100644 --- a/test/arraybuffer/index.js +++ b/test/arraybuffer/index.js @@ -1,4 +1,4 @@ -var env = require("../support/env"); +const env = require("../support/env"); require("./polling.js"); if (env.wsSupport && !env.isOldSimulator && !env.isAndroid && !env.isIE11) { diff --git a/test/arraybuffer/polling.js b/test/arraybuffer/polling.js index b320adcd3..033403ba2 100644 --- a/test/arraybuffer/polling.js +++ b/test/arraybuffer/polling.js @@ -1,19 +1,19 @@ -var expect = require("expect.js"); -var eio = require("../../"); +const expect = require("expect.js"); +const eio = require("../../"); describe("arraybuffer", function() { this.timeout(30000); - it("should be able to receive binary data when bouncing it back (polling)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data when bouncing it back (polling)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket({ transports: ["polling"] }); + const socket = new eio.Socket({ transports: ["polling"] }); socket.binaryType = "arraybuffer"; - socket.on("open", function() { + socket.on("open", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { if (data === "hi") return; expect(data).to.be.an(ArrayBuffer); @@ -24,19 +24,19 @@ describe("arraybuffer", function() { }); }); - it("should be able to receive binary data and a multibyte utf-8 string (polling)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data and a multibyte utf-8 string (polling)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var msg = 0; - var socket = new eio.Socket({ transports: ["polling"] }); + let msg = 0; + const socket = new eio.Socket({ transports: ["polling"] }); socket.binaryType = "arraybuffer"; - socket.on("open", function() { + socket.on("open", () => { socket.send(binaryData); socket.send("cash money €€€"); - socket.on("message", function(data) { + socket.on("message", data => { if (data === "hi") return; if (msg === 0) { @@ -52,20 +52,20 @@ describe("arraybuffer", function() { }); }); - it("should be able to receive binary data when forcing base64 (polling)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data when forcing base64 (polling)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket({ forceBase64: true }); + const socket = new eio.Socket({ forceBase64: true }); socket.binaryType = "arraybuffer"; - socket.on("open", function() { + socket.on("open", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { if (typeof data === "string") return; expect(data).to.be.an(ArrayBuffer); - var ia = new Int8Array(data); + const ia = new Int8Array(data); expect(ia).to.eql(binaryData); socket.close(); done(); diff --git a/test/arraybuffer/ws.js b/test/arraybuffer/ws.js index c031c0710..86408174d 100644 --- a/test/arraybuffer/ws.js +++ b/test/arraybuffer/ws.js @@ -1,20 +1,20 @@ -var expect = require("expect.js"); -var eio = require("../../"); +const expect = require("expect.js"); +const eio = require("../../"); describe("arraybuffer", function() { this.timeout(30000); - it("should be able to receive binary data when bouncing it back (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data when bouncing it back (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket(); + const socket = new eio.Socket(); socket.binaryType = "arraybuffer"; - socket.on("open", function() { - socket.on("upgrade", function() { + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { if (typeof data === "string") return; expect(data).to.be.an(ArrayBuffer); @@ -27,20 +27,20 @@ describe("arraybuffer", function() { }); }); - it("should be able to receive binary data and a multibyte utf-8 string (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data and a multibyte utf-8 string (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var msg = 0; - var socket = new eio.Socket(); + let msg = 0; + const socket = new eio.Socket(); socket.binaryType = "arraybuffer"; - socket.on("open", function() { - socket.on("upgrade", function() { + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(binaryData); socket.send("cash money €€€"); - socket.on("message", function(data) { + socket.on("message", data => { if (data === "hi") return; if (msg === 0) { @@ -57,17 +57,17 @@ describe("arraybuffer", function() { }); }); - it("should be able to receive binary data when bouncing it back and forcing base64 (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data when bouncing it back and forcing base64 (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket({ forceBase64: true }); + const socket = new eio.Socket({ forceBase64: true }); socket.binaryType = "arraybuffer"; - socket.on("open", function() { - socket.on("upgrade", function() { + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { if (typeof data === "string") return; expect(data).to.be.an(ArrayBuffer); diff --git a/test/binary-fallback.js b/test/binary-fallback.js index 9e418b672..7255c2b7b 100644 --- a/test/binary-fallback.js +++ b/test/binary-fallback.js @@ -1,15 +1,15 @@ -var expect = require("expect.js"); -var eio = require("../"); +const expect = require("expect.js"); +const eio = require("../"); describe("binary fallback", function() { this.timeout(10000); - it("should be able to receive binary data when ArrayBuffer not available (polling)", function(done) { - var socket = new eio.Socket({ forceBase64: true }); - socket.on("open", function() { + it("should be able to receive binary data when ArrayBuffer not available (polling)", done => { + const socket = new eio.Socket({ forceBase64: true }); + socket.on("open", () => { socket.send("give binary"); - var firstPacket = true; - socket.on("message", function(data) { + let firstPacket = true; + socket.on("message", data => { if (firstPacket) { firstPacket = false; return; diff --git a/test/blob/index.js b/test/blob/index.js index 9daadf990..4208b3ce8 100644 --- a/test/blob/index.js +++ b/test/blob/index.js @@ -1,4 +1,4 @@ -var env = require("../support/env"); +const env = require("../support/env"); require("./polling.js"); if (env.wsSupport && !env.isOldSimulator && !env.isAndroid && !env.isIE11) { diff --git a/test/blob/polling.js b/test/blob/polling.js index 12ea3e287..7cc460748 100644 --- a/test/blob/polling.js +++ b/test/blob/polling.js @@ -1,28 +1,28 @@ -var expect = require("expect.js"); -var eio = require("../../"); +const expect = require("expect.js"); +const eio = require("../../"); -var Blob = require("blob"); +const Blob = require("blob"); describe("blob", function() { this.timeout(30000); - it("should be able to receive binary data as blob when bouncing it back (polling)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data as blob when bouncing it back (polling)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket(); + const socket = new eio.Socket(); socket.binaryType = "blob"; - socket.on("open", function() { + socket.on("open", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { if (typeof data === "string") return; expect(data).to.be.a(Blob); - var fr = new FileReader(); + const fr = new FileReader(); fr.onload = function() { - var ab = this.result; - var ia = new Int8Array(ab); + const ab = this.result; + const ia = new Int8Array(ab); expect(ia).to.eql(binaryData); socket.close(); done(); @@ -32,15 +32,15 @@ describe("blob", function() { }); }); - it("should be able to send data as a blob when bouncing it back (polling)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to send data as a blob when bouncing it back (polling)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket(); - socket.on("open", function() { + const socket = new eio.Socket(); + socket.on("open", () => { socket.send(new Blob([binaryData.buffer])); - socket.on("message", function(data) { + socket.on("message", data => { if (typeof data === "string") return; expect(data).to.be.an(ArrayBuffer); diff --git a/test/blob/ws.js b/test/blob/ws.js index 34ce17882..67a91fe40 100644 --- a/test/blob/ws.js +++ b/test/blob/ws.js @@ -1,27 +1,27 @@ -var expect = require("expect.js"); -var eio = require("../../"); +const expect = require("expect.js"); +const eio = require("../../"); -var Blob = require("blob"); +const Blob = require("blob"); describe("blob", function() { this.timeout(30000); - it("should be able to receive binary data as blob when bouncing it back (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to receive binary data as blob when bouncing it back (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket(); + const socket = new eio.Socket(); socket.binaryType = "blob"; - socket.on("open", function() { - socket.on("upgrade", function() { + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(binaryData); - socket.on("message", function(data) { + socket.on("message", data => { expect(data).to.be.a(Blob); - var fr = new FileReader(); + const fr = new FileReader(); fr.onload = function() { - var ab = this.result; - var ia = new Int8Array(ab); + const ab = this.result; + const ia = new Int8Array(ab); expect(ia).to.eql(binaryData); socket.close(); done(); @@ -32,16 +32,16 @@ describe("blob", function() { }); }); - it("should be able to send data as a blob when bouncing it back (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to send data as a blob when bouncing it back (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket(); - socket.on("open", function() { - socket.on("upgrade", function() { + const socket = new eio.Socket(); + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(new Blob([binaryData.buffer])); - socket.on("message", function(data) { + socket.on("message", data => { expect(data).to.be.an(ArrayBuffer); expect(new Int8Array(data)).to.eql(binaryData); socket.close(); @@ -51,16 +51,16 @@ describe("blob", function() { }); }); - it("should be able to send data as a blob encoded into base64 when bouncing it back (ws)", function(done) { - var binaryData = new Int8Array(5); - for (var i = 0; i < 5; i++) { + it("should be able to send data as a blob encoded into base64 when bouncing it back (ws)", done => { + const binaryData = new Int8Array(5); + for (let i = 0; i < 5; i++) { binaryData[i] = i; } - var socket = new eio.Socket({ forceBase64: true }); - socket.on("open", function() { - socket.on("upgrade", function() { + const socket = new eio.Socket({ forceBase64: true }); + socket.on("open", () => { + socket.on("upgrade", () => { socket.send(new Blob([binaryData.buffer])); - socket.on("message", function(data) { + socket.on("message", data => { expect(data).to.be.an(ArrayBuffer); expect(new Int8Array(data)).to.eql(binaryData); socket.close(); diff --git a/test/connection.js b/test/connection.js index 39d6fdf50..02fd21f06 100644 --- a/test/connection.js +++ b/test/connection.js @@ -5,10 +5,10 @@ const env = require("./support/env"); describe("connection", function() { this.timeout(20000); - it("should connect to localhost", function(done) { + it("should connect to localhost", done => { const socket = new Socket(); - socket.on("open", function() { - socket.on("message", function(data) { + socket.on("open", () => { + socket.on("message", data => { expect(data).to.equal("hi"); socket.close(); done(); @@ -16,11 +16,11 @@ describe("connection", function() { }); }); - it("should receive multibyte utf-8 strings with polling", function(done) { + it("should receive multibyte utf-8 strings with polling", done => { const socket = new Socket(); - socket.on("open", function() { + socket.on("open", () => { socket.send("cash money €€€"); - socket.on("message", function(data) { + socket.on("message", data => { if ("hi" === data) return; expect(data).to.be("cash money €€€"); socket.close(); @@ -29,13 +29,13 @@ describe("connection", function() { }); }); - it("should receive emoji", function(done) { + it("should receive emoji", done => { const socket = new Socket(); - socket.on("open", function() { + socket.on("open", () => { socket.send( "\uD800\uDC00-\uDB7F\uDFFF\uDB80\uDC00-\uDBFF\uDFFF\uE000-\uF8FF" ); - socket.on("message", function(data) { + socket.on("message", data => { if ("hi" === data) return; expect(data).to.be( "\uD800\uDC00-\uDB7F\uDFFF\uDB80\uDC00-\uDBFF\uDFFF\uE000-\uF8FF" @@ -46,16 +46,16 @@ describe("connection", function() { }); }); - it("should not send packets if socket closes", function(done) { + it("should not send packets if socket closes", done => { const socket = new Socket(); - socket.on("open", function() { - var noPacket = true; - socket.on("packetCreate", function() { + socket.on("open", () => { + let noPacket = true; + socket.on("packetCreate", () => { noPacket = false; }); socket.close(); socket.send("hi"); - setTimeout(function() { + setTimeout(() => { expect(noPacket).to.be(true); done(); }, 1200); @@ -64,11 +64,11 @@ describe("connection", function() { // no `Worker` on old IE if (typeof Worker !== "undefined") { - it("should work in a worker", function(done) { - var worker = new Worker("/test/support/worker.js"); - var msg = 0; - var utf8yay = "пойду спать всем спокойной ночи"; - worker.onmessage = function(e) { + it("should work in a worker", done => { + const worker = new Worker("/test/support/worker.js"); + let msg = 0; + const utf8yay = "пойду спать всем спокойной ночи"; + worker.onmessage = e => { msg++; if (msg === 1) { expect(e.data).to.be("hi"); @@ -83,51 +83,51 @@ describe("connection", function() { }; function testBinary(data) { - var byteArray = new Uint8Array(data); - for (var i = 0; i < byteArray.byteLength; i++) { + const byteArray = new Uint8Array(data); + for (let i = 0; i < byteArray.byteLength; i++) { expect(byteArray[i]).to.be(i); } } }); } - it("should not connect at all when JSONP forced and disabled", function(done) { + it("should not connect at all when JSONP forced and disabled", done => { const socket = new Socket({ transports: ["polling"], forceJSONP: true, jsonp: false }); - socket.on("error", function(msg) { + socket.on("error", msg => { expect(msg).to.be("No transports available"); done(); }); }); if (env.wsSupport && !env.isOldSimulator && !env.isAndroid && !env.isIE11) { - it("should connect with ws when JSONP forced and disabled", function(done) { + it("should connect with ws when JSONP forced and disabled", done => { const socket = new Socket({ transports: ["polling", "websocket"], forceJSONP: true, jsonp: false }); - socket.on("open", function() { + socket.on("open", () => { expect(socket.transport.name).to.be("websocket"); socket.close(); done(); }); }); - it("should defer close when upgrading", function(done) { + it("should defer close when upgrading", done => { const socket = new Socket(); - socket.on("open", function() { - var upgraded = false; + socket.on("open", () => { + let upgraded = false; socket - .on("upgrade", function() { + .on("upgrade", () => { upgraded = true; }) - .on("upgrading", function() { - socket.on("close", function() { + .on("upgrading", () => { + socket.on("close", () => { expect(upgraded).to.be(true); done(); }); @@ -136,16 +136,16 @@ describe("connection", function() { }); }); - it("should close on upgradeError if closing is deferred", function(done) { + it("should close on upgradeError if closing is deferred", done => { const socket = new Socket(); - socket.on("open", function() { - var upgradeError = false; + socket.on("open", () => { + let upgradeError = false; socket - .on("upgradeError", function() { + .on("upgradeError", () => { upgradeError = true; }) - .on("upgrading", function() { - socket.on("close", function() { + .on("upgrading", () => { + socket.on("close", () => { expect(upgradeError).to.be(true); done(); }); @@ -155,33 +155,33 @@ describe("connection", function() { }); }); - it("should not send packets if closing is deferred", function(done) { + it("should not send packets if closing is deferred", done => { const socket = new Socket(); - socket.on("open", function() { - var noPacket = true; - socket.on("upgrading", function() { - socket.on("packetCreate", function() { + socket.on("open", () => { + let noPacket = true; + socket.on("upgrading", () => { + socket.on("packetCreate", () => { noPacket = false; }); socket.close(); socket.send("hi"); }); - setTimeout(function() { + setTimeout(() => { expect(noPacket).to.be(true); done(); }, 1200); }); }); - it("should send all buffered packets if closing is deferred", function(done) { + it("should send all buffered packets if closing is deferred", done => { const socket = new Socket(); - socket.on("open", function() { + socket.on("open", () => { socket - .on("upgrading", function() { + .on("upgrading", () => { socket.send("hi"); socket.close(); }) - .on("close", function() { + .on("close", () => { expect(socket.writeBuffer).to.have.length(0); done(); }); diff --git a/test/engine.io-client.js b/test/engine.io-client.js index 63584227d..608571c11 100644 --- a/test/engine.io-client.js +++ b/test/engine.io-client.js @@ -6,89 +6,89 @@ const expectedPort = ? "443" : "80"; -describe("engine.io-client", function() { +describe("engine.io-client", () => { let open; - before(function() { + before(() => { open = eio.Socket.prototype.open; // override Socket#open to not connect - eio.Socket.prototype.open = function() {}; + eio.Socket.prototype.open = () => {}; }); - after(function() { + after(() => { eio.Socket.prototype.open = open; }); - it("should expose protocol number", function() { + it("should expose protocol number", () => { expect(eio.protocol).to.be.a("number"); }); - it("should properly parse http uri without port", function() { + it("should properly parse http uri without port", () => { const client = eio("http://localhost"); expect(client.port).to.be("80"); }); - it("should properly parse https uri without port", function() { + it("should properly parse https uri without port", () => { const client = eio("https://localhost"); expect(client.hostname).to.be("localhost"); expect(client.port).to.be("443"); }); - it("should properly parse wss uri without port", function() { + it("should properly parse wss uri without port", () => { const client = eio("wss://localhost"); expect(client.hostname).to.be("localhost"); expect(client.port).to.be("443"); }); - it("should properly parse wss uri with port", function() { + it("should properly parse wss uri with port", () => { const client = eio("wss://localhost:2020"); expect(client.hostname).to.be("localhost"); expect(client.port).to.be("2020"); }); - it("should properly parse a host without port", function() { + it("should properly parse a host without port", () => { const client = eio({ host: "localhost" }); expect(client.hostname).to.be("localhost"); expect(client.port).to.be(expectedPort); }); - it("should properly parse a host with port", function() { + it("should properly parse a host with port", () => { const client = eio({ host: "localhost", port: "8080" }); expect(client.hostname).to.be("localhost"); expect(client.port).to.be("8080"); }); - it("should properly parse an IPv6 uri without port", function() { + it("should properly parse an IPv6 uri without port", () => { const client = eio("http://[::1]"); expect(client.hostname).to.be("::1"); expect(client.port).to.be("80"); }); - it("should properly parse an IPv6 uri with port", function() { + it("should properly parse an IPv6 uri with port", () => { const client = eio("http://[::1]:8080"); expect(client.hostname).to.be("::1"); expect(client.port).to.be("8080"); }); - it("should properly parse an IPv6 host without port (1/2)", function() { + it("should properly parse an IPv6 host without port (1/2)", () => { const client = eio({ host: "[::1]" }); expect(client.hostname).to.be("::1"); expect(client.port).to.be(expectedPort); }); - it("should properly parse an IPv6 host without port (2/2)", function() { + it("should properly parse an IPv6 host without port (2/2)", () => { const client = eio({ secure: true, host: "[::1]" }); expect(client.hostname).to.be("::1"); expect(client.port).to.be("443"); }); - it("should properly parse an IPv6 host with port", function() { + it("should properly parse an IPv6 host with port", () => { const client = eio({ host: "[::1]", port: "8080" }); expect(client.hostname).to.be("::1"); expect(client.port).to.be("8080"); }); - it("should properly parse an IPv6 host without brace", function() { + it("should properly parse an IPv6 host without brace", () => { const client = eio({ host: "::1" }); expect(client.hostname).to.be("::1"); expect(client.port).to.be(expectedPort); diff --git a/test/index.js b/test/index.js index 9bbc98a16..e71a7763a 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,7 @@ if (env.browser) { require("./node"); } -var Blob = require("blob"); +const Blob = require("blob"); require("./engine.io-client"); require("./socket"); diff --git a/test/socket.js b/test/socket.js index cc0ce5644..a9524d359 100644 --- a/test/socket.js +++ b/test/socket.js @@ -1,12 +1,12 @@ -var expect = require("expect.js"); -var eio = require("../"); +const expect = require("expect.js"); +const eio = require("../"); describe("Socket", function() { this.timeout(10000); - describe("filterUpgrades", function() { - it("should return only available transports", function() { - var socket = new eio.Socket({ transports: ["polling"] }); + describe("filterUpgrades", () => { + it("should return only available transports", () => { + const socket = new eio.Socket({ transports: ["polling"] }); expect(socket.filterUpgrades(["polling", "websocket"])).to.eql([ "polling" ]); diff --git a/test/support/env.js b/test/support/env.js index 645c0fd5f..b1f245d9c 100644 --- a/test/support/env.js +++ b/test/support/env.js @@ -11,7 +11,7 @@ exports.wsSupport = !!( window.MozWebSocket ); -var userAgent = typeof navigator !== "undefined" ? navigator.userAgent : ""; +const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : ""; exports.isOldSimulator = ~userAgent.indexOf("iPhone OS 4") || ~userAgent.indexOf("iPhone OS 5"); exports.isIE8 = /MSIE 8/.test(userAgent); diff --git a/test/support/server.js b/test/support/server.js index 609148e81..400feedaf 100644 --- a/test/support/server.js +++ b/test/support/server.js @@ -1,18 +1,18 @@ // this is a test server to support tests which make requests -var express = require("express"); -var app = express(); -var join = require("path").join; -var http = require("http").Server(app); -var server = require("engine.io").attach(http, { pingInterval: 500 }); -var webpack = require("webpack"); +const express = require("express"); +const app = express(); +const join = require("path").join; +const http = require("http").Server(app); +const server = require("engine.io").attach(http, { pingInterval: 500 }); +const webpack = require("webpack"); const path = require("path"); -var webpackConfig = require("../../support/prod.config.js"); +const webpackConfig = require("../../support/prod.config.js"); webpackConfig.output.path = path.resolve(__dirname, "public"); -webpack(webpackConfig, function(err, stats) { +webpack(webpackConfig, (err, stats) => { if (err) console.log(err); }); @@ -21,14 +21,14 @@ http.listen(process.env.ZUUL_PORT || 3000); // serve worker.js and engine.io.js as raw file app.use("/test/support", express.static(join(__dirname, "public"))); -server.on("connection", function(socket) { +server.on("connection", socket => { socket.send("hi"); // Bounce any received messages back - socket.on("message", function(data) { + socket.on("message", data => { if (data === "give binary") { - var abv = new Int8Array(5); - for (var i = 0; i < 5; i++) { + const abv = new Int8Array(5); + for (let i = 0; i < 5; i++) { abv[i] = i; } socket.send(abv); diff --git a/test/transport.js b/test/transport.js index 4dad77e10..81788fcc9 100644 --- a/test/transport.js +++ b/test/transport.js @@ -1,52 +1,52 @@ -var expect = require("expect.js"); -var eio = require("../"); -var env = require("./support/env"); +const expect = require("expect.js"); +const eio = require("../"); +const env = require("./support/env"); // Disables eslint to capitalise constructor names /* eslint-disable new-cap */ -describe("Transport", function() { - describe("rememberUpgrade", function() { - it("should remember websocket connection", function(done) { - var socket = new eio.Socket(); +describe("Transport", () => { + describe("rememberUpgrade", () => { + it("should remember websocket connection", done => { + const socket = new eio.Socket(); expect(socket.transport.name).to.be("polling"); - var timedout = false; - var timeout = setTimeout(function() { + let timedout = false; + const timeout = setTimeout(() => { timedout = true; socket.close(); done(); }, 300); - socket.on("upgrade", function(transport) { + socket.on("upgrade", transport => { if (timedout) return; clearTimeout(timeout); socket.close(); if (transport.name === "websocket") { - var socket2 = new eio.Socket({ rememberUpgrade: true }); + const socket2 = new eio.Socket({ rememberUpgrade: true }); expect(socket2.transport.name).to.be("websocket"); } done(); }); }); - it("should not remember websocket connection", function(done) { - var socket = new eio.Socket(); + it("should not remember websocket connection", done => { + const socket = new eio.Socket(); expect(socket.transport.name).to.be("polling"); - var timedout = false; - var timeout = setTimeout(function() { + let timedout = false; + const timeout = setTimeout(() => { timedout = true; socket.close(); done(); }, 300); - socket.on("upgrade", function(transport) { + socket.on("upgrade", transport => { if (timedout) return; clearTimeout(timeout); socket.close(); if (transport.name === "websocket") { - var socket2 = new eio.Socket({ rememberUpgrade: false }); + const socket2 = new eio.Socket({ rememberUpgrade: false }); expect(socket2.transport.name).to.not.be("websocket"); } done(); @@ -54,21 +54,21 @@ describe("Transport", function() { }); }); - describe("public constructors", function() { - it("should include Transport", function() { + describe("public constructors", () => { + it("should include Transport", () => { expect(eio.Transport).to.be.a("function"); }); - it("should include Polling and WebSocket", function() { + it("should include Polling and WebSocket", () => { expect(eio.transports).to.be.an("object"); expect(eio.transports.polling).to.be.a("function"); expect(eio.transports.websocket).to.be.a("function"); }); }); - describe("transport uris", function() { - it("should generate an http uri", function() { - var polling = new eio.transports.polling({ + describe("transport uris", () => { + it("should generate an http uri", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", secure: false, @@ -78,8 +78,8 @@ describe("Transport", function() { expect(polling.uri()).to.contain("http://localhost/engine.io?sid=test"); }); - it("should generate an http uri w/o a port", function() { - var polling = new eio.transports.polling({ + it("should generate an http uri w/o a port", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", secure: false, @@ -90,8 +90,8 @@ describe("Transport", function() { expect(polling.uri()).to.contain("http://localhost/engine.io?sid=test"); }); - it("should generate an http uri with a port", function() { - var polling = new eio.transports.polling({ + it("should generate an http uri with a port", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", secure: false, @@ -104,8 +104,8 @@ describe("Transport", function() { ); }); - it("should generate an https uri w/o a port", function() { - var polling = new eio.transports.polling({ + it("should generate an https uri w/o a port", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", secure: true, @@ -116,8 +116,8 @@ describe("Transport", function() { expect(polling.uri()).to.contain("https://localhost/engine.io?sid=test"); }); - it("should generate a timestamped uri", function() { - var polling = new eio.transports.polling({ + it("should generate a timestamped uri", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", timestampParam: "t", @@ -128,8 +128,8 @@ describe("Transport", function() { ); }); - it("should generate an ipv6 uri", function() { - var polling = new eio.transports.polling({ + it("should generate an ipv6 uri", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "::1", secure: false, @@ -139,8 +139,8 @@ describe("Transport", function() { expect(polling.uri()).to.contain("http://[::1]/engine.io"); }); - it("should generate an ipv6 uri with port", function() { - var polling = new eio.transports.polling({ + it("should generate an ipv6 uri with port", () => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "::1", secure: false, @@ -150,8 +150,8 @@ describe("Transport", function() { expect(polling.uri()).to.contain("http://[::1]:8080/engine.io"); }); - it("should generate a ws uri", function() { - var ws = new eio.transports.websocket({ + it("should generate a ws uri", () => { + const ws = new eio.transports.websocket({ path: "/engine.io", hostname: "test", secure: false, @@ -161,8 +161,8 @@ describe("Transport", function() { expect(ws.uri()).to.be("ws://test/engine.io?transport=websocket"); }); - it("should generate a wss uri", function() { - var ws = new eio.transports.websocket({ + it("should generate a wss uri", () => { + const ws = new eio.transports.websocket({ path: "/engine.io", hostname: "test", secure: true, @@ -172,8 +172,8 @@ describe("Transport", function() { expect(ws.uri()).to.be("wss://test/engine.io"); }); - it("should timestamp ws uris", function() { - var ws = new eio.transports.websocket({ + it("should timestamp ws uris", () => { + const ws = new eio.transports.websocket({ path: "/engine.io", hostname: "localhost", timestampParam: "woot", @@ -184,8 +184,8 @@ describe("Transport", function() { ); }); - it("should generate a ws ipv6 uri", function() { - var ws = new eio.transports.websocket({ + it("should generate a ws ipv6 uri", () => { + const ws = new eio.transports.websocket({ path: "/engine.io", hostname: "::1", secure: false, @@ -195,8 +195,8 @@ describe("Transport", function() { expect(ws.uri()).to.be("ws://[::1]/engine.io"); }); - it("should generate a ws ipv6 uri with port", function() { - var ws = new eio.transports.websocket({ + it("should generate a ws ipv6 uri with port", () => { + const ws = new eio.transports.websocket({ path: "/engine.io", hostname: "::1", secure: false, @@ -209,25 +209,25 @@ describe("Transport", function() { // these are server only if (!env.browser) { - describe("options", function() { - it("should accept an `agent` option for WebSockets", function(done) { - var polling = new eio.transports.websocket({ + describe("options", () => { + it("should accept an `agent` option for WebSockets", done => { + const polling = new eio.transports.websocket({ path: "/engine.io", hostname: "localhost", agent: { - addRequest: function() { + addRequest: () => { done(); } } }); polling.doOpen(); }); - it("should accept an `agent` option for XMLHttpRequest", function(done) { - var polling = new eio.transports.polling({ + it("should accept an `agent` option for XMLHttpRequest", done => { + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", agent: { - addRequest: function() { + addRequest: () => { done(); } } @@ -235,27 +235,27 @@ describe("Transport", function() { polling.doOpen(); }); - describe("for extraHeaders", function() { - it("should correctly set them for WebSockets", function() { - var headers = { + describe("for extraHeaders", () => { + it("should correctly set them for WebSockets", () => { + const headers = { "X-Custom-Header-For-My-Project": "my-secret-access-token", Cookie: "user_session=NI2JlCKF90aE0sJZD9ZzujtdsUqNYSBYxzlTsvdSUe35ZzdtVRGqYFr0kdGxbfc5gUOkR9RGp20GVKza; path=/; expires=Tue, 07-Apr-2015 18:18:08 GMT; secure; HttpOnly" }; - var polling = new eio.transports.websocket({ + const polling = new eio.transports.websocket({ path: "/engine.io", hostname: "localhost", extraHeaders: headers }); expect(polling.opts.extraHeaders).to.equal(headers); }); - it("should correctly set them for XMLHttpRequest", function() { - var headers = { + it("should correctly set them for XMLHttpRequest", () => { + const headers = { "X-Custom-Header-For-My-Project": "my-secret-access-token", Cookie: "user_session=NI2JlCKF90aE0sJZD9ZzujtdsUqNYSBYxzlTsvdSUe35ZzdtVRGqYFr0kdGxbfc5gUOkR9RGp20GVKza; path=/; expires=Tue, 07-Apr-2015 18:18:08 GMT; secure; HttpOnly" }; - var polling = new eio.transports.polling({ + const polling = new eio.transports.polling({ path: "/engine.io", hostname: "localhost", extraHeaders: headers @@ -264,16 +264,16 @@ describe("Transport", function() { }); }); - describe("perMessageDeflate", function() { - it("should set threshold", function(done) { - var socket = new eio.Socket({ + describe("perMessageDeflate", () => { + it("should set threshold", done => { + const socket = new eio.Socket({ transports: ["websocket"], perMessageDeflate: { threshold: 0 } }); - socket.on("open", function() { - var ws = socket.transport.ws; - var send = ws.send; - ws.send = function(data, opts, callback) { + socket.on("open", () => { + const ws = socket.transport.ws; + const send = ws.send; + ws.send = (data, opts, callback) => { ws.send = send; ws.send(data, opts, callback); @@ -285,12 +285,12 @@ describe("Transport", function() { }); }); - it("should not compress when the byte size is below threshold", function(done) { - var socket = new eio.Socket({ transports: ["websocket"] }); - socket.on("open", function() { - var ws = socket.transport.ws; - var send = ws.send; - ws.send = function(data, opts, callback) { + it("should not compress when the byte size is below threshold", done => { + const socket = new eio.Socket({ transports: ["websocket"] }); + socket.on("open", () => { + const ws = socket.transport.ws; + const send = ws.send; + ws.send = (data, opts, callback) => { ws.send = send; ws.send(data, opts, callback); @@ -305,14 +305,14 @@ describe("Transport", function() { }); } - describe("options", function() { - it("should accept an `extraHeaders` option for XMLHttpRequest in browser", function() { - var headers = { + describe("options", () => { + it("should accept an `extraHeaders` option for XMLHttpRequest in browser", () => { + const headers = { "X-Custom-Header-For-My-Project": "my-secret-access-token", Cookie: "user_session=NI2JlCKF90aE0sJZD9ZzujtdsUqNYSBYxzlTsvdSUe35ZzdtVRGqYFr0kdGxbfc5gUOkR9RGp20GVKza; path=/; expires=Tue, 07-Apr-2015 18:18:08 GMT; secure; HttpOnly" }; - var socket = new eio.Socket({ + const socket = new eio.Socket({ transportOptions: { polling: { extraHeaders: headers diff --git a/test/transports/polling-xhr.js b/test/transports/polling-xhr.js index a185b218c..ae7c64a4e 100644 --- a/test/transports/polling-xhr.js +++ b/test/transports/polling-xhr.js @@ -1,13 +1,13 @@ -var expect = require("expect.js"); -var XHR = require("../../lib/transports/polling-xhr"); -var env = require("../support/env"); +const expect = require("expect.js"); +const XHR = require("../../lib/transports/polling-xhr"); +const env = require("../support/env"); -describe("XHR", function() { - describe("Request", function() { - describe("hasXDR", function() { +describe("XHR", () => { + describe("Request", () => { + describe("hasXDR", () => { if (env.isIE8) { - it("should return true when xscheme is false and enablesXDR is true", function() { - var request = new XHR.Request({ + it("should return true when xscheme is false and enablesXDR is true", () => { + const request = new XHR.Request({ uri: "http://localhost/engine.io?sid=test", xd: true, xs: false, @@ -16,8 +16,8 @@ describe("XHR", function() { expect(request.hasXDR()).to.be(true); }); - it("should return false when xscheme is true", function() { - var request; + it("should return false when xscheme is true", () => { + let request; request = new XHR.Request({ uri: "http://localhost/engine.io?sid=test", xd: true, @@ -35,8 +35,8 @@ describe("XHR", function() { expect(request.hasXDR()).to.be(false); }); - it("should return false when enablesXDR is false", function() { - var request; + it("should return false when enablesXDR is false", () => { + let request; request = new XHR.Request({ uri: "http://localhost/engine.io?sid=test", xd: true, diff --git a/test/xmlhttprequest.js b/test/xmlhttprequest.js index cef9aa651..e9146f33d 100644 --- a/test/xmlhttprequest.js +++ b/test/xmlhttprequest.js @@ -1,13 +1,13 @@ -var expect = require("expect.js"); -var XMLHttpRequest = require("../lib/xmlhttprequest"); -var env = require("./support/env"); +const expect = require("expect.js"); +const XMLHttpRequest = require("../lib/xmlhttprequest"); +const env = require("./support/env"); -describe("XMLHttpRequest", function() { +describe("XMLHttpRequest", () => { if (env.isIE8 || env.isIE9) { - describe("IE8_9", function() { - context("when xdomain is false", function() { - it("should have same properties as XMLHttpRequest does", function() { - var xhra = new XMLHttpRequest({ + describe("IE8_9", () => { + context("when xdomain is false", () => { + it("should have same properties as XMLHttpRequest does", () => { + const xhra = new XMLHttpRequest({ xdomain: false, xscheme: false, enablesXDR: false @@ -15,7 +15,7 @@ describe("XMLHttpRequest", function() { expect(xhra).to.be.an("object"); expect(xhra).to.have.property("open"); expect(xhra).to.have.property("onreadystatechange"); - var xhrb = new XMLHttpRequest({ + const xhrb = new XMLHttpRequest({ xdomain: false, xscheme: false, enablesXDR: true @@ -23,7 +23,7 @@ describe("XMLHttpRequest", function() { expect(xhrb).to.be.an("object"); expect(xhrb).to.have.property("open"); expect(xhrb).to.have.property("onreadystatechange"); - var xhrc = new XMLHttpRequest({ + const xhrc = new XMLHttpRequest({ xdomain: false, xscheme: true, enablesXDR: false @@ -31,7 +31,7 @@ describe("XMLHttpRequest", function() { expect(xhrc).to.be.an("object"); expect(xhrc).to.have.property("open"); expect(xhrc).to.have.property("onreadystatechange"); - var xhrd = new XMLHttpRequest({ + const xhrd = new XMLHttpRequest({ xdomain: false, xscheme: true, enablesXDR: true @@ -42,10 +42,10 @@ describe("XMLHttpRequest", function() { }); }); - context("when xdomain is true", function() { - context("when xscheme is false and enablesXDR is true", function() { - it("should have same properties as XDomainRequest does", function() { - var xhr = new XMLHttpRequest({ + context("when xdomain is true", () => { + context("when xscheme is false and enablesXDR is true", () => { + it("should have same properties as XDomainRequest does", () => { + const xhr = new XMLHttpRequest({ xdomain: true, xscheme: false, enablesXDR: true @@ -57,16 +57,16 @@ describe("XMLHttpRequest", function() { }); }); - context("when xscheme is true", function() { - it("should not have open in properties", function() { - var xhra = new XMLHttpRequest({ + context("when xscheme is true", () => { + it("should not have open in properties", () => { + const xhra = new XMLHttpRequest({ xdomain: true, xscheme: true, enablesXDR: false }); expect(xhra).to.be.an("object"); expect(xhra).not.to.have.property("open"); - var xhrb = new XMLHttpRequest({ + const xhrb = new XMLHttpRequest({ xdomain: true, xscheme: true, enablesXDR: true @@ -76,16 +76,16 @@ describe("XMLHttpRequest", function() { }); }); - context("when enablesXDR is false", function() { - it("should not have open in properties", function() { - var xhra = new XMLHttpRequest({ + context("when enablesXDR is false", () => { + it("should not have open in properties", () => { + const xhra = new XMLHttpRequest({ xdomain: true, xscheme: false, enablesXDR: false }); expect(xhra).to.be.an("object"); expect(xhra).not.to.have.property("open"); - var xhrb = new XMLHttpRequest({ + const xhrb = new XMLHttpRequest({ xdomain: true, xscheme: true, enablesXDR: false @@ -99,10 +99,10 @@ describe("XMLHttpRequest", function() { } if (env.isIE10 || env.isIE11) { - describe("IE10_11", function() { - context("when enablesXDR is true and xscheme is false", function() { - it("should have same properties as XMLHttpRequest does", function() { - var xhra = new XMLHttpRequest({ + describe("IE10_11", () => { + context("when enablesXDR is true and xscheme is false", () => { + it("should have same properties as XMLHttpRequest does", () => { + const xhra = new XMLHttpRequest({ xdomain: false, xscheme: false, enablesXDR: true @@ -110,7 +110,7 @@ describe("XMLHttpRequest", function() { expect(xhra).to.be.an("object"); expect(xhra).to.have.property("open"); expect(xhra).to.have.property("onreadystatechange"); - var xhrb = new XMLHttpRequest({ + const xhrb = new XMLHttpRequest({ xdomain: true, xscheme: false, enablesXDR: true From d291a4c9f6accfc86fcd96683a5d493a87e3644c Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 31 Mar 2021 10:16:40 +0200 Subject: [PATCH 2/3] fix: ignore packets when the transport is silently closed In some cases, a "Transport not open" error could be thrown when the transport was silently closed in the onbeforeunload event (added in [1]). To reproduce: ```js window.addEventListener("unload", () => { socket.write("..."); }); ``` [1]: https://github.com/socketio/engine.io-client/commit/ed48b5dc3407e5ded45072606b3bb0eafa49c01f Related: https://github.com/socketio/socket.io/issues/3838 --- lib/transport.js | 4 +++- test/connection.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/transport.js b/lib/transport.js index eb864dc6d..a8800771b 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -1,5 +1,6 @@ const parser = require("engine.io-parser"); const Emitter = require("component-emitter"); +const debug = require("debug")("engine.io-client:transport"); class Transport extends Emitter { /** @@ -70,7 +71,8 @@ class Transport extends Emitter { if ("open" === this.readyState) { this.write(packets); } else { - throw new Error("Transport not open"); + // this might happen if the transport was silently closed in the beforeunload event handler + debug("transport is not open, discarding packets"); } } diff --git a/test/connection.js b/test/connection.js index 02fd21f06..28ee94127 100644 --- a/test/connection.js +++ b/test/connection.js @@ -188,4 +188,34 @@ describe("connection", function() { }); }); } + + if (env.browser && typeof addEventListener === "function") { + it("should close the socket when receiving a beforeunload event", done => { + const socket = new Socket(); + + const createEvent = name => { + if (typeof Event === "function") { + return new Event(name); + } else { + // polyfill for IE + const event = document.createEvent("Event"); + event.initEvent(name, true, true); + return event; + } + }; + + socket.on("open", () => { + const handler = () => { + expect(socket.transport.readyState).to.eql("closed"); + expect(() => socket.write("ignored")).to.not.throwException(); + + removeEventListener("beforeunload", handler, false); + done(); + }; + + addEventListener("beforeunload", handler, false); + dispatchEvent(createEvent("beforeunload")); + }); + }); + } }); From 9eeed5e0c0a3a3598d27947dabc57b47ca3a8365 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 31 Mar 2021 23:59:36 +0200 Subject: [PATCH 3/3] chore(release): 5.0.1 Diff: https://github.com/socketio/engine.io-client/compare/5.0.0...5.0.1 --- CHANGELOG.md | 8 ++++++++ dist/engine.io.js | 4 ++-- dist/engine.io.min.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 238529c05..1ec7a7063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [5.0.1](https://github.com/socketio/engine.io-client/compare/5.0.0...5.0.1) (2021-03-31) + + +### Bug Fixes + +* ignore packets when the transport is silently closed ([d291a4c](https://github.com/socketio/engine.io-client/commit/d291a4c9f6accfc86fcd96683a5d493a87e3644c)) + + # [5.0.0](https://github.com/socketio/engine.io-client/compare/4.1.2...5.0.0) (2021-03-10) The major bump is due to a breaking change on the server side. diff --git a/dist/engine.io.js b/dist/engine.io.js index 968ee2c58..c01a1c65a 100644 --- a/dist/engine.io.js +++ b/dist/engine.io.js @@ -1,5 +1,5 @@ /*! - * Engine.IO v5.0.0 + * Engine.IO v5.0.1 * (c) 2014-2021 Guillermo Rauch * Released under the MIT License. */ @@ -141,7 +141,7 @@ eval("function _extends() { _extends = Object.assign || function (target) { for /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -eval("function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nvar parser = __webpack_require__(/*! engine.io-parser */ \"./node_modules/engine.io-parser/lib/index.js\");\n\nvar Emitter = __webpack_require__(/*! component-emitter */ \"./node_modules/component-emitter/index.js\");\n\nvar Transport = /*#__PURE__*/function (_Emitter) {\n _inherits(Transport, _Emitter);\n\n var _super = _createSuper(Transport);\n\n /**\n * Transport abstract constructor.\n *\n * @param {Object} options.\n * @api private\n */\n function Transport(opts) {\n var _this;\n\n _classCallCheck(this, Transport);\n\n _this = _super.call(this);\n _this.opts = opts;\n _this.query = opts.query;\n _this.readyState = \"\";\n _this.socket = opts.socket;\n return _this;\n }\n /**\n * Emits an error.\n *\n * @param {String} str\n * @return {Transport} for chaining\n * @api public\n */\n\n\n _createClass(Transport, [{\n key: \"onError\",\n value: function onError(msg, desc) {\n var err = new Error(msg);\n err.type = \"TransportError\";\n err.description = desc;\n this.emit(\"error\", err);\n return this;\n }\n /**\n * Opens the transport.\n *\n * @api public\n */\n\n }, {\n key: \"open\",\n value: function open() {\n if (\"closed\" === this.readyState || \"\" === this.readyState) {\n this.readyState = \"opening\";\n this.doOpen();\n }\n\n return this;\n }\n /**\n * Closes the transport.\n *\n * @api private\n */\n\n }, {\n key: \"close\",\n value: function close() {\n if (\"opening\" === this.readyState || \"open\" === this.readyState) {\n this.doClose();\n this.onClose();\n }\n\n return this;\n }\n /**\n * Sends multiple packets.\n *\n * @param {Array} packets\n * @api private\n */\n\n }, {\n key: \"send\",\n value: function send(packets) {\n if (\"open\" === this.readyState) {\n this.write(packets);\n } else {\n throw new Error(\"Transport not open\");\n }\n }\n /**\n * Called upon open\n *\n * @api private\n */\n\n }, {\n key: \"onOpen\",\n value: function onOpen() {\n this.readyState = \"open\";\n this.writable = true;\n this.emit(\"open\");\n }\n /**\n * Called with data.\n *\n * @param {String} data\n * @api private\n */\n\n }, {\n key: \"onData\",\n value: function onData(data) {\n var packet = parser.decodePacket(data, this.socket.binaryType);\n this.onPacket(packet);\n }\n /**\n * Called with a decoded packet.\n */\n\n }, {\n key: \"onPacket\",\n value: function onPacket(packet) {\n this.emit(\"packet\", packet);\n }\n /**\n * Called upon close.\n *\n * @api private\n */\n\n }, {\n key: \"onClose\",\n value: function onClose() {\n this.readyState = \"closed\";\n this.emit(\"close\");\n }\n }]);\n\n return Transport;\n}(Emitter);\n\nmodule.exports = Transport;\n\n//# sourceURL=webpack://eio/./lib/transport.js?"); +eval("function _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nvar parser = __webpack_require__(/*! engine.io-parser */ \"./node_modules/engine.io-parser/lib/index.js\");\n\nvar Emitter = __webpack_require__(/*! component-emitter */ \"./node_modules/component-emitter/index.js\");\n\nvar debug = __webpack_require__(/*! debug */ \"./node_modules/debug/src/browser.js\")(\"engine.io-client:transport\");\n\nvar Transport = /*#__PURE__*/function (_Emitter) {\n _inherits(Transport, _Emitter);\n\n var _super = _createSuper(Transport);\n\n /**\n * Transport abstract constructor.\n *\n * @param {Object} options.\n * @api private\n */\n function Transport(opts) {\n var _this;\n\n _classCallCheck(this, Transport);\n\n _this = _super.call(this);\n _this.opts = opts;\n _this.query = opts.query;\n _this.readyState = \"\";\n _this.socket = opts.socket;\n return _this;\n }\n /**\n * Emits an error.\n *\n * @param {String} str\n * @return {Transport} for chaining\n * @api public\n */\n\n\n _createClass(Transport, [{\n key: \"onError\",\n value: function onError(msg, desc) {\n var err = new Error(msg);\n err.type = \"TransportError\";\n err.description = desc;\n this.emit(\"error\", err);\n return this;\n }\n /**\n * Opens the transport.\n *\n * @api public\n */\n\n }, {\n key: \"open\",\n value: function open() {\n if (\"closed\" === this.readyState || \"\" === this.readyState) {\n this.readyState = \"opening\";\n this.doOpen();\n }\n\n return this;\n }\n /**\n * Closes the transport.\n *\n * @api private\n */\n\n }, {\n key: \"close\",\n value: function close() {\n if (\"opening\" === this.readyState || \"open\" === this.readyState) {\n this.doClose();\n this.onClose();\n }\n\n return this;\n }\n /**\n * Sends multiple packets.\n *\n * @param {Array} packets\n * @api private\n */\n\n }, {\n key: \"send\",\n value: function send(packets) {\n if (\"open\" === this.readyState) {\n this.write(packets);\n } else {\n // this might happen if the transport was silently closed in the beforeunload event handler\n debug(\"transport is not open, discarding packets\");\n }\n }\n /**\n * Called upon open\n *\n * @api private\n */\n\n }, {\n key: \"onOpen\",\n value: function onOpen() {\n this.readyState = \"open\";\n this.writable = true;\n this.emit(\"open\");\n }\n /**\n * Called with data.\n *\n * @param {String} data\n * @api private\n */\n\n }, {\n key: \"onData\",\n value: function onData(data) {\n var packet = parser.decodePacket(data, this.socket.binaryType);\n this.onPacket(packet);\n }\n /**\n * Called with a decoded packet.\n */\n\n }, {\n key: \"onPacket\",\n value: function onPacket(packet) {\n this.emit(\"packet\", packet);\n }\n /**\n * Called upon close.\n *\n * @api private\n */\n\n }, {\n key: \"onClose\",\n value: function onClose() {\n this.readyState = \"closed\";\n this.emit(\"close\");\n }\n }]);\n\n return Transport;\n}(Emitter);\n\nmodule.exports = Transport;\n\n//# sourceURL=webpack://eio/./lib/transport.js?"); /***/ }), diff --git a/dist/engine.io.min.js b/dist/engine.io.min.js index f654a1090..f801f938d 100644 --- a/dist/engine.io.min.js +++ b/dist/engine.io.min.js @@ -1,6 +1,6 @@ /*! - * Engine.IO v5.0.0 + * Engine.IO v5.0.1 * (c) 2014-2021 Guillermo Rauch * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.eio=e():t.eio=e()}(self,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=11)}([function(t,e,r){var n=r(15),o=r(16),i=String.fromCharCode(30);t.exports={protocol:4,encodePacket:n,encodePayload:function(t,e){var r=t.length,o=new Array(r),s=0;t.forEach((function(t,a){n(t,!1,(function(t){o[a]=t,++s===r&&e(o.join(i))}))}))},decodePacket:o,decodePayload:function(t,e){for(var r=t.split(i),n=[],s=0;s0);return e}function c(){var t=u(+new Date);return t!==n?(s=0,n=t):t+"."+u(s++)}for(;a<64;a++)i[o[a]]=a;c.encode=u,c.decode=function(t){var e=0;for(a=0;a1?e-1:0),n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return i(this,l),e=f.call(this),t&&"object"===o(t)&&(r=t,t=null),t?(t=y(t),r.hostname=t.host,r.secure="https"===t.protocol||"wss"===t.protocol,r.port=t.port,t.query&&(r.query=t.query)):r.host&&(r.hostname=y(r.host).host),e.secure=null!=r.secure?r.secure:"undefined"!=typeof location&&"https:"===location.protocol,r.hostname&&!r.port&&(r.port=e.secure?"443":"80"),e.hostname=r.hostname||("undefined"!=typeof location?location.hostname:"localhost"),e.port=r.port||("undefined"!=typeof location&&location.port?location.port:e.secure?443:80),e.transports=r.transports||["polling","websocket"],e.readyState="",e.writeBuffer=[],e.prevBufferLen=0,e.opts=n({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,jsonp:!0,timestampParam:"t",rememberUpgrade:!1,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{}},r),e.opts.path=e.opts.path.replace(/\/$/,"")+"/","string"==typeof e.opts.query&&(e.opts.query=d.decode(e.opts.query)),e.id=null,e.upgrades=null,e.pingInterval=null,e.pingTimeout=null,e.pingTimeoutTimer=null,"function"==typeof addEventListener&&(addEventListener("beforeunload",(function(){e.transport&&(e.transport.removeAllListeners(),e.transport.close())}),!1),"localhost"!==e.hostname&&(e.offlineEventListener=function(){e.onClose("transport close")},addEventListener("offline",e.offlineEventListener,!1))),e.open(),e}return e=l,(r=[{key:"createTransport",value:function(t){var e=function(t){var e={};for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}(this.opts.query);e.EIO=h.protocol,e.transport=t,this.id&&(e.sid=this.id);var r=n({},this.opts.transportOptions[t],this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new p[t](r)}},{key:"open",value:function(){var t;if(this.opts.rememberUpgrade&&l.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length){var e=this;return void setTimeout((function(){e.emit("error","No transports available")}),0)}t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}},{key:"setTransport",value:function(t){var e=this;this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",(function(){e.onDrain()})).on("packet",(function(t){e.onPacket(t)})).on("error",(function(t){e.onError(t)})).on("close",(function(){e.onClose("transport close")}))}},{key:"probe",value:function(t){var e=this.createTransport(t,{probe:1}),r=!1,n=this;function o(){if(n.onlyBinaryUpgrades){var t=!this.supportsBinary&&n.transport.supportsBinary;r=r||t}r||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(function(t){if(!r)if("pong"===t.type&&"probe"===t.data){if(n.upgrading=!0,n.emit("upgrading",e),!e)return;l.priorWebsocketSuccess="websocket"===e.name,n.transport.pause((function(){r||"closed"!==n.readyState&&(f(),n.setTransport(e),e.send([{type:"upgrade"}]),n.emit("upgrade",e),e=null,n.upgrading=!1,n.flush())}))}else{var o=new Error("probe error");o.transport=e.name,n.emit("upgradeError",o)}})))}function i(){r||(r=!0,f(),e.close(),e=null)}function s(t){var r=new Error("probe error: "+t);r.transport=e.name,i(),n.emit("upgradeError",r)}function a(){s("transport closed")}function u(){s("socket closed")}function c(t){e&&t.name!==e.name&&i()}function f(){e.removeListener("open",o),e.removeListener("error",s),e.removeListener("close",a),n.removeListener("close",u),n.removeListener("upgrading",c)}l.priorWebsocketSuccess=!1,e.once("open",o),e.once("error",s),e.once("close",a),this.once("close",u),this.once("upgrading",c),e.open()}},{key:"onOpen",value:function(){if(this.readyState="open",l.priorWebsocketSuccess="websocket"===this.transport.name,this.emit("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade&&this.transport.pause)for(var t=0,e=this.upgrades.length;t0&&void 0!==arguments[0]?arguments[0]:{};return o(t,{xd:this.xd,xs:this.xs},this.opts),new k(this.uri(),t)}},{key:"doWrite",value:function(t,e){var r=this.request({method:"POST",data:t}),n=this;r.on("success",e),r.on("error",(function(t){n.onError("xhr post error",t)}))}},{key:"doPoll",value:function(){var t=this.request(),e=this;t.on("data",(function(t){e.onData(t)})),t.on("error",(function(t){e.onError("xhr poll error",t)})),this.pollXhr=t}}]),r}(y),k=function(t){u(r,t);var e=f(r);function r(t,n){var o;return i(this,r),(o=e.call(this)).opts=n,o.method=n.method||"GET",o.uri=t,o.async=!1!==n.async,o.data=void 0!==n.data?n.data:null,o.create(),o}return a(r,[{key:"create",value:function(){var t=m(this.opts,"agent","enablesXDR","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;var e=this.xhr=new h(t),n=this;try{e.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders)for(var o in e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0),this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(o)&&e.setRequestHeader(o,this.opts.extraHeaders[o])}catch(t){}if("POST"===this.method)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}"withCredentials"in e&&(e.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(e.timeout=this.opts.requestTimeout),this.hasXDR()?(e.onload=function(){n.onLoad()},e.onerror=function(){n.onError(e.responseText)}):e.onreadystatechange=function(){4===e.readyState&&(200===e.status||1223===e.status?n.onLoad():setTimeout((function(){n.onError("number"==typeof e.status?e.status:0)}),0))},e.send(this.data)}catch(t){return void setTimeout((function(){n.onError(t)}),0)}"undefined"!=typeof document&&(this.index=r.requestsCount++,r.requests[this.index]=this)}},{key:"onSuccess",value:function(){this.emit("success"),this.cleanup()}},{key:"onData",value:function(t){this.emit("data",t),this.onSuccess()}},{key:"onError",value:function(t){this.emit("error",t),this.cleanup(!0)}},{key:"cleanup",value:function(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=b:this.xhr.onreadystatechange=b,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete r.requests[this.index],this.xhr=null}}},{key:"onLoad",value:function(){var t=this.xhr.responseText;null!==t&&this.onData(t)}},{key:"hasXDR",value:function(){return"undefined"!=typeof XDomainRequest&&!this.xs&&this.enablesXDR}},{key:"abort",value:function(){this.cleanup()}}]),r}(d);if(k.requestsCount=0,k.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",O);else if("function"==typeof addEventListener){addEventListener("onpagehide"in v?"pagehide":"unload",O,!1)}function O(){for(var t in k.requests)k.requests.hasOwnProperty(t)&&k.requests[t].abort()}t.exports=w,t.exports.Request=k},function(t,e,r){var n=r(8).PACKET_TYPES,o="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),i="function"==typeof ArrayBuffer,s=function(t,e){var r=new FileReader;return r.onload=function(){var t=r.result.split(",")[1];e("b"+t)},r.readAsDataURL(t)};t.exports=function(t,e,r){var a,u=t.type,c=t.data;return o&&c instanceof Blob?e?r(c):s(c,r):i&&(c instanceof ArrayBuffer||(a=c,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(a):a&&a.buffer instanceof ArrayBuffer))?e?r(c instanceof ArrayBuffer?c:c.buffer):s(new Blob([c]),r):r(n[u]+(c||""))}},function(t,e,r){var n,o=r(8),i=o.PACKET_TYPES_REVERSE,s=o.ERROR_PACKET;"function"==typeof ArrayBuffer&&(n=r(17));var a=function(t,e){if(n){var r=n.decode(t);return u(r,e)}return{base64:!0,data:t}},u=function(t,e){switch(e){case"blob":return t instanceof ArrayBuffer?new Blob([t]):t;case"arraybuffer":default:return t}};t.exports=function(t,e){if("string"!=typeof t)return{type:"message",data:u(t,e)};var r=t.charAt(0);return"b"===r?{type:"message",data:a(t.substring(1),e)}:i[r]?t.length>1?{type:i[r],data:t.substring(1)}:{type:i[r]}:s}},function(t,e){!function(t){"use strict";e.encode=function(e){var r,n=new Uint8Array(e),o=n.length,i="";for(r=0;r>2],i+=t[(3&n[r])<<4|n[r+1]>>4],i+=t[(15&n[r+1])<<2|n[r+2]>>6],i+=t[63&n[r+2]];return o%3==2?i=i.substring(0,i.length-1)+"=":o%3==1&&(i=i.substring(0,i.length-2)+"=="),i},e.decode=function(e){var r,n,o,i,s,a=.75*e.length,u=e.length,c=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var f=new ArrayBuffer(a),p=new Uint8Array(f);for(r=0;r>4,p[c++]=(15&o)<<4|i>>2,p[c++]=(3&i)<<6|63&s;return f}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},function(t,e,r){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r';r=document.createElement(t)}catch(t){(r=document.createElement("iframe")).name=n.iframeId,r.src="javascript:0"}r.id=n.iframeId,n.form.appendChild(r),n.iframe=r}this.form.action=this.uri(),u(),t=t.replace(d,"\\\n"),this.area.value=t.replace(y,"\\n");try{this.form.submit()}catch(t){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===n.iframe.readyState&&a()}:this.iframe.onload=a}},{key:"supportsBinary",get:function(){return!1}}])&&o(e.prototype,r),n&&o(e,n),l}(l);t.exports=m},function(t,e,r){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r0);return e}function c(){var t=u(+new Date);return t!==n?(s=0,n=t):t+"."+u(s++)}for(;a<64;a++)i[o[a]]=a;c.encode=u,c.decode=function(t){var e=0;for(a=0;a1?e-1:0),n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return i(this,l),e=f.call(this),t&&"object"===o(t)&&(r=t,t=null),t?(t=y(t),r.hostname=t.host,r.secure="https"===t.protocol||"wss"===t.protocol,r.port=t.port,t.query&&(r.query=t.query)):r.host&&(r.hostname=y(r.host).host),e.secure=null!=r.secure?r.secure:"undefined"!=typeof location&&"https:"===location.protocol,r.hostname&&!r.port&&(r.port=e.secure?"443":"80"),e.hostname=r.hostname||("undefined"!=typeof location?location.hostname:"localhost"),e.port=r.port||("undefined"!=typeof location&&location.port?location.port:e.secure?443:80),e.transports=r.transports||["polling","websocket"],e.readyState="",e.writeBuffer=[],e.prevBufferLen=0,e.opts=n({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,jsonp:!0,timestampParam:"t",rememberUpgrade:!1,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{}},r),e.opts.path=e.opts.path.replace(/\/$/,"")+"/","string"==typeof e.opts.query&&(e.opts.query=d.decode(e.opts.query)),e.id=null,e.upgrades=null,e.pingInterval=null,e.pingTimeout=null,e.pingTimeoutTimer=null,"function"==typeof addEventListener&&(addEventListener("beforeunload",(function(){e.transport&&(e.transport.removeAllListeners(),e.transport.close())}),!1),"localhost"!==e.hostname&&(e.offlineEventListener=function(){e.onClose("transport close")},addEventListener("offline",e.offlineEventListener,!1))),e.open(),e}return e=l,(r=[{key:"createTransport",value:function(t){var e=function(t){var e={};for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}(this.opts.query);e.EIO=h.protocol,e.transport=t,this.id&&(e.sid=this.id);var r=n({},this.opts.transportOptions[t],this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new p[t](r)}},{key:"open",value:function(){var t;if(this.opts.rememberUpgrade&&l.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length){var e=this;return void setTimeout((function(){e.emit("error","No transports available")}),0)}t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}},{key:"setTransport",value:function(t){var e=this;this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",(function(){e.onDrain()})).on("packet",(function(t){e.onPacket(t)})).on("error",(function(t){e.onError(t)})).on("close",(function(){e.onClose("transport close")}))}},{key:"probe",value:function(t){var e=this.createTransport(t,{probe:1}),r=!1,n=this;function o(){if(n.onlyBinaryUpgrades){var t=!this.supportsBinary&&n.transport.supportsBinary;r=r||t}r||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(function(t){if(!r)if("pong"===t.type&&"probe"===t.data){if(n.upgrading=!0,n.emit("upgrading",e),!e)return;l.priorWebsocketSuccess="websocket"===e.name,n.transport.pause((function(){r||"closed"!==n.readyState&&(f(),n.setTransport(e),e.send([{type:"upgrade"}]),n.emit("upgrade",e),e=null,n.upgrading=!1,n.flush())}))}else{var o=new Error("probe error");o.transport=e.name,n.emit("upgradeError",o)}})))}function i(){r||(r=!0,f(),e.close(),e=null)}function s(t){var r=new Error("probe error: "+t);r.transport=e.name,i(),n.emit("upgradeError",r)}function a(){s("transport closed")}function u(){s("socket closed")}function c(t){e&&t.name!==e.name&&i()}function f(){e.removeListener("open",o),e.removeListener("error",s),e.removeListener("close",a),n.removeListener("close",u),n.removeListener("upgrading",c)}l.priorWebsocketSuccess=!1,e.once("open",o),e.once("error",s),e.once("close",a),this.once("close",u),this.once("upgrading",c),e.open()}},{key:"onOpen",value:function(){if(this.readyState="open",l.priorWebsocketSuccess="websocket"===this.transport.name,this.emit("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade&&this.transport.pause)for(var t=0,e=this.upgrades.length;t0&&void 0!==arguments[0]?arguments[0]:{};return o(t,{xd:this.xd,xs:this.xs},this.opts),new k(this.uri(),t)}},{key:"doWrite",value:function(t,e){var r=this.request({method:"POST",data:t}),n=this;r.on("success",e),r.on("error",(function(t){n.onError("xhr post error",t)}))}},{key:"doPoll",value:function(){var t=this.request(),e=this;t.on("data",(function(t){e.onData(t)})),t.on("error",(function(t){e.onError("xhr poll error",t)})),this.pollXhr=t}}]),r}(y),k=function(t){u(r,t);var e=f(r);function r(t,n){var o;return i(this,r),(o=e.call(this)).opts=n,o.method=n.method||"GET",o.uri=t,o.async=!1!==n.async,o.data=void 0!==n.data?n.data:null,o.create(),o}return a(r,[{key:"create",value:function(){var t=m(this.opts,"agent","enablesXDR","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;var e=this.xhr=new h(t),n=this;try{e.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders)for(var o in e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0),this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(o)&&e.setRequestHeader(o,this.opts.extraHeaders[o])}catch(t){}if("POST"===this.method)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}"withCredentials"in e&&(e.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(e.timeout=this.opts.requestTimeout),this.hasXDR()?(e.onload=function(){n.onLoad()},e.onerror=function(){n.onError(e.responseText)}):e.onreadystatechange=function(){4===e.readyState&&(200===e.status||1223===e.status?n.onLoad():setTimeout((function(){n.onError("number"==typeof e.status?e.status:0)}),0))},e.send(this.data)}catch(t){return void setTimeout((function(){n.onError(t)}),0)}"undefined"!=typeof document&&(this.index=r.requestsCount++,r.requests[this.index]=this)}},{key:"onSuccess",value:function(){this.emit("success"),this.cleanup()}},{key:"onData",value:function(t){this.emit("data",t),this.onSuccess()}},{key:"onError",value:function(t){this.emit("error",t),this.cleanup(!0)}},{key:"cleanup",value:function(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=b:this.xhr.onreadystatechange=b,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete r.requests[this.index],this.xhr=null}}},{key:"onLoad",value:function(){var t=this.xhr.responseText;null!==t&&this.onData(t)}},{key:"hasXDR",value:function(){return"undefined"!=typeof XDomainRequest&&!this.xs&&this.enablesXDR}},{key:"abort",value:function(){this.cleanup()}}]),r}(d);if(k.requestsCount=0,k.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",O);else if("function"==typeof addEventListener){addEventListener("onpagehide"in v?"pagehide":"unload",O,!1)}function O(){for(var t in k.requests)k.requests.hasOwnProperty(t)&&k.requests[t].abort()}t.exports=w,t.exports.Request=k},function(t,e,r){var n=r(8).PACKET_TYPES,o="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),i="function"==typeof ArrayBuffer,s=function(t,e){var r=new FileReader;return r.onload=function(){var t=r.result.split(",")[1];e("b"+t)},r.readAsDataURL(t)};t.exports=function(t,e,r){var a,u=t.type,c=t.data;return o&&c instanceof Blob?e?r(c):s(c,r):i&&(c instanceof ArrayBuffer||(a=c,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(a):a&&a.buffer instanceof ArrayBuffer))?e?r(c instanceof ArrayBuffer?c:c.buffer):s(new Blob([c]),r):r(n[u]+(c||""))}},function(t,e,r){var n,o=r(8),i=o.PACKET_TYPES_REVERSE,s=o.ERROR_PACKET;"function"==typeof ArrayBuffer&&(n=r(17));var a=function(t,e){if(n){var r=n.decode(t);return u(r,e)}return{base64:!0,data:t}},u=function(t,e){switch(e){case"blob":return t instanceof ArrayBuffer?new Blob([t]):t;case"arraybuffer":default:return t}};t.exports=function(t,e){if("string"!=typeof t)return{type:"message",data:u(t,e)};var r=t.charAt(0);return"b"===r?{type:"message",data:a(t.substring(1),e)}:i[r]?t.length>1?{type:i[r],data:t.substring(1)}:{type:i[r]}:s}},function(t,e){!function(t){"use strict";e.encode=function(e){var r,n=new Uint8Array(e),o=n.length,i="";for(r=0;r>2],i+=t[(3&n[r])<<4|n[r+1]>>4],i+=t[(15&n[r+1])<<2|n[r+2]>>6],i+=t[63&n[r+2]];return o%3==2?i=i.substring(0,i.length-1)+"=":o%3==1&&(i=i.substring(0,i.length-2)+"=="),i},e.decode=function(e){var r,n,o,i,s,a=.75*e.length,u=e.length,c=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var f=new ArrayBuffer(a),p=new Uint8Array(f);for(r=0;r>4,p[c++]=(15&o)<<4|i>>2,p[c++]=(3&i)<<6|63&s;return f}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},function(t,e,r){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r';r=document.createElement(t)}catch(t){(r=document.createElement("iframe")).name=n.iframeId,r.src="javascript:0"}r.id=n.iframeId,n.form.appendChild(r),n.iframe=r}this.form.action=this.uri(),u(),t=t.replace(d,"\\\n"),this.area.value=t.replace(y,"\\n");try{this.form.submit()}catch(t){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"===n.iframe.readyState&&a()}:this.iframe.onload=a}},{key:"supportsBinary",get:function(){return!1}}])&&o(e.prototype,r),n&&o(e,n),l}(l);t.exports=m},function(t,e,r){function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r