this.listeners[type].push(callback);
}else{
this.source.addEventListener(type,function(e){
- callback(JSON.parse(e.data));
+ if (typeof e.data != 'undefined') {
+ callback(JSON.parse(e.data));
+ } else {
+ callback('');
+ }
},false);
}
}else{
});
updateEventSource.listen('error', function(message) {
$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
+ message = 'Please reload the page.';
+ $('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
+ updateEventSource.close();
});
updateEventSource.listen('failure', function(message) {
$('<span>').addClass('error').append(message).append('<br />').appendTo($('.update'));
window.location.href = OC.webroot;
}, 3000);
});
-});
\ No newline at end of file
+});
* wrapper for server side events (http://en.wikipedia.org/wiki/Server-sent_events)
* includes a fallback for older browsers and IE
*
- * use server side events with causion, to many open requests can hang the server
+ * use server side events with caution, to many open requests can hang the server
*/
class OC_EventSource{
private $fallback;
header("Content-Type: text/event-stream");
}
if( !OC_Util::isCallRegistered()) {
+ $this->send('error', 'Possible CSRF attack. Connection will be closed.');
exit();
}
flush();
/**
* send a message to the client
- * @param string type
- * @param object data
+ * @param string $type
+ * @param object $data
*
- * if only one paramater is given, a typeless message will be send with that paramater as data
+ * if only one parameter is given, a typeless message will be send with that parameter as data
*/
public function send($type, $data=null) {
if(is_null($data)) {