SockJS
view release on metacpan or search on metacpan
t-vendor/html/lib/sockjs.js view on Meta::CPAN
"\u206e":"\\u206e","\u206f":"\\u206f","\ufeff":"\\ufeff","\ufff0":"\\ufff0",
"\ufff1":"\\ufff1","\ufff2":"\\ufff2","\ufff3":"\\ufff3","\ufff4":"\\ufff4",
"\ufff5":"\\ufff5","\ufff6":"\\ufff6","\ufff7":"\\ufff7","\ufff8":"\\ufff8",
"\ufff9":"\\ufff9","\ufffa":"\\ufffa","\ufffb":"\\ufffb","\ufffc":"\\ufffc",
"\ufffd":"\\ufffd","\ufffe":"\\ufffe","\uffff":"\\uffff"};
// Some extra characters that Chrome gets wrong, and substitutes with
// something else on the wire.
var extra_escapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06e...
extra_lookup;
// JSON Quote string. Use native implementation when possible.
var JSONQuote = (JSON && JSON.stringify) || function(string) {
json_escapable.lastIndex = 0;
if (json_escapable.test(string)) {
string = string.replace(json_escapable, function(a) {
return json_lookup[a];
});
}
return '"' + string + '"';
};
// This may be quite slow, so let's delay until user actually uses bad
// characters.
var unroll_lookup = function(escapable) {
var i;
var unrolled = {}
var c = []
for(i=0; i<65536; i++) {
c.push( String.fromCharCode(i) );
}
escapable.lastIndex = 0;
c.join('').replace(escapable, function (a) {
unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
return '';
});
escapable.lastIndex = 0;
return unrolled;
};
// Quote string, also taking care of unicode characters that browsers
// often break. Especially, take care of unicode surrogates:
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
utils.quote = function(string) {
var quoted = JSONQuote(string);
// In most cases this should be very fast and good enough.
extra_escapable.lastIndex = 0;
if(!extra_escapable.test(quoted)) {
return quoted;
}
if(!extra_lookup) extra_lookup = unroll_lookup(extra_escapable);
return quoted.replace(extra_escapable, function(a) {
return extra_lookup[a];
});
}
var _all_protocols = ['websocket',
'xdr-streaming',
'xhr-streaming',
'iframe-eventsource',
'iframe-htmlfile',
'xdr-polling',
'xhr-polling',
'iframe-xhr-polling',
'jsonp-polling'];
utils.probeProtocols = function() {
var probed = {};
for(var i=0; i<_all_protocols.length; i++) {
var protocol = _all_protocols[i];
// User can have a typo in protocol name.
probed[protocol] = SockJS[protocol] &&
SockJS[protocol].enabled();
}
return probed;
};
utils.detectProtocols = function(probed, protocols_whitelist, info) {
var pe = {},
protocols = [];
if (!protocols_whitelist) protocols_whitelist = _all_protocols;
for(var i=0; i<protocols_whitelist.length; i++) {
var protocol = protocols_whitelist[i];
pe[protocol] = probed[protocol];
}
var maybe_push = function(protos) {
var proto = protos.shift();
if (pe[proto]) {
protocols.push(proto);
} else {
if (protos.length > 0) {
maybe_push(protos);
}
}
}
// 1. Websocket
if (info.websocket !== false) {
maybe_push(['websocket']);
}
// 2. Streaming
if (pe['xhr-streaming'] && !info.null_origin) {
protocols.push('xhr-streaming');
} else {
if (pe['xdr-streaming'] && !info.cookie_needed && !info.null_origin) {
protocols.push('xdr-streaming');
} else {
maybe_push(['iframe-eventsource',
'iframe-htmlfile']);
}
}
// 3. Polling
if (pe['xhr-polling'] && !info.null_origin) {
protocols.push('xhr-polling');
} else {
if (pe['xdr-polling'] && !info.cookie_needed && !info.null_origin) {
protocols.push('xdr-polling');
} else {
maybe_push(['iframe-xhr-polling',
'jsonp-polling']);
}
}
return protocols;
}
// [*] End of lib/utils.js
// [*] Including lib/dom.js
/*
* ***** BEGIN LICENSE BLOCK *****
* Copyright (c) 2011-2012 VMware, Inc.
*
* For the license see COPYING.
* ***** END LICENSE BLOCK *****
*/
// 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.
t-vendor/html/lib/sockjs.js view on Meta::CPAN
if (that._recv_stop) {
that._recv_stop();
}
that.ri = that._recv_stop = null;
that.send_destructor();
};
// Abstract away code that handles global namespace pollution.
var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
var id = 'a' + utils.random_string(6);
var url_id = url + '?c=' + escape(WPrefix + '.' + id);
// Callback will be called exactly once.
var callback = function(frame) {
delete _window[WPrefix][id];
user_callback(frame);
};
var close_script = constructReceiver(url_id, callback);
_window[WPrefix][id] = close_script;
var stop = function() {
if (_window[WPrefix][id]) {
_window[WPrefix][id](utils.closeFrame(1000, "JSONP user aborted read"));
}
};
return stop;
};
// [*] End of lib/trans-jsonp-polling.js
// [*] Including lib/trans-xhr.js
/*
* ***** BEGIN LICENSE BLOCK *****
* Copyright (c) 2011-2012 VMware, Inc.
*
* For the license see COPYING.
* ***** END LICENSE BLOCK *****
*/
var AjaxBasedTransport = function() {};
AjaxBasedTransport.prototype = new BufferedSender();
AjaxBasedTransport.prototype.run = function(ri, trans_url,
url_suffix, Receiver, AjaxObject) {
var that = this;
that.ri = ri;
that.trans_url = trans_url;
that.send_constructor(createAjaxSender(AjaxObject));
that.poll = new Polling(ri, Receiver,
trans_url + url_suffix, AjaxObject);
};
AjaxBasedTransport.prototype.doCleanup = function() {
var that = this;
if (that.poll) {
that.poll.abort();
that.poll = null;
}
};
// xhr-streaming
var XhrStreamingTransport = SockJS['xhr-streaming'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XHRCorsObject);
};
XhrStreamingTransport.prototype = new AjaxBasedTransport();
XhrStreamingTransport.enabled = function() {
// Support for CORS Ajax aka Ajax2? Opera 12 claims CORS but
// doesn't do streaming.
return (_window.XMLHttpRequest &&
'withCredentials' in new XMLHttpRequest() &&
(!/opera/i.test(navigator.userAgent)));
};
XhrStreamingTransport.roundTrips = 2; // preflight, ajax
// Safari gets confused when a streaming ajax request is started
// before onload. This causes the load indicator to spin indefinetely.
XhrStreamingTransport.need_body = true;
// According to:
// http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
// xdr-streaming
var XdrStreamingTransport = SockJS['xdr-streaming'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, utils.XDRObject);
};
XdrStreamingTransport.prototype = new AjaxBasedTransport();
XdrStreamingTransport.enabled = function() {
return !!_window.XDomainRequest;
};
XdrStreamingTransport.roundTrips = 2; // preflight, ajax
// xhr-polling
var XhrPollingTransport = SockJS['xhr-polling'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRCorsObject);
};
XhrPollingTransport.prototype = new AjaxBasedTransport();
XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
XhrPollingTransport.roundTrips = 2; // preflight, ajax
// xdr-polling
var XdrPollingTransport = SockJS['xdr-polling'] = function(ri, trans_url) {
this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XDRObject);
};
XdrPollingTransport.prototype = new AjaxBasedTransport();
XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
XdrPollingTransport.roundTrips = 2; // preflight, ajax
// [*] End of lib/trans-xhr.js
// [*] Including lib/trans-iframe.js
/*
* ***** BEGIN LICENSE BLOCK *****
* Copyright (c) 2011-2012 VMware, Inc.
*
* For the license see COPYING.
* ***** END LICENSE BLOCK *****
*/
// Few cool transports do work only for same-origin. In order to make
// them working cross-domain we shall use iframe, served form the
// remote domain. New browsers, have capabilities to communicate with
// cross domain iframe, using postMessage(). In IE it was implemented
// from IE 8+, but of course, IE got some details wrong:
// http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
// http://stevesouders.com/misc/test-postmessage.php
var IframeTransport = function() {};
IframeTransport.prototype.i_constructor = function(ri, trans_url, base_url) {
var that = this;
that.ri = ri;
that.origin = utils.getOrigin(base_url);
that.base_url = base_url;
that.trans_url = trans_url;
( run in 1.735 second using v1.01-cache-2.11-cpan-39bf76dae61 )