rc-web@69
|
1
|
rc-web@69
|
2 /*!
|
rc-web@69
|
3 * socket.io-node
|
rc-web@69
|
4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
rc-web@69
|
5 * MIT Licensed
|
rc-web@69
|
6 */
|
rc-web@69
|
7
|
rc-web@69
|
8 /**
|
rc-web@69
|
9 * Module requirements.
|
rc-web@69
|
10 */
|
rc-web@69
|
11
|
rc-web@69
|
12 var HTTPTransport = require('./http');
|
rc-web@69
|
13
|
rc-web@69
|
14 /**
|
rc-web@69
|
15 * Exports the constructor.
|
rc-web@69
|
16 */
|
rc-web@69
|
17
|
rc-web@69
|
18 exports = module.exports = HTTPPolling;
|
rc-web@69
|
19
|
rc-web@69
|
20 /**
|
rc-web@69
|
21 * HTTP polling constructor.
|
rc-web@69
|
22 *
|
rc-web@69
|
23 * @api public.
|
rc-web@69
|
24 */
|
rc-web@69
|
25
|
rc-web@69
|
26 function HTTPPolling (mng, data, req) {
|
rc-web@69
|
27 HTTPTransport.call(this, mng, data, req);
|
rc-web@69
|
28 };
|
rc-web@69
|
29
|
rc-web@69
|
30 /**
|
rc-web@69
|
31 * Inherits from HTTPTransport.
|
rc-web@69
|
32 *
|
rc-web@69
|
33 * @api public.
|
rc-web@69
|
34 */
|
rc-web@69
|
35
|
rc-web@69
|
36 HTTPPolling.prototype.__proto__ = HTTPTransport.prototype;
|
rc-web@69
|
37
|
rc-web@69
|
38 /**
|
rc-web@69
|
39 * Transport name
|
rc-web@69
|
40 *
|
rc-web@69
|
41 * @api public
|
rc-web@69
|
42 */
|
rc-web@69
|
43
|
rc-web@69
|
44 HTTPPolling.prototype.name = 'httppolling';
|
rc-web@69
|
45
|
rc-web@69
|
46 /**
|
rc-web@69
|
47 * Override setHandlers
|
rc-web@69
|
48 *
|
rc-web@69
|
49 * @api private
|
rc-web@69
|
50 */
|
rc-web@69
|
51
|
rc-web@69
|
52 HTTPPolling.prototype.setHandlers = function () {
|
rc-web@69
|
53 HTTPTransport.prototype.setHandlers.call(this);
|
rc-web@69
|
54 this.socket.removeListener('end', this.bound.end);
|
rc-web@69
|
55 this.socket.removeListener('close', this.bound.close);
|
rc-web@69
|
56 };
|
rc-web@69
|
57
|
rc-web@69
|
58 /**
|
rc-web@69
|
59 * Removes heartbeat timeouts for polling.
|
rc-web@69
|
60 */
|
rc-web@69
|
61
|
rc-web@69
|
62 HTTPPolling.prototype.setHeartbeatInterval = function () {
|
rc-web@69
|
63 return this;
|
rc-web@69
|
64 };
|
rc-web@69
|
65
|
rc-web@69
|
66 /**
|
rc-web@69
|
67 * Handles a request
|
rc-web@69
|
68 *
|
rc-web@69
|
69 * @api private
|
rc-web@69
|
70 */
|
rc-web@69
|
71
|
rc-web@69
|
72 HTTPPolling.prototype.handleRequest = function (req) {
|
rc-web@69
|
73 HTTPTransport.prototype.handleRequest.call(this, req);
|
rc-web@69
|
74
|
rc-web@69
|
75 if (req.method == 'GET') {
|
rc-web@69
|
76 var self = this;
|
rc-web@69
|
77
|
rc-web@69
|
78 this.pollTimeout = setTimeout(function () {
|
rc-web@69
|
79 self.packet({ type: 'noop' });
|
rc-web@69
|
80 self.log.debug(self.name + ' closed due to exceeded duration');
|
rc-web@69
|
81 }, this.manager.get('polling duration') * 1000);
|
rc-web@69
|
82
|
rc-web@69
|
83 this.log.debug('setting poll timeout');
|
rc-web@69
|
84 }
|
rc-web@69
|
85 };
|
rc-web@69
|
86
|
rc-web@69
|
87 /**
|
rc-web@69
|
88 * Clears polling timeout
|
rc-web@69
|
89 *
|
rc-web@69
|
90 * @api private
|
rc-web@69
|
91 */
|
rc-web@69
|
92
|
rc-web@69
|
93 HTTPPolling.prototype.clearPollTimeout = function () {
|
rc-web@69
|
94 if (this.pollTimeout) {
|
rc-web@69
|
95 clearTimeout(this.pollTimeout);
|
rc-web@69
|
96 this.pollTimeout = null;
|
rc-web@69
|
97 this.log.debug('clearing poll timeout');
|
rc-web@69
|
98 }
|
rc-web@69
|
99
|
rc-web@69
|
100 return this;
|
rc-web@69
|
101 };
|
rc-web@69
|
102
|
rc-web@69
|
103 /**
|
rc-web@69
|
104 * Override clear timeouts to clear the poll timeout
|
rc-web@69
|
105 *
|
rc-web@69
|
106 * @api private
|
rc-web@69
|
107 */
|
rc-web@69
|
108
|
rc-web@69
|
109 HTTPPolling.prototype.clearTimeouts = function () {
|
rc-web@69
|
110 HTTPTransport.prototype.clearTimeouts.call(this);
|
rc-web@69
|
111
|
rc-web@69
|
112 this.clearPollTimeout();
|
rc-web@69
|
113 };
|
rc-web@69
|
114
|
rc-web@69
|
115 /**
|
rc-web@69
|
116 * doWrite to clear poll timeout
|
rc-web@69
|
117 *
|
rc-web@69
|
118 * @api private
|
rc-web@69
|
119 */
|
rc-web@69
|
120
|
rc-web@69
|
121 HTTPPolling.prototype.doWrite = function () {
|
rc-web@69
|
122 this.clearPollTimeout();
|
rc-web@69
|
123 };
|
rc-web@69
|
124
|
rc-web@69
|
125 /**
|
rc-web@69
|
126 * Performs a write.
|
rc-web@69
|
127 *
|
rc-web@69
|
128 * @api private.
|
rc-web@69
|
129 */
|
rc-web@69
|
130
|
rc-web@69
|
131 HTTPPolling.prototype.write = function (data, close) {
|
rc-web@69
|
132 this.doWrite(data);
|
rc-web@69
|
133 this.response.end();
|
rc-web@69
|
134 this.onClose();
|
rc-web@69
|
135 };
|
rc-web@69
|
136
|
rc-web@69
|
137 /**
|
rc-web@69
|
138 * Override end.
|
rc-web@69
|
139 *
|
rc-web@69
|
140 * @api private
|
rc-web@69
|
141 */
|
rc-web@69
|
142
|
rc-web@69
|
143 HTTPPolling.prototype.end = function (reason) {
|
rc-web@69
|
144 this.clearPollTimeout();
|
rc-web@69
|
145 return HTTPTransport.prototype.end.call(this, reason);
|
rc-web@69
|
146 };
|
rc-web@69
|
147
|