annotate node_modules/socket.io/lib/transports/jsonp-polling.js @ 69:333afcfd3f3a

added node_modules to project and fixed path to chronometer also added deps to installer script
author tzara <rc-web@kiben.net>
date Sat, 26 Oct 2013 14:12:50 +0100
parents
children
rev   line source
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 HTTPPolling = require('./http-polling');
rc-web@69 13 var jsonpolling_re = /^\d+$/
rc-web@69 14
rc-web@69 15 /**
rc-web@69 16 * Export the constructor.
rc-web@69 17 */
rc-web@69 18
rc-web@69 19 exports = module.exports = JSONPPolling;
rc-web@69 20
rc-web@69 21 /**
rc-web@69 22 * JSON-P polling transport.
rc-web@69 23 *
rc-web@69 24 * @api public
rc-web@69 25 */
rc-web@69 26
rc-web@69 27 function JSONPPolling (mng, data, req) {
rc-web@69 28 HTTPPolling.call(this, mng, data, req);
rc-web@69 29
rc-web@69 30 this.head = 'io.j[0](';
rc-web@69 31 this.foot = ');';
rc-web@69 32
rc-web@69 33 if (data.query.i && jsonpolling_re.test(data.query.i)) {
rc-web@69 34 this.head = 'io.j[' + data.query.i + '](';
rc-web@69 35 }
rc-web@69 36 };
rc-web@69 37
rc-web@69 38 /**
rc-web@69 39 * Inherits from Transport.
rc-web@69 40 */
rc-web@69 41
rc-web@69 42 JSONPPolling.prototype.__proto__ = HTTPPolling.prototype;
rc-web@69 43
rc-web@69 44 /**
rc-web@69 45 * Transport name
rc-web@69 46 *
rc-web@69 47 * @api public
rc-web@69 48 */
rc-web@69 49
rc-web@69 50 JSONPPolling.prototype.name = 'jsonppolling';
rc-web@69 51
rc-web@69 52 /**
rc-web@69 53 * Make sure POST are decoded.
rc-web@69 54 */
rc-web@69 55
rc-web@69 56 JSONPPolling.prototype.postEncoded = true;
rc-web@69 57
rc-web@69 58 /**
rc-web@69 59 * Handles incoming data.
rc-web@69 60 * Due to a bug in \n handling by browsers, we expect a JSONified string.
rc-web@69 61 *
rc-web@69 62 * @api private
rc-web@69 63 */
rc-web@69 64
rc-web@69 65 JSONPPolling.prototype.onData = function (data) {
rc-web@69 66 try {
rc-web@69 67 data = JSON.parse(data);
rc-web@69 68 } catch (e) {
rc-web@69 69 this.error('parse', 'reconnect');
rc-web@69 70 return;
rc-web@69 71 }
rc-web@69 72
rc-web@69 73 HTTPPolling.prototype.onData.call(this, data);
rc-web@69 74 };
rc-web@69 75
rc-web@69 76 /**
rc-web@69 77 * Performs the write.
rc-web@69 78 *
rc-web@69 79 * @api private
rc-web@69 80 */
rc-web@69 81
rc-web@69 82 JSONPPolling.prototype.doWrite = function (data) {
rc-web@69 83 HTTPPolling.prototype.doWrite.call(this);
rc-web@69 84
rc-web@69 85 var data = data === undefined
rc-web@69 86 ? '' : this.head + JSON.stringify(data) + this.foot;
rc-web@69 87
rc-web@69 88 this.response.writeHead(200, {
rc-web@69 89 'Content-Type': 'text/javascript; charset=UTF-8'
rc-web@69 90 , 'Content-Length': Buffer.byteLength(data)
rc-web@69 91 , 'Connection': 'Keep-Alive'
rc-web@69 92 , 'X-XSS-Protection': '0'
rc-web@69 93 });
rc-web@69 94
rc-web@69 95 this.response.write(data);
rc-web@69 96 this.log.debug(this.name + ' writing', data);
rc-web@69 97 };