rc-web@69: rc-web@69: /*! rc-web@69: * socket.io-node rc-web@69: * Copyright(c) 2011 LearnBoost rc-web@69: * MIT Licensed rc-web@69: */ rc-web@69: rc-web@69: /** rc-web@69: * Module requirements. rc-web@69: */ rc-web@69: rc-web@69: var HTTPTransport = require('./http'); rc-web@69: rc-web@69: /** rc-web@69: * Exports the constructor. rc-web@69: */ rc-web@69: rc-web@69: exports = module.exports = HTTPPolling; rc-web@69: rc-web@69: /** rc-web@69: * HTTP polling constructor. rc-web@69: * rc-web@69: * @api public. rc-web@69: */ rc-web@69: rc-web@69: function HTTPPolling (mng, data, req) { rc-web@69: HTTPTransport.call(this, mng, data, req); rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Inherits from HTTPTransport. rc-web@69: * rc-web@69: * @api public. rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.__proto__ = HTTPTransport.prototype; rc-web@69: rc-web@69: /** rc-web@69: * Transport name rc-web@69: * rc-web@69: * @api public rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.name = 'httppolling'; rc-web@69: rc-web@69: /** rc-web@69: * Override setHandlers rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.setHandlers = function () { rc-web@69: HTTPTransport.prototype.setHandlers.call(this); rc-web@69: this.socket.removeListener('end', this.bound.end); rc-web@69: this.socket.removeListener('close', this.bound.close); rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Removes heartbeat timeouts for polling. rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.setHeartbeatInterval = function () { rc-web@69: return this; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Handles a request rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.handleRequest = function (req) { rc-web@69: HTTPTransport.prototype.handleRequest.call(this, req); rc-web@69: rc-web@69: if (req.method == 'GET') { rc-web@69: var self = this; rc-web@69: rc-web@69: this.pollTimeout = setTimeout(function () { rc-web@69: self.packet({ type: 'noop' }); rc-web@69: self.log.debug(self.name + ' closed due to exceeded duration'); rc-web@69: }, this.manager.get('polling duration') * 1000); rc-web@69: rc-web@69: this.log.debug('setting poll timeout'); rc-web@69: } rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Clears polling timeout rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.clearPollTimeout = function () { rc-web@69: if (this.pollTimeout) { rc-web@69: clearTimeout(this.pollTimeout); rc-web@69: this.pollTimeout = null; rc-web@69: this.log.debug('clearing poll timeout'); rc-web@69: } rc-web@69: rc-web@69: return this; rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Override clear timeouts to clear the poll timeout rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.clearTimeouts = function () { rc-web@69: HTTPTransport.prototype.clearTimeouts.call(this); rc-web@69: rc-web@69: this.clearPollTimeout(); rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * doWrite to clear poll timeout rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.doWrite = function () { rc-web@69: this.clearPollTimeout(); rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Performs a write. rc-web@69: * rc-web@69: * @api private. rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.write = function (data, close) { rc-web@69: this.doWrite(data); rc-web@69: this.response.end(); rc-web@69: this.onClose(); rc-web@69: }; rc-web@69: rc-web@69: /** rc-web@69: * Override end. rc-web@69: * rc-web@69: * @api private rc-web@69: */ rc-web@69: rc-web@69: HTTPPolling.prototype.end = function (reason) { rc-web@69: this.clearPollTimeout(); rc-web@69: return HTTPTransport.prototype.end.call(this, reason); rc-web@69: }; rc-web@69: