[Pkg-javascript-commits] [sockjs-client] 113/350: Create iframe wrap transport instead of separate for each underlying transport.
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit 5d9769de5544c18cacf3764672571a58c2151573
Author: Bryce Kahle <bkahle at gmail.com>
Date: Fri Oct 10 15:01:17 2014 -0400
Create iframe wrap transport instead of separate for each underlying transport.
---
lib/entry.js | 15 +++++++++++----
lib/iframe-bootstrap.js | 2 +-
lib/main.js | 2 ++
lib/transport/eventsource.js | 22 ++++++++++++++++++++++
lib/transport/facade/eventsource.js | 17 -----------------
lib/transport/facade/htmlfile.js | 17 -----------------
lib/transport/facade/xhr-polling-iframe.js | 17 -----------------
lib/transport/htmlfile.js | 22 ++++++++++++++++++++++
lib/transport/iframe-eventsource.js | 23 -----------------------
lib/transport/iframe-htmlfile.js | 28 ----------------------------
lib/transport/iframe-wrap.js | 29 +++++++++++++++++++++++++++++
lib/transport/iframe-xhr-polling.js | 24 ------------------------
lib/transport/xhr-polling.js | 4 +---
lib/transport/xhr-streaming.js | 4 +---
lib/utils/object.js | 24 ++++++++++++++++++++++++
tests/transports.js | 3 +--
16 files changed, 114 insertions(+), 139 deletions(-)
diff --git a/lib/entry.js b/lib/entry.js
index c2fa15a..7a55954 100644
--- a/lib/entry.js
+++ b/lib/entry.js
@@ -1,17 +1,24 @@
'use strict';
+var EventSourceTransport = require('./transport/eventsource')
+ , HtmlFileTransport = require('./transport/htmlfile')
+ , XhrPollingTransport = require('./transport/xhr-polling')
+ ;
+
var transports = [
// streaming transports
require('./transport/websocket')
, require('./transport/xdr-streaming')
, require('./transport/xhr-streaming')
-, require('./transport/iframe-eventsource')
+, EventSourceTransport
+, require('./transport/iframe-wrap')(EventSourceTransport)
// polling transports
-, require('./transport/iframe-htmlfile')
+, HtmlFileTransport
+, require('./transport/iframe-wrap')(HtmlFileTransport)
, require('./transport/xdr-polling')
-, require('./transport/xhr-polling')
-, require('./transport/iframe-xhr-polling')
+, XhrPollingTransport
+, require('./transport/iframe-wrap')(XhrPollingTransport)
, require('./transport/jsonp-polling')
];
diff --git a/lib/iframe-bootstrap.js b/lib/iframe-bootstrap.js
index 2f8954f..ee8ad8f 100644
--- a/lib/iframe-bootstrap.js
+++ b/lib/iframe-bootstrap.js
@@ -5,7 +5,7 @@ var originUtils = require('./utils/origin')
, JSON3 = require('json3')
, FacadeJS = require('./facade')
, InfoIframeFacade = require('./transport/facade/info-receiver-iframe')
- , iframeUtils = require('./transports/lib/iframe-utils')
+ , iframeUtils = require('./transport/lib/iframe-utils')
, loc = require('./polyfills/location')
;
diff --git a/lib/main.js b/lib/main.js
index c865dc9..4d16c01 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -6,6 +6,7 @@ var u = require('url')
, util = require('util')
, random = require('./utils/random')
, escape = require('./utils/escape')
+ , origin = require('./utils/origin')
, SecurityError = require('./error/securityerror')
, InvalidAccessError = require('./error/invalidaccesserror')
, InvalidStateError = require('./error/invalidstateerror')
@@ -145,6 +146,7 @@ SockJS.prototype._receiveInfo = function(info, rtt) {
// allow server to override url used for the actual transport
this._transUrl = info.base_url ? info.base_url : this.url;
info.nullOrigin = global.document && !global.document.domain;
+ info.sameOrigin = origin.isSameOriginUrl(this.url, loc.href);
// determine list of desired and supported transports
var enabledTransports = transports(this.url, this._transportsWhitelist, info);
this._transports = enabledTransports.main;
diff --git a/lib/transport/eventsource.js b/lib/transport/eventsource.js
new file mode 100644
index 0000000..d6a613f
--- /dev/null
+++ b/lib/transport/eventsource.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var util = require('util')
+ , AjaxBasedTransport = require('./lib/ajax-based')
+ , EventSourceReceiver = require('./receiver/eventsource')
+ , XHRCorsObject = require('./sender/xhr-cors')
+ ;
+
+function EventSourceTransport(transUrl) {
+ AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);
+}
+
+util.inherits(EventSourceTransport, AjaxBasedTransport);
+
+EventSourceTransport.enabled = function () {
+ return ('EventSource' in global);
+};
+
+EventSourceTransport.transportName = 'eventsource';
+EventSourceTransport.roundTrips = 2;
+
+module.exports = EventSourceTransport;
diff --git a/lib/transport/facade/eventsource.js b/lib/transport/facade/eventsource.js
deleted file mode 100644
index aba9586..0000000
--- a/lib/transport/facade/eventsource.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict';
-
-var util = require('util')
- , AjaxBasedTransport = require('../lib/ajax-based')
- , EventSourceReceiver = require('../receiver/eventsource')
- , XHRLocalObject = require('../sender/xhr-local')
- ;
-
-function EventSourceTransport(transUrl) {
- AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRLocalObject);
-}
-
-util.inherits(EventSourceTransport, AjaxBasedTransport);
-
-EventSourceTransport.transportName = 'w-iframe-eventsource';
-
-module.exports = EventSourceTransport;
diff --git a/lib/transport/facade/htmlfile.js b/lib/transport/facade/htmlfile.js
deleted file mode 100644
index 81ae9b7..0000000
--- a/lib/transport/facade/htmlfile.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict';
-
-var util = require('util')
- , HtmlfileReceiver = require('../receiver/htmlfile')
- , XHRLocalObject = require('../sender/xhr-local')
- , AjaxBasedTransport = require('../lib/ajax-based')
- ;
-
-function HtmlFileTransport(transUrl) {
- AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
-}
-
-util.inherits(HtmlFileTransport, AjaxBasedTransport);
-
-HtmlFileTransport.transportName = 'w-iframe-htmlfile';
-
-module.exports = HtmlFileTransport;
diff --git a/lib/transport/facade/xhr-polling-iframe.js b/lib/transport/facade/xhr-polling-iframe.js
deleted file mode 100644
index da86150..0000000
--- a/lib/transport/facade/xhr-polling-iframe.js
+++ /dev/null
@@ -1,17 +0,0 @@
-'use strict';
-
-var util = require('util')
- , XhrReceiver = require('../receiver/xhr')
- , XHRLocalObject = require('../sender/xhr-local')
- , AjaxBasedTransport = require('../lib/ajax-based')
- ;
-
-function XhrPollingITransport(ri, transUrl) {
- AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRLocalObject);
-}
-
-util.inherits(XhrPollingITransport, AjaxBasedTransport);
-
-XhrPollingITransport.transportName = 'w-iframe-xhr-polling';
-
-module.exports = XhrPollingITransport;
diff --git a/lib/transport/htmlfile.js b/lib/transport/htmlfile.js
new file mode 100644
index 0000000..f790eb4
--- /dev/null
+++ b/lib/transport/htmlfile.js
@@ -0,0 +1,22 @@
+'use strict';
+
+var util = require('util')
+ , HtmlfileReceiver = require('./receiver/htmlfile')
+ , XHRLocalObject = require('./sender/xhr-local')
+ , AjaxBasedTransport = require('./lib/ajax-based')
+ ;
+
+function HtmlFileTransport(transUrl) {
+ AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
+}
+
+util.inherits(HtmlFileTransport, AjaxBasedTransport);
+
+HtmlFileTransport.enabled = function (url, info) {
+ return info.sameOrigin;
+};
+
+HtmlFileTransport.transportName = 'htmlfile';
+HtmlFileTransport.roundTrips = 2;
+
+module.exports = HtmlFileTransport;
diff --git a/lib/transport/iframe-eventsource.js b/lib/transport/iframe-eventsource.js
deleted file mode 100644
index 0e48d9a..0000000
--- a/lib/transport/iframe-eventsource.js
+++ /dev/null
@@ -1,23 +0,0 @@
-'use strict';
-
-var util = require('util')
- , IframeTransport = require('./lib/iframe')
- ;
-
-function EventSourceIframeTransport(transUrl, baseUrl) {
- IframeTransport.call(this, 'w-iframe-eventsource', transUrl, baseUrl);
-}
-
-util.inherits(EventSourceIframeTransport, IframeTransport);
-
-EventSourceIframeTransport.enabled = function () {
- return ('EventSource' in global) && IframeTransport.enabled();
-};
-
-EventSourceIframeTransport.transportName = 'iframe-eventsource';
-EventSourceIframeTransport.needBody = true;
-EventSourceIframeTransport.roundTrips = 3; // html, javascript, eventsource
-
-EventSourceIframeTransport.facadeTransport = require('./facade/eventsource');
-
-module.exports = EventSourceIframeTransport;
diff --git a/lib/transport/iframe-htmlfile.js b/lib/transport/iframe-htmlfile.js
deleted file mode 100644
index c48403e..0000000
--- a/lib/transport/iframe-htmlfile.js
+++ /dev/null
@@ -1,28 +0,0 @@
-'use strict';
-
-// This transport generally works in any browser, but will cause a
-// spinning cursor to appear in any browser other than IE.
-// We may test this transport in all browsers - why not, but in
-// production it should be only run in IE.
-
-var util = require('util')
- , IframeTransport = require('./lib/iframe')
- ;
-
-function HtmlFileIframeTransport(transUrl, baseUrl) {
- IframeTransport.call(this, 'w-iframe-htmlfile', transUrl, baseUrl);
-}
-
-util.inherits(HtmlFileIframeTransport, IframeTransport);
-
-HtmlFileIframeTransport.enabled = function() {
- return IframeTransport.enabled();
-};
-
-HtmlFileIframeTransport.transportName = 'iframe-htmlfile';
-HtmlFileIframeTransport.needBody = true;
-HtmlFileIframeTransport.roundTrips = 3; // html, javascript, htmlfile
-
-HtmlFileIframeTransport.facadeTransport = require('./facade/htmlfile');
-
-module.exports = HtmlFileIframeTransport;
diff --git a/lib/transport/iframe-wrap.js b/lib/transport/iframe-wrap.js
new file mode 100644
index 0000000..a13d7be
--- /dev/null
+++ b/lib/transport/iframe-wrap.js
@@ -0,0 +1,29 @@
+'use strict';
+
+var util = require('util')
+ , IframeTransport = require('./lib/iframe')
+ , objectUtils = require('../utils/object')
+ ;
+
+module.exports = function (transport) {
+
+ function IframeWrapTransport(transUrl, baseUrl) {
+ IframeTransport.call(this, transport.transportName, transUrl, baseUrl);
+ }
+
+ util.inherits(IframeWrapTransport, IframeTransport);
+
+ IframeWrapTransport.enabled = function (url, info) {
+ var iframeInfo = objectUtils.extend({}, info);
+ iframeInfo.sameOrigin = true;
+ return transport.enabled(url, iframeInfo) && IframeTransport.enabled();
+ };
+
+ IframeWrapTransport.transportName = 'iframe-' + transport.transportName;
+ IframeWrapTransport.needBody = true;
+ IframeWrapTransport.roundTrips = transport.roundTrips + 1; // html, javascript (2) + transport - no CORS (1)
+
+ IframeWrapTransport.facadeTransport = transport;
+
+ return IframeWrapTransport;
+};
diff --git a/lib/transport/iframe-xhr-polling.js b/lib/transport/iframe-xhr-polling.js
deleted file mode 100644
index 231460c..0000000
--- a/lib/transport/iframe-xhr-polling.js
+++ /dev/null
@@ -1,24 +0,0 @@
-'use strict';
-
-var util = require('util')
- , IframeTransport = require('./lib/iframe')
- , XHRLocalObject = require('./sender/xhr-local')
- ;
-
-function XhrPollingIframeTransport(transUrl, baseUrl) {
- IframeTransport.call(this, 'w-iframe-xhr-polling', transUrl, baseUrl);
-}
-
-util.inherits(XhrPollingIframeTransport, IframeTransport);
-
-XhrPollingIframeTransport.enabled = function () {
- return XHRLocalObject.enabled && IframeTransport.enabled();
-};
-
-XhrPollingIframeTransport.transportName = 'iframe-xhr-polling';
-XhrPollingIframeTransport.needBody = true;
-XhrPollingIframeTransport.roundTrips = 3; // html, javascript, xhr
-
-XhrPollingIframeTransport.facadeTransport = require('./facade/xhr-polling-iframe');
-
-module.exports = XhrPollingIframeTransport;
diff --git a/lib/transport/xhr-polling.js b/lib/transport/xhr-polling.js
index cbc2fcd..f89959d 100644
--- a/lib/transport/xhr-polling.js
+++ b/lib/transport/xhr-polling.js
@@ -5,8 +5,6 @@ var util = require('util')
, XhrReceiver = require('./receiver/xhr')
, XHRCorsObject = require('./sender/xhr-cors')
, XHRLocalObject = require('./sender/xhr-local')
- , utils = require('../utils/origin')
- , loc = require('../polyfills/location')
;
function XhrPollingTransport(transUrl) {
@@ -20,7 +18,7 @@ XhrPollingTransport.enabled = function(url, info) {
return false;
}
- if (XHRLocalObject.enabled && utils.isSameOriginUrl(url, loc.href)) {
+ if (XHRLocalObject.enabled && info.sameOrigin) {
return true;
}
return XHRCorsObject.enabled;
diff --git a/lib/transport/xhr-streaming.js b/lib/transport/xhr-streaming.js
index 0a2344e..06625ef 100644
--- a/lib/transport/xhr-streaming.js
+++ b/lib/transport/xhr-streaming.js
@@ -5,9 +5,7 @@ var util = require('util')
, XhrReceiver = require('./receiver/xhr')
, XHRCorsObject = require('./sender/xhr-cors')
, XHRLocalObject = require('./sender/xhr-local')
- , utils = require('../utils/origin')
, browser = require('../utils/browser')
- , loc = require('../polyfills/location')
;
function XhrStreamingTransport(transUrl) {
@@ -25,7 +23,7 @@ XhrStreamingTransport.enabled = function(url, info) {
return false;
}
- if (XHRLocalObject.enabled && utils.isSameOriginUrl(url, loc.href)) {
+ if (XHRLocalObject.enabled && info.sameOrigin) {
return true;
}
return XHRCorsObject.enabled;
diff --git a/lib/utils/object.js b/lib/utils/object.js
new file mode 100644
index 0000000..6e98496
--- /dev/null
+++ b/lib/utils/object.js
@@ -0,0 +1,24 @@
+'use strict';
+
+module.exports = {
+ isObject: function(obj) {
+ var type = typeof obj;
+ return type === 'function' || type === 'object' && !!obj;
+ }
+
+, extend: function(obj) {
+ if (!this.isObject(obj)) {
+ return obj;
+ }
+ var source, prop;
+ for (var i = 1, length = arguments.length; i < length; i++) {
+ source = arguments[i];
+ for (prop in source) {
+ if (hasOwnProperty.call(source, prop)) {
+ obj[prop] = source[prop];
+ }
+ }
+ }
+ return obj;
+ }
+};
diff --git a/tests/transports.js b/tests/transports.js
index f5c1425..e7e3971 100644
--- a/tests/transports.js
+++ b/tests/transports.js
@@ -3,14 +3,13 @@
var expect = require('expect.js')
, fs = require('fs')
, path = require('path')
- , EventTarget = require('../lib/polyfills/eventtarget')
;
var transportFiles = [];
var dir = path.resolve(__dirname, '../lib/transport');
var files = fs.readdirSync(dir);
files.forEach(function (file) {
- if (file[0] === '.') {
+ if (file[0] === '.' || file === 'iframe-wrap.js') {
return;
}
var fileName = path.resolve(dir, file);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list