Revision ca6bb3d5 templates/poller.js

b/templates/poller.js
11 11
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 12
// License for the specific language governing permissions and limitations
13 13
// under the License.
14

  
14
var xhrlp = '';
15 15
$(document).ready(function() {
16 16
    if (!window.console) window.console = {};
17 17
    if (!window.console.log) window.console.log = function() {};
......
29 29
    $("#message").select();
30 30
    {% if user.is_authenticated %}
31 31
    updater.start();
32
    updater.poll();
32
    updater.keepalive();
33
    
33 34
    {% endif %}
34 35
});
35 36

  
37

  
38

  
36 39
function newMessage(form) {
37 40
    var message = form.formToDict();
38 41
    var disabled = form.find("input[type=submit]");
......
89 92
var updater = {
90 93
    errorSleepTime: 500,
91 94
    cursor: null,
95
    xhrlp: null,
96
    
97
    keepalive: function (){
98
	try {
99
		updater.xhrlp.abort();
100
	}
101
	catch (e) {	 
102
	}
103
	updater.poll();
104
	if (updater.errorSleepTime == 500){
105
		window.setTimeout(updater.keepalive, 180000);
106
	}
107
//	if (updater.errorSleepTime > 60000){
108
//		window.setTimeout('location.reload()', 3000);
109
//		}
110
	},
92 111
    
93 112
    start: function() {
94
    	$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
113
		$.ajax({url: "{% url fetch-existing %}", type: "POST", dataType: "text",
95 114
    		success: updater.onFetchExisting,
96 115
    		error: updater.onError});
97 116
        },
98 117
    
99 118
    poll: function() {
100
	{% if user.is_authenticated %}
101
	$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
102
		success: updater.onSuccess,
103
		error: updater.onError});
104
	{% endif %}
119
    	{% if user.is_authenticated %}
120
    	if (updater.errorSleepTime > 60000){
121
    		window.setTimeout('location.reload()', 1000);
122
    		}
123
    	updater.xhrlp=$.ajax({url: "{% url fetch-updates %}", type: "POST", dataType: "text",
124
    		success: updater.onSuccess,
125
    		error: updater.onError});
126
    	{% endif %}
105 127
    },
106

  
107 128
    onSuccess: function(response) {
108 129
	try {
109 130
	    updater.newMessages(eval("(" + response + ")"));
......
124 145
    	}
125 146
        },
126 147
     
127
    onError: function(response) {
128
	updater.errorSleepTime *= 2;
129
	console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
130
	window.setTimeout(updater.poll, updater.errorSleepTime);
148
    onError: function(response, text) {
149
        	if (text != 'abort'){
150
				updater.errorSleepTime *= 2;
151
				console.log("Poll error; sleeping for", updater.errorSleepTime, "ms");
152
				window.setTimeout(updater.keepalive, updater.errorSleepTime);
153
        	}
131 154
    },
132 155

  
133 156
    newMessages: function(response) {

Also available in: Unified diff