So here we go ![]()
The last few nights, I was coding AJAX stream tool based on Mootools and XHR (part of Moo’s Remoting). I’ll like to write more examples soon, but 1st i’ll post the code not for the masses, so any suggest will be discussed and etc. Ideas are welcome
var MooStreamer = XHR.extend({
messageTag:"msg",
pollingInterval:null,
pollingSpeed:150,
lastIndex:0,
initialize: function(options){
this.parent(options);
},
send: function(url, data) {
switch($type(data)){
case 'element': data = $(data).toQueryString(); break;
case 'object': data = Object.toQueryString(data);
} //Ajax.request's code for toQueryString converting
this.pollingInterval = this.streamReader.bind(this).periodical(this.pollingSpeed);
this.nextReadPos=1;
this.parent(url, data);
},
streamReader: function() {
var txt = this.transport.responseText;
var msgs = txt.split(new RegExp(“\<”+this.messageTag+”\>(.*?)\<\/”+this.messageTag+”\>”,”gi”));
for(k in msgs) {
if(k >= this.lastIndex && msgs[k].length != 0 && msgs[k].indexOf(“<”+this.messageTag+”>”) == -1) {
//console.log(“idx(“+k+”/”+this.lastIndex+”) = “+msgs[k])
eval(msgs[k]);
this.lastIndex+=2;
}
}
if (!this.running) $clear(this.pollingInterval);
}
});
More on AJAX Streaming technologies, like Load balancing, PHP frameworks and etc.. soon
Let’s move the discussion to Mootools Forum