Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

comet stuff - crossdomain works

git-svn-id: http://evserver.googlecode.com/svn/trunk@57 e9bb6d7e-af12-11dd-bad7-87afd3b02348
  • Loading branch information...
commit af731cda3773e77a1627a3cbf323d819ac0c4a5a 1 parent 6302bc2
majek04 authored
View
65 evserver/examples/static/comet.js
@@ -404,7 +404,6 @@ function comet_crossdomain_connection(iframe_uri, comet_uri, user_callback, tran
transportstr = '&transport=' + transport;
comet_log('cometcrossdomain: started');
-
window[fname] = user_callback;
window[fname + '_uri'] = comet_uri;
@@ -425,15 +424,15 @@ function comet_crossdomain_connection(iframe_uri, comet_uri, user_callback, tran
if(ifr.contentWindow)
doc = ifr.contentWindow.document;
}
- if(doc && doc.comet_garbage){
+ try{
+ if(doc && doc.comet_garbage)
doc.comet_garbage();
- }
+ }catch(e){};
document.body.removeChild(ifr);
delete(ifr);
ifr=null;
}
-
- window[fname] = null;
+ window[fname] = function(){};
window[fname + '_uri'] = null;
}
comet_attach_unload_event(garbc);
@@ -442,42 +441,52 @@ function comet_crossdomain_connection(iframe_uri, comet_uri, user_callback, tran
/********************************************************************/
-function comet_create_crossdomain_ajax(iframe_uri, ajax_uri, method, post_data, user_callback) {
+function comet_create_crossdomain_ajax(iframe_uri, ajax_uri, method, post_data, user_callback, mimetype) {
+ var queue_key = escape(iframe_uri) + '_queue';
+ var garbc_key = escape(iframe_uri) + '_garbc';
+ var push_key = escape(iframe_uri) + '_push';
+ if(window[queue_key] == undefined){
+ window[queue_key] = [];
+ window[push_key] = function(){};
+ }
+
+ var v = [ajax_uri, method, post_data, user_callback, mimetype];
+ window[queue_key] = ([v]).concat(window[queue_key]);
+ window[push_key]();
+
+ if(window[garbc_key] == undefined) {
+ window[garbc_key] = comet_create_crossdomain_ajax_iframe(iframe_uri);
+ }
+}
+
+function comet_create_crossdomain_ajax_iframe(iframe_uri) {
var i=0; while(window['ajc'+i] != undefined) i += 1;
var fname = 'ajc' + i;
var ifr;
+ window[fname] = escape(iframe_uri);
+ var queue_key = fname + '_data';
+
if(iframe_uri.indexOf('?') == -1)
iframe_uri = iframe_uri + '?a=' + Math.random()
- function gc(){
- document.body.removeChild(ifr);
- delete(ifr);
- ifr=null;
- window[fname] = null;
- window[fname + '_method'] = null;
- window[fname + '_ajax_uri'] = null;
- window[fname + '_post_data'] = null;
- }
-
- function callback(o){
- if(user_callback)
- user_callback(o);
- gc();
- }
-
- window[fname] = callback;
- window[fname + '_method'] = method;
- window[fname + '_ajax_uri'] = ajax_uri;
- window[fname + '_post_data'] = post_data;
-
ifr = document.createElement('iframe');
hide_iframe(ifr);
ifr.setAttribute('src', iframe_uri +
'&callback=' + fname);
document.body.appendChild(ifr);
kill_load_bar();
- return gc;
+
+ var garbc = function(){
+ if(ifr){
+ document.body.removeChild(ifr);
+ delete(ifr);
+ ifr=null;
+ }
+ window[fname] = null;
+ }
+ comet_attach_unload_event(garbc);
+ return garbc;
}
View
76 evserver/examples/static/crossajax.html
@@ -3,38 +3,59 @@
<script type="text/javascript" src="./comet.js"></script>
<script type="text/javascript" charset="utf-8">
- var newdomain = extract_xss_domain(document.domain);
- if(document.domain != newdomain)
- document.domain = newdomain;
+ document.domain = extract_xss_domain(document.domain);
</script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
- callback = getURLParam('callback');
- var xhr = null;
- function x(){
- var user_callback = parent[callback];
- var post_data = parent[callback + '_post_data'];
- var ajax_method = parent[callback + '_method'];
- var ajax_uri = parent[callback + '_ajax_uri'];
- var onreadystatechange = function (){
- if(!xhr)
- return;
- if(xhr.readyState != 4)
- return;
- if(user_callback){
- /* avoid passing xhr object directly to parent iframe */
- var x = {};
- x.readyState = xhr.readyState;
- x.responseText = xhr.responseText;
- x.responseBody = xhr.responseBody;
- x.status = xhr.status;
- x.statusText = xhr.statusText;
- user_callback(x);
+ var callback = getURLParam('callback');
+ var key = parent[callback];
+ var queue_key = key + '_queue';
+ var garbc_key = key + '_garbc';
+ var push_key = key + '_push';
+
+ var empty_queue = null;
+ parent[push_key] = function(){
+ if(empty_queue)
+ empty_queue();
+ }
+
+ empty_queue = function(){
+ while(true){
+ var items = parent[queue_key].pop();
+ if(!items)
+ break;
+ var closure = function (){
+ var ajax_uri = items[0];
+ var method = items[1];
+ var post_data = items[2];
+ var user_callback = items[3];
+ var mimetype = items[4];
+ var xhr = null;
+ var onreadystatechange = function (){
+ if(!xhr)
+ return;
+ if(xhr.readyState != 4)
+ return;
+ if(user_callback){
+ /* avoid passing xhr object directly to parent iframe */
+ var x = {};
+ x.readyState = xhr.readyState;
+ x.responseText = xhr.responseText;
+ x.responseBody = xhr.responseBody;
+ x.status = xhr.status;
+ x.statusText = xhr.statusText;
+ user_callback(x);
+ }
+ };
+ xhr = comet_create_ajax(ajax_uri, method, post_data, onreadystatechange, mimetype);
}
- };
- xhr = comet_create_ajax(ajax_uri, ajax_method, post_data, onreadystatechange);
+ closure();
+ }
+ }
+ empty_queue();
+ /*
function gc2(){
if(xhr){
xhr.onreadystatechange=function () {};
@@ -46,8 +67,7 @@
comet_attach_unload_event(gc2);
document.comet_garbage = gc2;
window.comet_garbage = gc2;
- }
- x();
+ */
</script>
</body>
</html>
View
8 evserver/examples/static/crosscomet.html
@@ -3,14 +3,14 @@
<script type="text/javascript" src="./comet.js"></script>
<script type="text/javascript" charset="utf-8">
- var newdomain = extract_xss_domain(document.domain);
- if(document.domain != newdomain)
- document.domain = newdomain;
+ document.domain = extract_xss_domain(document.domain);
</script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
+ document.domain = extract_xss_domain(document.domain);
var callback = getURLParam('callback');
+
var transport = getURLParam('transport');
var gc = null;
function cb(data){
@@ -33,7 +33,7 @@
document.comet_garbage = gc2;
window.comet_garbage = gc2;
}catch(e){
- alert('got data but cant pass it from iframe. callback:' + callback + ' domain:' +document.domain + ' error:' + e.message);
+ alert('got data but cant pass it from iframe. callback:' + callback + ' domain:>' +document.domain + '< error:' + e.message);
}
</script>
View
7 evserver/examples/static/index.html
@@ -5,6 +5,9 @@
<script src="/static/comet.js" type="text/javascript"></script>
+ <script type="text/javascript" charset="utf-8">
+ document.domain = extract_xss_domain(document.domain);
+ </script>
<style type="text/css">
.box {color:black;
@@ -187,12 +190,12 @@
}
function create_comet(url, user_callback, transport_local){
- return comet_crossdomain_connection('./static/crosscomet.html', url, user_callback, transport_local);
+ return comet_crossdomain_connection('http://comet.majek.net/static/crosscomet.html', url, user_callback, transport_local);
return comet_connection(url, user_callback_o, transport_local);
}
function create_ajax(url, method, data, onreadystatechange, mimetype) {
- return comet_create_crossdomain_ajax('./static/crossajax.html', url, method, data, onreadystatechange);
+ return comet_create_crossdomain_ajax('http://comet.majek.net/static/crossajax.html', url, method, data, onreadystatechange);
return comet_create_ajax(url, method, data, onreadystatechange, mimetype);
}
View
17 evserver/reloader.py
@@ -184,13 +184,16 @@ def onchange(fname):
# sorry about that, but I haven't found any better working solution
self.orginal_import = __builtin__.__import__
def new_import(*args, **kwargs):
- mod = self.orginal_import(*args, **kwargs)
- if mod and getattr(mod, '__file__', None):
- add_file(mod.__file__, mod)
- # quick hack for __init__ files. anyone has better idea?
- if '__init__' in mod.__file__:
- add_file(os.path.join(os.path.dirname(mod.__file__), args[0].rpartition('.')[2] + '.py'), mod)
- return mod
+ omod = self.orginal_import(*args, **kwargs)
+ try:
+ mod = omod
+ for comp in args[0].split('.')[1:]:
+ mod = getattr(mod, comp)
+ if mod and getattr(mod, '__file__', None):
+ add_file(mod.__file__, mod)
+ except AttributeError:
+ pass
+ return omod
__builtin__.__import__ = new_import
return
View
10 evserver/transports.py
@@ -59,7 +59,7 @@ def __init__(self, *args, **kwargs):
self.headers['Content-Type'] = 'text/html; charset=utf-8'
self.headers['Refresh'] = '3000'
Transport.__init__(self, *args, **kwargs)
- self.alert = "llog('iframe: ' + e.message + ' ' + e);"
+ self.alert = "try{comet_log('iframe: ' + e.message + ' ' + e);}catch(e){}"
initial_data = '''
<html>
@@ -68,13 +68,7 @@ def __init__(self, *args, **kwargs):
<script type="text/javascript" src="./static/comet.js"></script>
<script type="text/javascript" charset="utf-8">
- var newdomain = extract_xss_domain(document.domain);
- if(document.domain != newdomain)
- document.domain = newdomain;
- function llog(txt){
- if(comet_log)
- comet_log(txt);
- }
+ document.domain = extract_xss_domain(document.domain);
</script>
</head>
<body onLoad="try{parent.%(callback)s_reconnect();}catch(e){%(alert)s}">
Please sign in to comment.
Something went wrong with that request. Please try again.