[Pkg-javascript-commits] [sockjs-client] 92/350: More cleanup and re-organization
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:46 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 3b7ea9d9228db61b361d7821768dce2ac60f1b6c
Author: Bryce Kahle <bkahle at gmail.com>
Date: Wed Oct 8 00:11:11 2014 -0400
More cleanup and re-organization
---
lib/facade.js | 4 +-
.../info-receiver-iframe.js} | 6 +--
lib/info-receiver-iframe.js | 2 +-
lib/info-receiver.js | 2 +-
lib/sockjs.js | 4 +-
lib/trans-eventsource.js | 15 -------
lib/trans-htmlfile.js | 15 -------
lib/transport/iframe-eventsource.js | 2 +-
lib/transport/iframe-htmlfile.js | 2 +-
lib/transport/iframe-xhr-polling.js | 2 +-
lib/transport/jsonp-polling.js | 50 +++++++++++-----------
lib/{ => transport/lib}/ajax-based.js | 25 ++++++-----
lib/{ => transport/lib}/buffered-sender.js | 34 ++++++++++-----
lib/transport/lib/eventsource.js | 15 +++++++
lib/transport/lib/htmlfile.js | 15 +++++++
lib/{trans-iframe.js => transport/lib/iframe.js} | 47 +++++++++++++-------
lib/{trans-polling.js => transport/lib/polling.js} | 19 ++++++--
.../lib/receiver-eventsource.js} | 4 +-
.../lib/receiver-htmlfile.js} | 6 +--
.../lib/receiver-xhr.js} | 4 +-
lib/{ => transport/lib}/xhr-polling-iframe.js | 6 +--
lib/transport/xdr-polling.js | 6 +--
lib/transport/xdr-streaming.js | 8 ++--
lib/transport/xhr-polling.js | 8 ++--
lib/transport/xhr-streaming.js | 6 +--
lib/utils.js | 6 +--
lib/xdr.js | 2 +-
tests/html/lib/domtests.js | 2 +-
tests/transports.js | 17 +++++++-
29 files changed, 193 insertions(+), 141 deletions(-)
diff --git a/lib/facade.js b/lib/facade.js
index 512d905..d6ceb76 100644
--- a/lib/facade.js
+++ b/lib/facade.js
@@ -10,10 +10,10 @@ FacadeJS.prototype._didMessage = function (frame) {
utils.postMessage('t', frame);
};
FacadeJS.prototype._doSend = function (data) {
- this._transport.doSend(data);
+ this._transport.send(data);
};
FacadeJS.prototype._doCleanup = function () {
- this._transport.doCleanup();
+ this._transport.close();
};
module.exports = FacadeJS;
diff --git a/lib/trans-receiver-iframe.js b/lib/facade/info-receiver-iframe.js
similarity index 68%
rename from lib/trans-receiver-iframe.js
rename to lib/facade/info-receiver-iframe.js
index 31dad88..6166f0e 100644
--- a/lib/trans-receiver-iframe.js
+++ b/lib/facade/info-receiver-iframe.js
@@ -1,8 +1,8 @@
'use strict';
-var XHRLocalObject = require('./xhr-local')
+var XHRLocalObject = require('../xhr-local')
, JSON3 = require('json3')
- , InfoReceiver = require('./info-receiver')
+ , InfoReceiver = require('../info-receiver')
;
function WInfoReceiverIframe(ri, transUrl, baseUrl) {
@@ -13,6 +13,6 @@ function WInfoReceiverIframe(ri, transUrl, baseUrl) {
});
}
-WInfoReceiverIframe.prototype.doCleanup = function() {};
+WInfoReceiverIframe.prototype.close = function() {};
module.exports = WInfoReceiverIframe;
diff --git a/lib/info-receiver-iframe.js b/lib/info-receiver-iframe.js
index d957cb8..61780de 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')
- , IframeTransport = require('./trans-iframe')
+ , IframeTransport = require('./transport/lib/iframe')
;
function InfoReceiverIframe(baseUrl) {
diff --git a/lib/info-receiver.js b/lib/info-receiver.js
index d61eed0..45b511d 100644
--- a/lib/info-receiver.js
+++ b/lib/info-receiver.js
@@ -11,7 +11,7 @@ var EventEmitter = require('events').EventEmitter
, XHRFake = require('./xhr-fake')
// it seems odd to include these just for the 'enabled' function
, XDRPolling = require('./transport/xdr-polling')
- //, IframeTransport = require('./trans-iframe')
+ //, IframeTransport = require('./transport/lib/iframe')
;
function InfoReceiver(baseUrl) {
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 8691425..9ef0b59 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -19,7 +19,7 @@ var XHRLocalObject = require('./xhr-local');
var XHRCorsObject = require('./xhr-cors');
var XDRObject = require('./xdr');
var XDRPolling = require('./trans-xdr-polling');
-var IframeTransport = require('./trans-iframe');
+var IframeTransport = require('./transport/lib/iframe');
var protocols = require('./protocols');
@@ -324,7 +324,7 @@ SockJS.bootstrap_iframe = function() {
module.exports = SockJS;
-FacadeJS['w-iframe-info-receiver'] = require('./info-receiver-iframe');
+FacadeJS['w-iframe-info-receiver'] = require('./trans-receiver-iframe');
FacadeJS['w-iframe-eventsource'] = require('./trans-eventsource');
FacadeJS['w-iframe-htmlfile'] = require('./trans-htmlfile');
FacadeJS['w-iframe-xhr-polling'] = require('./xhr-polling-iframe');
diff --git a/lib/trans-eventsource.js b/lib/trans-eventsource.js
deleted file mode 100644
index 18d85fe..0000000
--- a/lib/trans-eventsource.js
+++ /dev/null
@@ -1,15 +0,0 @@
-'use strict';
-
-var util = require('util')
- , AjaxBasedTransport = require('./ajax-based')
- , EventSourceReceiver = require('./trans-receiver-eventsource')
- , XHRLocalObject = require('./xhr-local')
- ;
-
-function EventSourceTransport(ri, transUrl) {
- this.run(ri, transUrl, '/eventsource', EventSourceReceiver, XHRLocalObject);
-}
-
-util.inherits(EventSourceTransport, AjaxBasedTransport);
-
-module.exports = EventSourceTransport;
diff --git a/lib/trans-htmlfile.js b/lib/trans-htmlfile.js
deleted file mode 100644
index fc85aea..0000000
--- a/lib/trans-htmlfile.js
+++ /dev/null
@@ -1,15 +0,0 @@
-'use strict';
-
-var util = require('util')
- , HtmlfileReceiver = require('./trans-receiver-htmlfile')
- , XHRLocalObject = require('./xhr-local')
- , AjaxBasedTransport = require('./ajax-based')
- ;
-
-function HtmlFileTransport(ri, transUrl) {
- this.run(ri, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
-}
-
-util.inherits(HtmlFileTransport, AjaxBasedTransport);
-
-module.exports = HtmlFileTransport;
diff --git a/lib/transport/iframe-eventsource.js b/lib/transport/iframe-eventsource.js
index 002b3e7..ccab083 100644
--- a/lib/transport/iframe-eventsource.js
+++ b/lib/transport/iframe-eventsource.js
@@ -1,7 +1,7 @@
'use strict';
var util = require('util')
- , IframeTransport = require('../trans-iframe')
+ , IframeTransport = require('./lib/iframe')
;
function EventSourceIframeTransport() {
diff --git a/lib/transport/iframe-htmlfile.js b/lib/transport/iframe-htmlfile.js
index aaf2a46..9e443bd 100644
--- a/lib/transport/iframe-htmlfile.js
+++ b/lib/transport/iframe-htmlfile.js
@@ -6,7 +6,7 @@
// production it should be only run in IE.
var util = require('util')
- , IframeTransport = require('../trans-iframe')
+ , IframeTransport = require('./lib/iframe')
;
function HtmlFileIframeTransport() {
diff --git a/lib/transport/iframe-xhr-polling.js b/lib/transport/iframe-xhr-polling.js
index 3339766..a22d29d 100644
--- a/lib/transport/iframe-xhr-polling.js
+++ b/lib/transport/iframe-xhr-polling.js
@@ -1,7 +1,7 @@
'use strict';
var util = require('util')
- , IframeTransport = require('../trans-iframe')
+ , IframeTransport = require('./lib/iframe')
;
function XhrPollingIframeTransport() {
diff --git a/lib/transport/jsonp-polling.js b/lib/transport/jsonp-polling.js
index faefb91..6e42fa3 100644
--- a/lib/transport/jsonp-polling.js
+++ b/lib/transport/jsonp-polling.js
@@ -10,7 +10,8 @@
var util = require('util')
, utils = require('../utils')
- , BufferedSender = require('../buffered-sender')
+ , BufferedSender = require('./lib/buffered-sender')
+ , TransportMessageEvent = require('../trans-message-event')
;
// Abstract away code that handles global namespace pollution.
@@ -47,7 +48,9 @@ var jsonPReceiverWrapper = function(url, constructReceiver, userCallback) {
var stop = function() {
if (window[utils.WPrefix][id]) {
aborting = 1;
- window[utils.WPrefix][id](utils.closeFrame(1000, 'JSONP user aborted read'));
+ var err = new Error('JSONP user aborted read');
+ err.code = 1000;
+ window[utils.WPrefix][id](err);
}
};
return stop;
@@ -106,7 +109,7 @@ function jsonPGenericSender(url, payload, callback) {
area.value = '';
// It is not possible to detect if the iframe succeeded or
// failed to submit our form.
- callback(true);
+ callback();
};
iframe.onerror = iframe.onload = completed;
iframe.onreadystatechange = function() {
@@ -123,9 +126,9 @@ function jsonPGenericSender(url, payload, callback) {
// https://code.google.com/p/jquery-jsonp/source/browse/trunk/core/jquery.jsonp.js
function jsonPGenericReceiver(url, callback) {
var tref;
- var script = document.createElement('script');
+ var script = global.document.createElement('script');
var script2; // Opera synchronous load trick.
- var closeScript = function(frame) {
+ var closeScript = function(err) {
if (script2) {
script2.parentNode.removeChild(script2);
script2 = null;
@@ -138,7 +141,7 @@ function jsonPGenericReceiver(url, callback) {
script.onreadystatechange = script.onerror =
script.onload = script.onclick = null;
script = null;
- callback(frame);
+ callback(err);
callback = null;
}
};
@@ -156,15 +159,13 @@ function jsonPGenericReceiver(url, callback) {
// Delay firing closeScript.
errorTimer = setTimeout(function() {
if (!loadedOkay) {
- closeScript(utils.closeFrame(
- 1006,
- 'JSONP script loaded abnormally (onerror)'));
+ closeScript(new Error('JSONP script loaded abnormally (onerror)'));
}
}, 1000);
}
};
script.onload = function() {
- closeScript(utils.closeFrame(1006, 'JSONP script loaded abnormally (onload)'));
+ closeScript(new Error('JSONP script loaded abnormally (onload)'));
};
script.onreadystatechange = function() {
@@ -177,7 +178,7 @@ function jsonPGenericReceiver(url, callback) {
} catch (x) {}
}
if (script) {
- closeScript(utils.closeFrame(1006, 'JSONP script loaded abnormally (onreadystatechange)'));
+ closeScript(new Error('JSONP script loaded abnormally (onreadystatechange)'));
}
}
};
@@ -215,7 +216,7 @@ function jsonPGenericReceiver(url, callback) {
// Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
tref = setTimeout(function() {
- closeScript(utils.closeFrame(1006, 'JSONP script loaded abnormally (timeout)'));
+ closeScript(new Error('JSONP script loaded abnormally (timeout)'));
}, 35000);
var head = document.getElementsByTagName('head')[0];
@@ -226,11 +227,10 @@ function jsonPGenericReceiver(url, callback) {
return closeScript;
}
-function JsonPTransport(ri, transUrl) {
+function JsonPTransport(transUrl) {
utils.polluteGlobalNamespace();
- this.ri = ri;
this.transUrl = transUrl;
- this.sendConstructor(jsonPGenericSender);
+ BufferedSender.call(this, transUrl, jsonPGenericSender);
this._scheduleReceiver();
}
@@ -243,7 +243,7 @@ JsonPTransport.prototype._scheduleReceiver = function() {
if (data) {
// no data - heartbeat;
if (!self._isClosing) {
- self.ri._didMessage(data);
+ self.dispatchEvent(new TransportMessageEvent(data));
}
}
// The message can be a close message, and change is_closing state.
@@ -255,6 +255,15 @@ JsonPTransport.prototype._scheduleReceiver = function() {
jsonPGenericReceiver, callback);
};
+JsonPTransport.prototype.close = function() {
+ this._isClosing = true;
+ if (this._receiveStop) {
+ this._receiveStop();
+ }
+ this._receiveStop = null;
+ this.stop();
+};
+
JsonPTransport.enabled = function() {
return true;
};
@@ -263,13 +272,4 @@ JsonPTransport.transportName = 'jsonp-polling';
JsonPTransport.roundTrips = 1;
JsonPTransport.needBody = true;
-JsonPTransport.prototype.doCleanup = function() {
- this._isClosing = true;
- if (this._receiveStop) {
- this._receiveStop();
- }
- this.ri = this._receiveStop = null;
- this.sendDestructor();
-};
-
module.exports = JsonPTransport;
diff --git a/lib/ajax-based.js b/lib/transport/lib/ajax-based.js
similarity index 52%
rename from lib/ajax-based.js
rename to lib/transport/lib/ajax-based.js
index fa5c72d..9257328 100644
--- a/lib/ajax-based.js
+++ b/lib/transport/lib/ajax-based.js
@@ -2,7 +2,7 @@
var util = require('util')
, BufferedSender = require('./buffered-sender')
- , Polling = require('./trans-polling')
+ , Polling = require('./polling')
;
function createAjaxSender(AjaxObject) {
@@ -13,31 +13,30 @@ function createAjaxSender(AjaxObject) {
}
var xo = new AjaxObject('POST', url + '/xhr_send', payload, opt);
xo.on('finish', function(status) {
- callback(status === 200 || status === 204, 'http status ' + status);
+ if (status !== 200 && status !== 204) {
+ return callback(new Error('http status ' + status));
+ }
+ callback();
});
- return function(abortReason) {
- callback(false, abortReason);
+ return function() {
+ callback();
};
};
}
-function AjaxBasedTransport() {
+function AjaxBasedTransport(transUrl, urlSuffix, Receiver, AjaxObject) {
+ BufferedSender.call(this, transUrl, createAjaxSender(AjaxObject));
+ this.poll = new Polling(Receiver, transUrl + urlSuffix, AjaxObject);
}
util.inherits(AjaxBasedTransport, BufferedSender);
-AjaxBasedTransport.prototype.run = function(ri, transUrl, urlSuffix, Receiver, AjaxObject) {
- this.ri = ri;
- this.transUrl = transUrl;
- this.sendConstructor(createAjaxSender(AjaxObject));
- this.poll = new Polling(ri, Receiver, transUrl + urlSuffix, AjaxObject);
-};
-
-AjaxBasedTransport.prototype.doCleanup = function() {
+AjaxBasedTransport.prototype.close = function() {
if (this.poll) {
this.poll.abort();
this.poll = null;
}
+ this.stop();
};
module.exports = AjaxBasedTransport;
diff --git a/lib/buffered-sender.js b/lib/transport/lib/buffered-sender.js
similarity index 64%
rename from lib/buffered-sender.js
rename to lib/transport/lib/buffered-sender.js
index 768df4c..4853534 100644
--- a/lib/buffered-sender.js
+++ b/lib/transport/lib/buffered-sender.js
@@ -1,11 +1,20 @@
'use strict';
-function BufferedSender() {}
-BufferedSender.prototype.sendConstructor = function(sender) {
+var util = require('util')
+ , EventTarget = require('../../polyfills/eventtarget')
+ , CloseEvent = require('../../closeevent')
+ ;
+
+function BufferedSender(url, sender) {
+ EventTarget.call(this);
this.sendBuffer = [];
this.sender = sender;
-};
-BufferedSender.prototype.doSend = function(message) {
+ this.url = url;
+}
+
+util.inherits(BufferedSender, EventTarget);
+
+BufferedSender.prototype.send = function(message) {
this.sendBuffer.push(message);
if (!this.sendStop) {
this.sendSchedule();
@@ -37,10 +46,13 @@ BufferedSender.prototype.sendSchedule = function() {
var self = this;
if (this.sendBuffer.length > 0) {
var payload = '[' + this.sendBuffer.join(',') + ']';
- this.sendStop = this.sender(this.transUrl, payload, function(success, abortReason) {
+ this.sendStop = this.sender(this.url, payload, function(err) {
self.sendStop = null;
- if (success === false) {
- self.ri._didClose(1006, 'Sending error ' + abortReason);
+ if (err) {
+ var closeEvent = new CloseEvent();
+ closeEvent.code = err.code || 1006;
+ closeEvent.reason = 'Sending error: ' + err;
+ self.dispatchEvent(closeEvent);
} else {
self.sendScheduleWait();
}
@@ -49,11 +61,11 @@ BufferedSender.prototype.sendSchedule = function() {
}
};
-BufferedSender.prototype.sendDestructor = function() {
- if (this._sendStop) {
- this._sendStop();
+BufferedSender.prototype.stop = function() {
+ if (this.sendStop) {
+ this.sendStop();
}
- this._sendStop = null;
+ this.sendStop = null;
};
module.exports = BufferedSender;
diff --git a/lib/transport/lib/eventsource.js b/lib/transport/lib/eventsource.js
new file mode 100644
index 0000000..21fab00
--- /dev/null
+++ b/lib/transport/lib/eventsource.js
@@ -0,0 +1,15 @@
+'use strict';
+
+var util = require('util')
+ , AjaxBasedTransport = require('./ajax-based')
+ , EventSourceReceiver = require('./receiver-eventsource')
+ , XHRLocalObject = require('../../xhr-local')
+ ;
+
+function EventSourceTransport(transUrl) {
+ AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRLocalObject);
+}
+
+util.inherits(EventSourceTransport, AjaxBasedTransport);
+
+module.exports = EventSourceTransport;
diff --git a/lib/transport/lib/htmlfile.js b/lib/transport/lib/htmlfile.js
new file mode 100644
index 0000000..26c8fff
--- /dev/null
+++ b/lib/transport/lib/htmlfile.js
@@ -0,0 +1,15 @@
+'use strict';
+
+var util = require('util')
+ , HtmlfileReceiver = require('./receiver-htmlfile')
+ , XHRLocalObject = require('../../xhr-local')
+ , AjaxBasedTransport = require('./ajax-based')
+ ;
+
+function HtmlFileTransport(transUrl) {
+ AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
+}
+
+util.inherits(HtmlFileTransport, AjaxBasedTransport);
+
+module.exports = HtmlFileTransport;
diff --git a/lib/trans-iframe.js b/lib/transport/lib/iframe.js
similarity index 66%
rename from lib/trans-iframe.js
rename to lib/transport/lib/iframe.js
index 96ba69f..082b916 100644
--- a/lib/trans-iframe.js
+++ b/lib/transport/lib/iframe.js
@@ -8,34 +8,46 @@
// http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
// http://stevesouders.com/misc/test-postmessage.php
-var JSON3 = require('json3');
-var utils = require('./utils');
+var util = require('util')
+ , EventTarget = require('../../polyfills/eventtarget')
+ , CloseEvent = require('../../closeevent')
+ , TransportMessageEvent = require('../../trans-message-event')
+ , JSON3 = require('json3')
+ , utils = require('../../utils')
+ ;
-function IframeTransport() {}
+function IframeTransport() {
+ EventTarget.call(this);
+}
-IframeTransport.prototype.start = function(ri, transUrl, baseUrl) {
+util.inherits(IframeTransport, EventTarget);
+
+IframeTransport.prototype.start = function(transUrl, baseUrl) {
var self = this;
- this.ri = ri;
this.origin = utils.getOrigin(baseUrl);
this.baseUrl = baseUrl;
this.transUrl = transUrl;
var iframeUrl = baseUrl + '/iframe.html';
- if (this.ri._devel) {
- iframeUrl += '?t=' + Date.now();
- }
+ // TODO figure out how to get this info again
+ // if (this.ri._devel) {
+ // iframeUrl += '?t=' + Date.now();
+ // }
this.windowId = utils.randomString(8);
iframeUrl += '#' + this.windowId;
this.iframeObj = utils.createIframe(iframeUrl, function(r) {
- self.ri._didClose(1006, 'Unable to load an iframe (' + r + ')');
+ var closeEvent = new CloseEvent();
+ closeEvent.code = 1006;
+ closeEvent.reason = 'Unable to load an iframe (' + r + ')';
+ self.dispatchEvent(closeEvent);
});
- this.onmessageCallback = utils.bind(this.onmessage, this);
+ this.onmessageCallback = this._message.bind(this);
utils.attachMessage(this.onmessageCallback);
};
-IframeTransport.prototype.doCleanup = function() {
+IframeTransport.prototype.close = function() {
if (this.iframeObj) {
utils.detachMessage(this.onmessageCallback);
try {
@@ -49,7 +61,7 @@ IframeTransport.prototype.doCleanup = function() {
}
};
-IframeTransport.prototype.onmessage = function(e) {
+IframeTransport.prototype._message = function(e) {
if (!utils.isSameOriginUrl(e.origin, this.origin)) {
return;
}
@@ -66,10 +78,15 @@ IframeTransport.prototype.onmessage = function(e) {
case 's':
this.iframeObj.loaded();
// window global dependency
- this.postMessage('s', JSON3.stringify([window.SockJS.version, this.protocol, this.transUrl, this.baseUrl]));
+ this.postMessage('s', JSON3.stringify([
+ global.SockJS.version
+ , this.protocol
+ , this.transUrl
+ , this.baseUrl
+ ]));
break;
case 't':
- this.ri._didMessage(data);
+ this.dispatchEvent(new TransportMessageEvent(data));
break;
}
};
@@ -78,7 +95,7 @@ IframeTransport.prototype.postMessage = function(type, data) {
this.iframeObj.post(this.windowId + type + (data || ''), this.origin);
};
-IframeTransport.prototype.doSend = function (message) {
+IframeTransport.prototype.send = function (message) {
this.postMessage('m', message);
};
diff --git a/lib/trans-polling.js b/lib/transport/lib/polling.js
similarity index 57%
rename from lib/trans-polling.js
rename to lib/transport/lib/polling.js
index 47459e3..efde094 100644
--- a/lib/trans-polling.js
+++ b/lib/transport/lib/polling.js
@@ -1,24 +1,35 @@
'use strict';
-function Polling(ri, Receiver, receiveUrl, AjaxObject) {
- this.ri = ri;
+var util = require('util')
+ , EventTarget = require('../../polyfills/eventtarget')
+ , TransMessageEvent = require('../../trans-message-event')
+ , CloseEvent = require('../../closeevent')
+ ;
+
+function Polling(Receiver, receiveUrl, AjaxObject) {
+ EventTarget.call(this);
this.Receiver = Receiver;
this.receiveUrl = receiveUrl;
this.AjaxObject = AjaxObject;
this._scheduleReceiver();
}
+util.inherits(Polling, EventTarget);
+
Polling.prototype._scheduleReceiver = function() {
var self = this;
var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);
poll.onmessage = function(e) {
- self.ri._didMessage(e.data);
+ self.dispatchEvent(new TransMessageEvent(e.data));
};
poll.onclose = function(e) {
self.poll = poll = poll.onmessage = poll.onclose = null;
if (!self.pollIsClosing) {
if (e.reason === 'permanent') {
- self.ri._didClose(1006, 'Polling error (' + e.reason + ')');
+ var ce = new CloseEvent();
+ ce.code = 1006;
+ ce.reason = 'Polling error (' + e.reason + ')';
+ self.dispatchEvent(ce);
} else {
self._scheduleReceiver();
}
diff --git a/lib/trans-receiver-eventsource.js b/lib/transport/lib/receiver-eventsource.js
similarity index 91%
rename from lib/trans-receiver-eventsource.js
rename to lib/transport/lib/receiver-eventsource.js
index cec679b..74897b3 100644
--- a/lib/trans-receiver-eventsource.js
+++ b/lib/transport/lib/receiver-eventsource.js
@@ -1,8 +1,8 @@
'use strict';
var util = require('util')
- , SimpleEvent = require('./simpleevent')
- , EventTarget = require('./polyfills/eventtarget')
+ , SimpleEvent = require('../../simpleevent')
+ , EventTarget = require('../../polyfills/eventtarget')
;
function EventSourceReceiver(url) {
diff --git a/lib/trans-receiver-htmlfile.js b/lib/transport/lib/receiver-htmlfile.js
similarity index 91%
rename from lib/trans-receiver-htmlfile.js
rename to lib/transport/lib/receiver-htmlfile.js
index 967fead..1727549 100644
--- a/lib/trans-receiver-htmlfile.js
+++ b/lib/transport/lib/receiver-htmlfile.js
@@ -1,9 +1,9 @@
'use strict';
var util = require('util')
- , utils = require('./utils')
- , SimpleEvent = require('./simpleevent')
- , EventTarget = require('./polyfills/eventtarget')
+ , utils = require('../../utils')
+ , SimpleEvent = require('../../simpleevent')
+ , EventTarget = require('../../polyfills/eventtarget')
;
var _isIeHtmlfileCapable;
diff --git a/lib/trans-receiver-xhr.js b/lib/transport/lib/receiver-xhr.js
similarity index 91%
rename from lib/trans-receiver-xhr.js
rename to lib/transport/lib/receiver-xhr.js
index 6066abd..44f3049 100644
--- a/lib/trans-receiver-xhr.js
+++ b/lib/transport/lib/receiver-xhr.js
@@ -1,8 +1,8 @@
'use strict';
var util = require('util')
- , SimpleEvent = require('./simpleevent')
- , EventTarget = require('./polyfills/eventtarget')
+ , SimpleEvent = require('../../simpleevent')
+ , EventTarget = require('../../polyfills/eventtarget')
;
function XhrReceiver(url, AjaxObject) {
diff --git a/lib/xhr-polling-iframe.js b/lib/transport/lib/xhr-polling-iframe.js
similarity index 59%
rename from lib/xhr-polling-iframe.js
rename to lib/transport/lib/xhr-polling-iframe.js
index e437860..672386d 100644
--- a/lib/xhr-polling-iframe.js
+++ b/lib/transport/lib/xhr-polling-iframe.js
@@ -1,14 +1,14 @@
'use strict';
var util = require('util')
- , XhrReceiver = require('./trans-receiver-xhr')
+ , XhrReceiver = require('./receiver-xhr')
, XHRLocalObject = require('./xhr-local')
- , AjaxBasedTransport = require('./ajax-based')
+ , AjaxBasedTransport = require('../../ajax-based')
;
// w-iframe-xhr-polling
function XhrPollingITransport(ri, transUrl) {
- this.run(ri, transUrl, '/xhr', XhrReceiver, XHRLocalObject);
+ AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRLocalObject);
}
util.inherits(XhrPollingITransport, AjaxBasedTransport);
diff --git a/lib/transport/xdr-polling.js b/lib/transport/xdr-polling.js
index da088fd..bd76c73 100644
--- a/lib/transport/xdr-polling.js
+++ b/lib/transport/xdr-polling.js
@@ -1,14 +1,14 @@
'use strict';
var util = require('util')
- , AjaxBasedTransport = require('../ajax-based')
+ , AjaxBasedTransport = require('./lib/ajax-based')
, XdrStreamingTransport = require('./xdr-streaming')
- , XhrReceiver = require('../trans-receiver-xhr')
+ , XhrReceiver = require('./lib/receiver-xhr')
, XDRObject = require('../xdr')
;
function XdrPollingTransport(ri, transUrl) {
- this.run(ri, transUrl, '/xhr', XhrReceiver, XDRObject);
+ AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XDRObject);
}
util.inherits(XdrPollingTransport, AjaxBasedTransport);
diff --git a/lib/transport/xdr-streaming.js b/lib/transport/xdr-streaming.js
index 7a2e577..9c8745c 100644
--- a/lib/transport/xdr-streaming.js
+++ b/lib/transport/xdr-streaming.js
@@ -1,8 +1,8 @@
'use strict';
var util = require('util')
- , AjaxBasedTransport = require('../ajax-based')
- , XhrReceiver = require('../trans-receiver-xhr')
+ , AjaxBasedTransport = require('./lib/ajax-based')
+ , XhrReceiver = require('./lib/receiver-xhr')
, XDRObject = require('../xdr')
, utils = require('../utils')
;
@@ -11,8 +11,8 @@ var util = require('util')
// http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
-function XdrStreamingTransport(ri, transUrl) {
- this.run(ri, transUrl, '/xhr_streaming', XhrReceiver, XDRObject);
+function XdrStreamingTransport(transUrl) {
+ AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XDRObject);
}
util.inherits(XdrStreamingTransport, AjaxBasedTransport);
diff --git a/lib/transport/xhr-polling.js b/lib/transport/xhr-polling.js
index 88ced22..e507aef 100644
--- a/lib/transport/xhr-polling.js
+++ b/lib/transport/xhr-polling.js
@@ -1,14 +1,14 @@
'use strict';
var util = require('util')
- , AjaxBasedTransport = require('../ajax-based')
- , XhrReceiver = require('../trans-receiver-xhr')
+ , AjaxBasedTransport = require('./lib/ajax-based')
+ , XhrReceiver = require('./lib/receiver-xhr')
, XHRCorsObject = require('../xhr-cors')
, utils = require('../utils')
;
function XhrPollingTransport(ri, transUrl) {
- this.run(ri, transUrl, '/xhr', XhrReceiver, XHRCorsObject);
+ AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRCorsObject);
}
util.inherits(XhrPollingTransport, AjaxBasedTransport);
@@ -17,7 +17,7 @@ XhrPollingTransport.enabled = function(url, info) {
if (info.nullOrigin) {
return false;
}
- if (window.XMLHttpRequest && utils.isSameOriginUrl(url)) {
+ if (global.XMLHttpRequest && utils.isSameOriginUrl(url)) {
return true;
}
return utils.isXHRCorsCapable() === 1;
diff --git a/lib/transport/xhr-streaming.js b/lib/transport/xhr-streaming.js
index acb8bbb..29d9e32 100644
--- a/lib/transport/xhr-streaming.js
+++ b/lib/transport/xhr-streaming.js
@@ -1,14 +1,14 @@
'use strict';
var util = require('util')
- , AjaxBasedTransport = require('../ajax-based')
- , XhrReceiver = require('../trans-receiver-xhr')
+ , AjaxBasedTransport = require('./lib/ajax-based')
+ , XhrReceiver = require('./lib/receiver-xhr')
, XHRCorsObject = require('../xhr-cors')
, utils = require('../utils')
;
function XhrStreamingTransport(ri, transUrl) {
- this.run(ri, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
+ AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
}
util.inherits(XhrStreamingTransport, AjaxBasedTransport);
diff --git a/lib/utils.js b/lib/utils.js
index 12717e2..2644a51 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -1,7 +1,7 @@
'use strict';
var JSON3 = require('json3');
-var IframeTransport = require('./trans-iframe');
+var IframeTransport = require('./transport/lib/iframe');
var utils = {};
var getRandomBytes;
@@ -116,8 +116,8 @@ utils.objectExtend = function(dst, src) {
var WPrefix = utils.WPrefix = '_jp';
utils.polluteGlobalNamespace = function() {
- if (!(WPrefix in window)) {
- window[WPrefix] = {};
+ if (!(WPrefix in global)) {
+ global[WPrefix] = {};
}
};
diff --git a/lib/xdr.js b/lib/xdr.js
index 8291d75..12e7cff 100644
--- a/lib/xdr.js
+++ b/lib/xdr.js
@@ -12,7 +12,7 @@ var EventEmitter = require('events').EventEmitter
function XDRObject(method, url, payload) {
var self = this;
EventEmitter.call(this);
-
+
process.nextTick(function(){
self._start(method, url, payload);
});
diff --git a/tests/html/lib/domtests.js b/tests/html/lib/domtests.js
index 9534d3a..adaf451 100644
--- a/tests/html/lib/domtests.js
+++ b/tests/html/lib/domtests.js
@@ -64,7 +64,7 @@ if (navigator.userAgent.indexOf('Konqueror') !== -1 || navigator.userAgent.index
});
}
-if (!require('../../../lib/trans-iframe').enabled()) {
+if (!require('../../../lib/transport/lib/iframe').enabled()) {
test("onmessage [unsupported by client]", function() {
assert.ok(true);
});
diff --git a/tests/transports.js b/tests/transports.js
index 2808137..f5c1425 100644
--- a/tests/transports.js
+++ b/tests/transports.js
@@ -13,7 +13,12 @@ files.forEach(function (file) {
if (file[0] === '.') {
return;
}
- transportFiles.push(path.resolve(dir, file));
+ var fileName = path.resolve(dir, file);
+ var stat = fs.statSync(fileName);
+ if (stat && stat.isDirectory()) {
+ return;
+ }
+ transportFiles.push(fileName);
});
describe('Transports', function () {
@@ -31,7 +36,15 @@ describe('Transports', function () {
expect(Trans).to.have.property('enabled');
expect(Trans.enabled).to.be.a('function');
- //expect(new Trans('http://localhost')).to.be.an(EventTarget);
+ //var t = new Trans('http://localhost');
+
+ expect(Trans.prototype).to.have.property('send');
+ expect(Trans.prototype.send).to.be.a('function');
+
+ expect(Trans.prototype).to.have.property('close');
+ expect(Trans.prototype.close).to.be.a('function');
+
+ //expect().to.be.an(EventTarget);
// TODO tests for event emitting
});
});
--
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