Skip to content

Commit

Permalink
mod_base: fix for subdomain polling loop.
Browse files Browse the repository at this point in the history
(cherry picked from commit bcd55ef)
  • Loading branch information
mworrell committed Nov 5, 2013
1 parent 64181a5 commit bf173c6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 65 deletions.
70 changes: 35 additions & 35 deletions modules/mod_base/lib/js/apps/zotonic-1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,57 +493,57 @@ function z_stream_start(host, websocket_host)
{
z_stream_host = host;
z_websocket_host = websocket_host || window.location.host;
setTimeout(function() { z_comet_poll(); }, 1000);
setTimeout(function() { z_comet_start(); }, 1000);
if ("WebSocket" in window)
{
setTimeout(function() { z_websocket_start(); }, 200);
}
}

function z_comet_poll()
function z_comet_start()
{
if (z_ws_pong_count === 0)
if (z_stream_host != window.location.host && window.location.protocol == "http:")
{
if (z_stream_host != window.location.host && window.location.protocol == "http:")
{
var $zc = $('#z_comet_connection');
if ($zc.length > 0) {
$zc.attr('src', $zc.attr('src'));
} else {
var url = window.location.protocol + '//' + z_stream_host + "/comet/subdomain?z_pageid=" + urlencode(z_pageid);
var comet = $('<iframe id="z_comet_connection" name="z_comet_connection" src="'+url+'" />');
comet.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
comet.appendTo("body");
}
}
else
{
z_comet_ajax();
var $zc = $('#z_comet_connection');
if ($zc.length > 0) {
$zc.attr('src', $zc.attr('src'));
} else {
var url = window.location.protocol + '//' + z_stream_host + "/comet/subdomain?z_pageid=" + urlencode(z_pageid);
var comet = $('<iframe id="z_comet_connection" name="z_comet_connection" src="'+url+'" />');
comet.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
comet.appendTo("body");
}
}
else
{
setTimeout(function() { z_comet_poll(); }, 5000);
z_comet_poll_ajax();
}
}

function z_comet_ajax()
function z_comet_poll_ajax()
{
$.ajax({
url: window.location.protocol + '//' + window.location.host + '/comet',
type:'post',
data: "z_pageid=" + urlencode(z_pageid),
dataType: 'text',
success: function(data, textStatus)
{
z_comet_data(data);
setTimeout(function() { z_comet_poll(); }, 1000);
},
error: function(xmlHttpRequest, textStatus, errorThrown)
{
setTimeout(function() { z_comet_poll(); }, 1000);
}
});
if (z_ws_pong_count === 0)
{
$.ajax({
url: window.location.protocol + '//' + window.location.host + '/comet',
type:'post',
data: "z_pageid=" + urlencode(z_pageid),
dataType: 'text',
success: function(data, textStatus)
{
z_comet_data(data);
setTimeout(function() { z_comet_poll_ajax(); }, 500);
},
error: function(xmlHttpRequest, textStatus, errorThrown)
{
setTimeout(function() { z_comet_poll_ajax(); }, 1000);
}
});
}
else
{
setTimeout(function() { z_comet_poll_ajax(); }, 5000);
}
}


Expand Down
76 changes: 46 additions & 30 deletions modules/mod_base/templates/comet_subdomain.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,57 @@
{% include "_js_include_jquery.tpl" %}

<script type="text/javascript">
function z_comet()
function get_poll_count()
{
$.ajax({
url: '/comet',
type: 'post',
data: "z_pageid={{ q.z_pageid|urlencode }}",
dataType: 'text',
success: function(data, textStatus)
{
var old_domain = document.domain;
try
var old_domain = document.domain;
document.domain = "{{ m.site.document_domain }}";
var ws_pong_count = window.parent.z_ws_pong_count;
try {
document.domain = old_domain;
} catch (e) {
}
return ws_pong_count;
}
function handle_poll_data(data)
{
var old_domain = document.domain;
try {
document.domain = "{{ m.site.document_domain }}";
window.parent.z_comet_data(data);
} catch (e) {
if (window.console && window.console.log)
window.console.log(e);
}
try {
document.domain = old_domain;
} catch (e) {
}
}
function z_comet_poll_subdomain()
{
if (get_poll_count() === 0) {
$.ajax({
url: '/comet',
type: 'post',
data: "z_pageid={{ q.z_pageid|urlencode }}",
dataType: 'text',
success: function(data, textStatus)
{
document.domain = "{{ m.site.document_domain }}";
window.parent.z_comet_data(data);
}
catch (e)
handle_poll_data(data);
setTimeout(function() { z_comet_poll_subdomain(); }, 500);
},
error: function(xmlHttpRequest, textStatus, errorThrown)
{
if (window.console && window.console.log)
window.console.log(e);
setTimeout(function() { z_comet_poll_subdomain(); }, 1000);
}
try {
document.domain = old_domain;
} catch (e) {
};
setTimeout("z_comet_poll();", 200);
},
error: function(xmlHttpRequest, textStatus, errorThrown)
{
setTimeout("z_comet_poll();", 1000);
}
});
return;
});
} else {
setTimeout(function() { z_comet_poll_subdomain(); }, 5000);
}
}
setTimeout("z_comet_poll()", 1000);
z_comet_poll_subdomain();
</script>
</body>
</html>

0 comments on commit bf173c6

Please sign in to comment.