[Pkg-javascript-commits] [sockjs-client] 58/350: Merge branch 'master' into build-system
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:42 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 2452493096bd6b5b73c0f0acc344f8bf154f622c
Merge: 5df0dab 3c07610
Author: Bryce Kahle <bkahle at gmail.com>
Date: Wed May 28 10:01:02 2014 -0400
Merge branch 'master' into build-system
Conflicts:
lib/info.js
lib/trans-websocket.js
lib/utils.js
lib/sockjs.js | 3 ++-
lib/trans-iframe.js | 3 ++-
lib/trans-websocket.js | 4 ++--
lib/utils.js | 27 ++++++++++++++++++++++-----
4 files changed, 28 insertions(+), 9 deletions(-)
diff --cc lib/sockjs.js
index d3a4c22,12de0f7..e1da745
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@@ -7,18 -6,7 +7,19 @@@
* ***** END LICENSE BLOCK *****
*/
-var SockJS = function(url, dep_protocols_whitelist, options) {
+var utils = require('./utils');
+var REventTarget = require('./reventtarget');
+var SimpleEvent = require('./SimpleEvent');
+var InfoReceiver = require('./info-receiver');
+var InfoReceiverIframe = require('./info-receiver-iframe');
+var InfoReceiverFake = require('./info-receiver-fake');
+var FacadeJS = require('./facade');
+var JSON3 = require('json3');
+var XHRLocalObject = require('./xhr-local');
++var XHRCorsObject = require('./xhr-cors');
+var XDRObject = require('./xdr');
+
+function SockJS(url, dep_protocols_whitelist, options) {
if (!(this instanceof SockJS)) {
// makes `new` optional
return new SockJS(url, dep_protocols_whitelist, options);
@@@ -281,111 -263,3 +282,111 @@@ SockJS.prototype._applyInfo = function(
var probed = utils.probeProtocols();
that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
};
+
+utils.parent_origin = undefined;
+
+SockJS.bootstrap_iframe = function() {
+ var facade;
+ utils.curr_window_id = document.location.hash.slice(1);
+ var onMessage = function(e) {
+ if(e.source !== parent) return;
+ if(typeof utils.parent_origin === 'undefined')
+ utils.parent_origin = e.origin;
+ if (e.origin !== utils.parent_origin) return;
+
+ var window_id = e.data.slice(0, 8);
+ var type = e.data.slice(8, 9);
+ var data = e.data.slice(9);
+ if (window_id !== utils.curr_window_id) return;
+ switch(type) {
+ case 's':
+ var p = JSON3.parse(data);
+ var version = p[0];
+ var protocol = p[1];
+ var trans_url = p[2];
+ var base_url = p[3];
+ // change this to semver logic
+ if (version !== SockJS.version) {
+ utils.log("Incompatibile SockJS! Main site uses:" +
+ " \"" + version + "\", the iframe:" +
+ " \"" + SockJS.version + "\".");
+ }
+ if (!utils.flatUrl(trans_url) || !utils.flatUrl(base_url)) {
+ utils.log("Only basic urls are supported in SockJS");
+ return;
+ }
+
+ if (!utils.isSameOriginUrl(trans_url) ||
+ !utils.isSameOriginUrl(base_url)) {
+ utils.log("Can't connect to different domain from within an " +
+ "iframe. (" + JSON3.stringify([window.location.href, trans_url, base_url]) +
+ ")");
+ return;
+ }
+ facade = new FacadeJS();
+ facade._transport = new FacadeJS[protocol](facade, trans_url, base_url);
+ break;
+ case 'm':
+ facade._doSend(data);
+ break;
+ case 'c':
+ if (facade)
+ facade._doCleanup();
+ facade = null;
+ break;
+ }
+ };
+
+ utils.attachMessage(onMessage);
+
+ // Start
+ utils.postMessage('s');
+};
+
+SockJS.websocket = require('./trans-websocket');
+SockJS['iframe-eventsource'] = require('./trans-iframe-eventsource');
+SockJS['iframe-htmlfile'] = require('./trans-iframe-htmlfile');
+SockJS['iframe-xhr-polling'] = require('./trans-iframe-xhr-polling');
+SockJS['jsonp-polling'] = require('./trans-jsonp-polling');
+SockJS['xdr-polling'] = require('./xdr-polling');
+SockJS['xdr-streaming'] = require('./xdr-streaming');
+SockJS['xhr-polling'] = require('./xhr-polling');
+SockJS['xhr-streaming'] = require('./xhr-streaming');
+
+module.exports = SockJS;
+
+FacadeJS['w-iframe-info-receiver'] = require('./info-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');
+
+// TODO get rid of both of these!!!!
+SockJS.getUtils = function () { return utils; };
+
+// This is seriously wack.
+if ('_sockjs_onload' in window) setTimeout(window._sockjs_onload, 1);
+
+function createInfoReceiver(base_url) {
+ if (utils.isSameOriginUrl(base_url)) {
+ // If, for some reason, we have SockJS locally - there's no
+ // need to start up the complex machinery. Just use ajax.
- return new InfoReceiver(base_url, XHRLocalObject);
++ return new InfoReceiver(base_url, XHRCorsObject);
+ }
+ switch (utils.isXHRCorsCapable()) {
+ case 1:
+ // XHRLocalObject -> no_credentials=true
+ return new InfoReceiver(base_url, XHRLocalObject);
+ case 2:
+ // IE 8/9 if the request target uses the same scheme
+ if (utils.isSameOriginScheme(base_url)) {
+ return new InfoReceiver(base_url, XDRObject);
+ }
+ break;
+ case 3:
+ // Opera
+ return new InfoReceiverIframe(base_url);
+ }
+
+ // IE 7, and IE 8/9 if requesting across schemes (e.g. http -> https)
+ return new InfoReceiverFake();
+}
diff --cc lib/trans-websocket.js
index 9805760,b967f22..222816f
--- a/lib/trans-websocket.js
+++ b/lib/trans-websocket.js
@@@ -30,13 -28,11 +30,13 @@@ function WebSocketTransport(ri, trans_u
// let's not open the ws connection at all. See:
// https://github.com/sockjs/sockjs-client/issues/28
// https://bugzilla.mozilla.org/show_bug.cgi?id=696085
- that.unload_ref = utils.unload_add(function(){that.ws.close()});
+ that.unload_ref = utils.unload_add(function(){
+ that.ws.close();
+ });
- that.ws.onclose = function() {
+ that.ws.onclose = that.ws.onerror = function() {
that.ri._didMessage(utils.closeFrame(1006, "WebSocket connection broken"));
};
-};
+}
WebSocketTransport.prototype.doSend = function(data) {
this.ws.send('[' + data + ']');
diff --cc lib/utils.js
index cd2739e,155ff7e..b504ea8
--- a/lib/utils.js
+++ b/lib/utils.js
@@@ -358,232 -371,4 +375,232 @@@ utils.detectProtocols = function(probed
}
}
return protocols;
-}
+};
+
+// 1. Is natively via XHR
+// 2. Is natively via XDR
+// 3. Nope, but postMessage is there so it should work via the Iframe.
+// 4. Nope, sorry.
+utils.isXHRCorsCapable = function() {
+ if (window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) {
+ return 1;
+ }
+ // XDomainRequest doesn't work if page is served from file://
+ if (window.XDomainRequest && document.domain) {
+ return 2;
+ }
+ if (IframeTransport.enabled()) {
+ return 3;
+ }
+ return 4;
+};
+
+// May be used by htmlfile jsonp and transports.
+var MPrefix = '_sockjs_global';
+utils.createHook = function() {
+ var window_id = 'a' + utils.random_string(8);
+ if (!(MPrefix in window)) {
+ var map = {};
+ window[MPrefix] = function(window_id) {
+ if (!(window_id in map)) {
+ map[window_id] = {
+ id: window_id,
+ del: function() {delete map[window_id];}
+ };
+ }
+ return map[window_id];
+ };
+ }
+ return window[MPrefix](window_id);
+};
+
+utils.attachMessage = function(listener) {
+ utils.attachEvent('message', listener);
+};
+utils.attachEvent = function(event, listener) {
+ if (typeof window.addEventListener !== 'undefined') {
+ window.addEventListener(event, listener, false);
+ } else {
+ // IE quirks.
+ // According to: http://stevesouders.com/misc/test-postmessage.php
+ // the message gets delivered only to 'document', not 'window'.
+ document.attachEvent("on" + event, listener);
+ // I get 'window' for ie8.
+ window.attachEvent("on" + event, listener);
+ }
+};
+
+utils.detachMessage = function(listener) {
+ utils.detachEvent('message', listener);
+};
+utils.detachEvent = function(event, listener) {
+ if (typeof window.addEventListener !== 'undefined') {
+ window.removeEventListener(event, listener, false);
+ } else {
+ document.detachEvent("on" + event, listener);
+ window.detachEvent("on" + event, listener);
+ }
+};
+
+
+var on_unload = {};
+// Things registered after beforeunload are to be called immediately.
+var after_unload = false;
+
+var trigger_unload_callbacks = function() {
+ for(var ref in on_unload) {
+ on_unload[ref]();
+ delete on_unload[ref];
+ }
+};
+
+var unload_triggered = function() {
+ if(after_unload) return;
+ after_unload = true;
+ trigger_unload_callbacks();
+};
+
+// 'unload' alone is not reliable in opera within an iframe, but we
+// can't use `beforeunload` as IE fires it on javascript: links.
+utils.attachEvent('unload', unload_triggered);
+
+utils.unload_add = function(listener) {
+ var ref = utils.random_string(8);
+ on_unload[ref] = listener;
+ if (after_unload) {
+ utils.delay(trigger_unload_callbacks);
+ }
+ return ref;
+};
+utils.unload_del = function(ref) {
+ if (ref in on_unload)
+ delete on_unload[ref];
+};
+
+
+utils.createIframe = function (iframe_url, error_callback) {
+ var iframe = document.createElement('iframe');
+ var tref, unload_ref;
+ var unattach = function() {
+ clearTimeout(tref);
+ // Explorer had problems with that.
+ try {iframe.onload = null;} catch (x) {}
+ iframe.onerror = null;
+ };
+ var cleanup = function() {
+ if (iframe) {
+ unattach();
+ // This timeout makes chrome fire onbeforeunload event
+ // within iframe. Without the timeout it goes straight to
+ // onunload.
+ setTimeout(function() {
+ if(iframe) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ iframe = null;
+ }, 0);
+ utils.unload_del(unload_ref);
+ }
+ };
+ var onerror = function(r) {
+ if (iframe) {
+ cleanup();
+ error_callback(r);
+ }
+ };
+ var post = function(msg, origin) {
+ try {
+ // When the iframe is not loaded, IE raises an exception
+ // on 'contentWindow'.
+ if (iframe && iframe.contentWindow) {
+ setTimeout(function() {
+ iframe.contentWindow.postMessage(msg, origin);
+ }, 0);
+ }
+ } catch (x) {}
+ };
+
+ iframe.src = iframe_url;
+ iframe.style.display = 'none';
+ iframe.style.position = 'absolute';
+ iframe.onerror = function(){onerror('onerror');};
+ iframe.onload = function() {
+ // `onload` is triggered before scripts on the iframe are
+ // executed. Give it few seconds to actually load stuff.
+ clearTimeout(tref);
+ tref = setTimeout(function(){onerror('onload timeout');}, 2000);
+ };
+ document.body.appendChild(iframe);
+ tref = setTimeout(function(){onerror('timeout');}, 15000);
+ unload_ref = utils.unload_add(cleanup);
+ return {
+ post: post,
+ cleanup: cleanup,
+ loaded: unattach
+ };
+};
+
+/* jshint undef: false, newcap: false */
+utils.createHtmlfile = function (iframe_url, error_callback) {
+ var doc = new ActiveXObject('htmlfile');
+ var tref, unload_ref;
+ var iframe;
+ var unattach = function() {
+ clearTimeout(tref);
+ };
+ var cleanup = function() {
+ if (doc) {
+ unattach();
+ utils.unload_del(unload_ref);
+ iframe.parentNode.removeChild(iframe);
+ iframe = doc = null;
+ CollectGarbage();
+ }
+ };
+ var onerror = function(r) {
+ if (doc) {
+ cleanup();
+ error_callback(r);
+ }
+ };
+ var post = function(msg, origin) {
+ try {
+ // When the iframe is not loaded, IE raises an exception
+ // on 'contentWindow'.
+ if (iframe && iframe.contentWindow) {
+ setTimeout(function() {
+ iframe.contentWindow.postMessage(msg, origin);
+ }, 0);
+ }
+ } catch (x) {}
+ };
+
+ doc.open();
+ doc.write('<html><s' + 'cript>' +
+ 'document.domain="' + document.domain + '";' +
+ '</s' + 'cript></html>');
+ doc.close();
+ doc.parentWindow[utils.WPrefix] = window[utils.WPrefix];
+ var c = doc.createElement('div');
+ doc.body.appendChild(c);
+ iframe = doc.createElement('iframe');
+ c.appendChild(iframe);
+ iframe.src = iframe_url;
+ tref = setTimeout(function(){onerror('timeout');}, 15000);
+ unload_ref = utils.unload_add(cleanup);
+ return {
+ post: post,
+ cleanup: cleanup,
+ loaded: unattach
+ };
+};
+
+utils.postMessage = function (type, data) {
+ if (parent !== window) {
+ parent.postMessage(utils.curr_window_id + type + (data || ''), '*');
+ } else {
+ utils.log("Can't postMessage, no parent window.", type, data);
+ }
+};
+
- module.exports = utils;
++module.exports = utils;
--
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