- function receiveMessageEvent(event)
- {
- for (var i in servers) {
- if (event.origin === rcserverbase(servers[i])) {
- messages = JSON.parse(event.data);
- for (var j in messages) {
- if ('Time' in messages[j] &&
- 'ID' in messages[j] &&
- 'Text' in messages[j]) {
- receiveMessage(servers[i], messages[j]['Time'], messages[j]['ID'], messages[j]['Text']);
+ function rcfetch(server) {
+ var delay = 10000; // TODO: Exponential backoff
+ var xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function() {
+ if (this.readyState == this.DONE) {
+ if (this.status == 200) {
+ var rtxt = this.responseText;
+ if (rtxt != null) {
+ var messages = JSON.parse(rtxt);
+ if (messages != null) {
+ rcreceivemessages(server, messages);
+ window.parent.postMessage(rtxt, "*");
+ delay = 40;
+ if (messages.length >= 1 && "Time" in messages[messages.length-1]) {
+ since[server] = messages[messages.length-1]["Time"];
+ }
+ }