Skip to content

Commit b2c7381

Browse files
refactor: remove JSONP polling
JSONP polling was only used in IE7/8, which are not supported anymore. BREAKING CHANGE: the jsonp and forceJSONP options are removed.
1 parent 27de300 commit b2c7381

File tree

5 files changed

+1
-289
lines changed

5 files changed

+1
-289
lines changed

README.md

-7
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ Exposed as `eio` in the browser standalone build.
226226
- `agent` (`http.Agent`): `http.Agent` to use, defaults to `false` (NodeJS only)
227227
- `upgrade` (`Boolean`): defaults to true, whether the client should try
228228
to upgrade the transport from long-polling to something better.
229-
- `forceJSONP` (`Boolean`): forces JSONP for polling transport.
230-
- `jsonp` (`Boolean`): determines whether to use JSONP when
231-
necessary for polling. If disabled (by settings to false) an error will
232-
be emitted (saying "No transports available") if no other transports
233-
are available. If another transport is available for opening a
234-
connection (e.g. WebSocket) that transport
235-
will be used instead.
236229
- `forceBase64` (`Boolean`): forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
237230
- `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.
238231
- `withCredentials` (`Boolean`): defaults to `false`, whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests.

lib/socket.ts

-16
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ export interface SocketOptions {
4646
*/
4747
upgrade: boolean;
4848

49-
/**
50-
* Forces JSONP for polling transport.
51-
*/
52-
forceJSONP: boolean;
53-
54-
/**
55-
* Determines whether to use JSONP when necessary for polling. If
56-
* disabled (by settings to false) an error will be emitted (saying
57-
* "No transports available") if no other transports are available.
58-
* If another transport is available for opening a connection (e.g.
59-
* WebSocket) that transport will be used instead.
60-
* @default true
61-
*/
62-
jsonp: boolean;
63-
6449
/**
6550
* Forces base 64 encoding for polling transport even when XHR2
6651
* responseType is available and WebSocket even if the used standard
@@ -322,7 +307,6 @@ export class Socket extends Emitter {
322307
agent: false,
323308
withCredentials: false,
324309
upgrade: true,
325-
jsonp: true,
326310
timestampParam: "t",
327311
rememberUpgrade: false,
328312
rejectUnauthorized: true,

lib/transports/index.ts

+1-43
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,7 @@
1-
import * as XMLHttpRequestModule from "xmlhttprequest-ssl";
21
import { XHR } from "./polling-xhr.js";
3-
import { JSONP } from "./polling-jsonp.js";
42
import { WS } from "./websocket.js";
53

6-
const XMLHttpRequest = XMLHttpRequestModule.default || XMLHttpRequestModule;
7-
8-
/**
9-
* Polling transport polymorphic constructor.
10-
* Decides on xhr vs jsonp based on feature detection.
11-
*
12-
* @api private
13-
*/
14-
15-
function polling(opts) {
16-
let xhr;
17-
let xd = false;
18-
let xs = false;
19-
const jsonp = false !== opts.jsonp;
20-
21-
if (typeof location !== "undefined") {
22-
const isSSL = "https:" === location.protocol;
23-
let port = location.port;
24-
25-
// some user agents have empty `location.port`
26-
if (!port) {
27-
port = isSSL ? "443" : "80";
28-
}
29-
30-
xd = opts.hostname !== location.hostname || port !== opts.port;
31-
xs = opts.secure !== isSSL;
32-
}
33-
34-
opts.xdomain = xd;
35-
opts.xscheme = xs;
36-
xhr = new XMLHttpRequest(opts);
37-
38-
if ("open" in xhr && !opts.forceJSONP) {
39-
return new XHR(opts);
40-
} else {
41-
if (!jsonp) throw new Error("JSONP disabled");
42-
return new JSONP(opts);
43-
}
44-
}
45-
464
export const transports = {
475
websocket: WS,
48-
polling
6+
polling: XHR
497
};

lib/transports/polling-jsonp.ts

-197
This file was deleted.

test/connection.js

-26
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,7 @@ describe("connection", function() {
9191
});
9292
}
9393

94-
it("should not connect at all when JSONP forced and disabled", done => {
95-
const socket = new Socket({
96-
transports: ["polling"],
97-
forceJSONP: true,
98-
jsonp: false
99-
});
100-
socket.on("error", msg => {
101-
expect(msg).to.be("No transports available");
102-
done();
103-
});
104-
});
105-
10694
if (env.wsSupport && !env.isOldSimulator && !env.isAndroid && !env.isIE11) {
107-
it("should connect with ws when JSONP forced and disabled", done => {
108-
const socket = new Socket({
109-
transports: ["polling", "websocket"],
110-
forceJSONP: true,
111-
jsonp: false
112-
});
113-
114-
socket.on("open", () => {
115-
expect(socket.transport.name).to.be("websocket");
116-
socket.close();
117-
done();
118-
});
119-
});
120-
12195
it("should defer close when upgrading", done => {
12296
const socket = new Socket();
12397
socket.on("open", () => {

0 commit comments

Comments
 (0)