Skip to content

Commit

Permalink
refactor: remove JSONP polling
Browse files Browse the repository at this point in the history
JSONP polling was only used in IE7/8, which are not supported anymore.

BREAKING CHANGE: the jsonp and forceJSONP options are removed.
  • Loading branch information
darrachequesne committed Oct 8, 2021
1 parent 27de300 commit b2c7381
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 289 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,6 @@ Exposed as `eio` in the browser standalone build.
- `agent` (`http.Agent`): `http.Agent` to use, defaults to `false` (NodeJS only)
- `upgrade` (`Boolean`): defaults to true, whether the client should try
to upgrade the transport from long-polling to something better.
- `forceJSONP` (`Boolean`): forces JSONP for polling transport.
- `jsonp` (`Boolean`): determines whether to use JSONP when
necessary for polling. If disabled (by settings to false) an error will
be emitted (saying "No transports available") if no other transports
are available. If another transport is available for opening a
connection (e.g. WebSocket) that transport
will be used instead.
- `forceBase64` (`Boolean`): forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
- `enablesXDR` (`Boolean`): enables XDomainRequest for IE8 to avoid loading bar flashing with click sound. default to `false` because XDomainRequest has a flaw of not sending cookie.
- `withCredentials` (`Boolean`): defaults to `false`, whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests.
Expand Down
16 changes: 0 additions & 16 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,6 @@ export interface SocketOptions {
*/
upgrade: boolean;

/**
* Forces JSONP for polling transport.
*/
forceJSONP: boolean;

/**
* Determines whether to use JSONP when necessary for polling. If
* disabled (by settings to false) an error will be emitted (saying
* "No transports available") if no other transports are available.
* If another transport is available for opening a connection (e.g.
* WebSocket) that transport will be used instead.
* @default true
*/
jsonp: boolean;

/**
* Forces base 64 encoding for polling transport even when XHR2
* responseType is available and WebSocket even if the used standard
Expand Down Expand Up @@ -322,7 +307,6 @@ export class Socket extends Emitter {
agent: false,
withCredentials: false,
upgrade: true,
jsonp: true,
timestampParam: "t",
rememberUpgrade: false,
rejectUnauthorized: true,
Expand Down
44 changes: 1 addition & 43 deletions lib/transports/index.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
import * as XMLHttpRequestModule from "xmlhttprequest-ssl";
import { XHR } from "./polling-xhr.js";
import { JSONP } from "./polling-jsonp.js";
import { WS } from "./websocket.js";

const XMLHttpRequest = XMLHttpRequestModule.default || XMLHttpRequestModule;

/**
* Polling transport polymorphic constructor.
* Decides on xhr vs jsonp based on feature detection.
*
* @api private
*/

function polling(opts) {
let xhr;
let xd = false;
let xs = false;
const jsonp = false !== opts.jsonp;

if (typeof location !== "undefined") {
const isSSL = "https:" === location.protocol;
let port = location.port;

// some user agents have empty `location.port`
if (!port) {
port = isSSL ? "443" : "80";
}

xd = opts.hostname !== location.hostname || port !== opts.port;
xs = opts.secure !== isSSL;
}

opts.xdomain = xd;
opts.xscheme = xs;
xhr = new XMLHttpRequest(opts);

if ("open" in xhr && !opts.forceJSONP) {
return new XHR(opts);
} else {
if (!jsonp) throw new Error("JSONP disabled");
return new JSONP(opts);
}
}

export const transports = {
websocket: WS,
polling
polling: XHR
};
197 changes: 0 additions & 197 deletions lib/transports/polling-jsonp.ts

This file was deleted.

26 changes: 0 additions & 26 deletions test/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,7 @@ describe("connection", function() {
});
}

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", 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", done => {
const socket = new Socket({
transports: ["polling", "websocket"],
forceJSONP: true,
jsonp: false
});

socket.on("open", () => {
expect(socket.transport.name).to.be("websocket");
socket.close();
done();
});
});

it("should defer close when upgrading", done => {
const socket = new Socket();
socket.on("open", () => {
Expand Down

0 comments on commit b2c7381

Please sign in to comment.