mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Possibility to disable JSONP. Emitting an error if JSONP is the only available transport.
This commit is contained in:
@@ -71,6 +71,7 @@ function Socket(uri, opts){
|
||||
this.upgrade = false !== opts.upgrade;
|
||||
this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
|
||||
this.forceJSONP = !!opts.forceJSONP;
|
||||
this.noJSONP = !!opts.noJSONP;
|
||||
this.forceBase64 = !!opts.forceBase64;
|
||||
this.timestampParam = opts.timestampParam || 't';
|
||||
this.timestampRequests = opts.timestampRequests;
|
||||
@@ -140,6 +141,7 @@ Socket.prototype.createTransport = function (name) {
|
||||
path: this.path,
|
||||
query: query,
|
||||
forceJSONP: this.forceJSONP,
|
||||
noJSONP: this.noJSONP,
|
||||
forceBase64: this.forceBase64,
|
||||
timestampRequests: this.timestampRequests,
|
||||
timestampParam: this.timestampParam,
|
||||
@@ -169,11 +171,26 @@ Socket.prototype.open = function () {
|
||||
var transport;
|
||||
if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') != -1) {
|
||||
transport = 'websocket';
|
||||
} else if (0 == this.transports.length) {
|
||||
// Emit error on next tick so it can be listened to
|
||||
var self = this;
|
||||
setTimeout(function() {
|
||||
self.emit('error', 'No transports available');
|
||||
}, 0);
|
||||
return;
|
||||
} else {
|
||||
transport = this.transports[0];
|
||||
}
|
||||
this.readyState = 'opening';
|
||||
var transport = this.createTransport(transport);
|
||||
|
||||
// If polling and JSONP disabled (constructor returns null)
|
||||
if (!transport.name) {
|
||||
this.transports.shift();
|
||||
this.open();
|
||||
return;
|
||||
}
|
||||
|
||||
transport.open();
|
||||
this.setTransport(transport);
|
||||
};
|
||||
|
||||
@@ -43,6 +43,6 @@ function polling(opts){
|
||||
if ('open' in xhr && !opts.forceJSONP) {
|
||||
return new XHR(opts);
|
||||
} else {
|
||||
return new JSONP(opts);
|
||||
return opts.noJSONP ? null : new JSONP(opts);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user