[Pkg-javascript-commits] [sockjs-client] 116/350: Much better way of handling transport list
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 8ed432fdac4b1c1fae07371ab2ea936db9ee48ad
Author: Bryce Kahle <bkahle at gmail.com>
Date: Fri Oct 10 15:30:40 2014 -0400
Much better way of handling transport list
---
lib/entry.js | 24 ++----------------------
lib/info-receiver-iframe.js | 2 +-
lib/info-receiver.js | 2 +-
lib/{entry.js => transport-list.js} | 4 +---
lib/transport/{lib => }/iframe.js | 19 +++++++++++--------
lib/transport/lib/iframe-wrap.js | 4 ++--
tests/transports.js | 23 +++--------------------
7 files changed, 21 insertions(+), 57 deletions(-)
diff --git a/lib/entry.js b/lib/entry.js
index 1326cdd..342b8a0 100644
--- a/lib/entry.js
+++ b/lib/entry.js
@@ -1,25 +1,5 @@
'use strict';
-var EventSourceTransport = require('./transport/eventsource')
- , HtmlFileTransport = require('./transport/htmlfile')
- , XhrPollingTransport = require('./transport/xhr-polling')
- ;
+var transportList = require('./transport-list');
-var transports = [
- // streaming transports
- require('./transport/websocket')
-, require('./transport/xdr-streaming')
-, require('./transport/xhr-streaming')
-, EventSourceTransport
-, require('./transport/lib/iframe-wrap')(EventSourceTransport)
-
- // polling transports
-, HtmlFileTransport
-, require('./transport/lib/iframe-wrap')(HtmlFileTransport)
-, require('./transport/xdr-polling')
-, XhrPollingTransport
-, require('./transport/lib/iframe-wrap')(XhrPollingTransport)
-, require('./transport/jsonp-polling')
-];
-
-module.exports = require('./main')(transports);
+module.exports = require('./main')(transportList);
diff --git a/lib/info-receiver-iframe.js b/lib/info-receiver-iframe.js
index f3aa2a6..4b6c8a3 100644
--- a/lib/info-receiver-iframe.js
+++ b/lib/info-receiver-iframe.js
@@ -4,7 +4,7 @@ var EventEmitter = require('events').EventEmitter
, util = require('util')
, JSON3 = require('json3')
, utils = require('./utils/event')
- , IframeTransport = require('./transport/lib/iframe')
+ , IframeTransport = require('./transport/iframe')
;
function InfoReceiverIframe(method, url) {
diff --git a/lib/info-receiver.js b/lib/info-receiver.js
index 9a569e7..a3d9d1f 100644
--- a/lib/info-receiver.js
+++ b/lib/info-receiver.js
@@ -11,7 +11,7 @@ var EventEmitter = require('events').EventEmitter
, XHRFake = require('./transport/sender/xhr-fake')
// it seems odd to include these just for the 'enabled' function
, XDRPolling = require('./transport/xdr-polling')
- , IframeTransport = require('./transport/lib/iframe')
+ , IframeTransport = require('./transport/iframe')
, InfoIframe = require('./info-receiver-iframe')
;
diff --git a/lib/entry.js b/lib/transport-list.js
similarity index 91%
copy from lib/entry.js
copy to lib/transport-list.js
index 1326cdd..985aa32 100644
--- a/lib/entry.js
+++ b/lib/transport-list.js
@@ -5,7 +5,7 @@ var EventSourceTransport = require('./transport/eventsource')
, XhrPollingTransport = require('./transport/xhr-polling')
;
-var transports = [
+module.exports = [
// streaming transports
require('./transport/websocket')
, require('./transport/xdr-streaming')
@@ -21,5 +21,3 @@ var transports = [
, require('./transport/lib/iframe-wrap')(XhrPollingTransport)
, require('./transport/jsonp-polling')
];
-
-module.exports = require('./main')(transports);
diff --git a/lib/transport/lib/iframe.js b/lib/transport/iframe.js
similarity index 86%
rename from lib/transport/lib/iframe.js
rename to lib/transport/iframe.js
index f74ed77..c8d70ba 100644
--- a/lib/transport/lib/iframe.js
+++ b/lib/transport/iframe.js
@@ -9,15 +9,15 @@
// http://stevesouders.com/misc/test-postmessage.php
var util = require('util')
- , EventTarget = require('../../polyfills/eventtarget')
- , CloseEvent = require('./closeevent')
- , TransportMessageEvent = require('./trans-message-event')
, JSON3 = require('json3')
- , originUtils = require('../../utils/origin')
- , iframeUtils = require('../../utils/iframe')
- , eventUtils = require('../../utils/event')
- , random = require('../../utils/random')
- , browser = require('../../utils/browser')
+ , EventTarget = require('../polyfills/eventtarget')
+ , CloseEvent = require('./lib/closeevent')
+ , TransportMessageEvent = require('./lib/trans-message-event')
+ , originUtils = require('../utils/origin')
+ , iframeUtils = require('../utils/iframe')
+ , eventUtils = require('../utils/event')
+ , random = require('../utils/random')
+ , browser = require('../utils/browser')
;
function IframeTransport(transport, transUrl, baseUrl) {
@@ -109,4 +109,7 @@ IframeTransport.enabled = function() {
typeof global.postMessage === 'object') && (!browser.isKonqueror()));
};
+IframeTransport.transportName = 'iframe';
+IframeTransport.roundTrips = 2;
+
module.exports = IframeTransport;
diff --git a/lib/transport/lib/iframe-wrap.js b/lib/transport/lib/iframe-wrap.js
index 4eb5465..87e9856 100644
--- a/lib/transport/lib/iframe-wrap.js
+++ b/lib/transport/lib/iframe-wrap.js
@@ -1,7 +1,7 @@
'use strict';
var util = require('util')
- , IframeTransport = require('./iframe')
+ , IframeTransport = require('../iframe')
, objectUtils = require('../../utils/object')
;
@@ -21,7 +21,7 @@ module.exports = function (transport) {
IframeWrapTransport.transportName = 'iframe-' + transport.transportName;
IframeWrapTransport.needBody = true;
- IframeWrapTransport.roundTrips = transport.roundTrips + 1; // html, javascript (2) + transport - no CORS (1)
+ IframeWrapTransport.roundTrips = IframeTransport.roundTrips + transport.roundTrips - 1; // html, javascript (2) + transport - no CORS (1)
IframeWrapTransport.facadeTransport = transport;
diff --git a/tests/transports.js b/tests/transports.js
index 2af605f..2156903 100644
--- a/tests/transports.js
+++ b/tests/transports.js
@@ -1,30 +1,13 @@
'use strict';
var expect = require('expect.js')
- , fs = require('fs')
- , path = require('path')
+ , transportList = require('../lib/transport-list')
;
-var transportFiles = [];
-var dir = path.resolve(__dirname, '../lib/transport');
-var files = fs.readdirSync(dir);
-files.forEach(function (file) {
- if (file[0] === '.') {
- return;
- }
- var fileName = path.resolve(dir, file);
- var stat = fs.statSync(fileName);
- if (stat && stat.isDirectory()) {
- return;
- }
- transportFiles.push(fileName);
-});
-
describe('Transports', function () {
- transportFiles.forEach(function (tf) {
- describe(path.basename(tf, '.js'), function () {
+ transportList.forEach(function (Trans) {
+ describe(Trans.transportName, function () {
it('has a valid interface', function () {
- var Trans = require(tf);
expect(Trans).to.be.ok();
expect(Trans).to.have.property('transportName');
expect(Trans.transportName.length).to.be.greaterThan(0);
--
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