mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Fixed htmlfile
- end > close for detecting closed connections - Added hearbeats - added flush() in write
This commit is contained in:
@@ -8,12 +8,21 @@ this['htmlfile'] = Client.extend({
|
||||
switch (req.method){
|
||||
case 'GET':
|
||||
this.__super__(req, res);
|
||||
this.request.connection.addListener('end', function(){ self._onClose(); });
|
||||
this.response.useChunkedEncodingByDefault = false;
|
||||
this.request.connection.addListener('close', function(){ self._onClose(); });
|
||||
this.response.useChunkedEncodingByDefault = true;
|
||||
this.response.shouldKeepAlive = true;
|
||||
this.response.writeHead(200, { 'Content-type': 'text/html' });
|
||||
this.response.writeHead(200, {
|
||||
'Content-Type': 'text/html',
|
||||
'Connection': 'keep-alive',
|
||||
'Transfer-Encoding': 'chunked'
|
||||
});
|
||||
this.response.write('<html><body>' + new Array(244).join(' '));
|
||||
this.response.flush();
|
||||
this._payload();
|
||||
setInterval(function(){
|
||||
self.response.write('<!-- heartbeat -->');
|
||||
self.response.flush();
|
||||
}, 1000);
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
@@ -24,7 +33,7 @@ this['htmlfile'] = Client.extend({
|
||||
try {
|
||||
var msg = qs.parse(body);
|
||||
self._onMessage(msg.data);
|
||||
} catch(e){}
|
||||
} catch(e){}
|
||||
res.writeHead(200);
|
||||
res.write('ok');
|
||||
res.end();
|
||||
@@ -34,8 +43,8 @@ this['htmlfile'] = Client.extend({
|
||||
},
|
||||
|
||||
_write: function(message){
|
||||
// not sure if this is enough escaping. looks lousy
|
||||
this.response.write("<script>parent.callback('"+ message.replace(/'/, "\'") +"')</script>");
|
||||
this.response.write('<script>parent.s._('+ message +', document);</script>');
|
||||
this.response.flush();
|
||||
}
|
||||
|
||||
});
|
||||
@@ -13,10 +13,10 @@ this['xhr-polling'] = Client.extend({
|
||||
var self = this, body = '';
|
||||
switch (req.method){
|
||||
case 'GET':
|
||||
this.__super__(req, res);
|
||||
this.__super__(req, res);
|
||||
this._closeTimeout = setTimeout(function(){
|
||||
self._write('');
|
||||
}, this.options.duration);
|
||||
}, this.options.duration);
|
||||
this._payload();
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user