From a74c0f0c35b5c6b68619c078c1eabb2f5757040b Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 17 Feb 2014 16:33:00 +0000 Subject: [PATCH] Reverting client engine.io upgrade --- client/assets/libs/engine.io.js | 3775 ++++++++++++++++--------------- 1 file changed, 2002 insertions(+), 1773 deletions(-) diff --git a/client/assets/libs/engine.io.js b/client/assets/libs/engine.io.js index ec5089f..f38b4df 100644 --- a/client/assets/libs/engine.io.js +++ b/client/assets/libs/engine.io.js @@ -1,1638 +1,1876 @@ -!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.eio=e():"undefined"!=typeof global?global.eio=e():"undefined"!=typeof self&&(self.eio=e())}(function(){var define,module,exports; -return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o [ `:` ] + * + * Example: + * + * 5:hello world + * 3 + * 4 * - * @param {Object} handshake obj * @api private */ -Socket.prototype.onHandshake = function (data) { - this.emit('handshake', data); - this.id = data.sid; - this.transport.query.sid = data.sid; - this.upgrades = this.filterUpgrades(data.upgrades); - this.pingInterval = data.pingInterval; - this.pingTimeout = data.pingTimeout; - this.onOpen(); - this.setPing(); +exports.encodePacket = function (packet) { + var encoded = packets[packet.type]; - // Prolong liveness of socket on heartbeat - this.removeListener('heartbeat', this.onHeartbeat); - this.on('heartbeat', this.onHeartbeat); + // data fragment is optional + if (undefined !== packet.data) { + encoded += String(packet.data); + } + + return '' + encoded; }; /** - * Resets ping timeout. + * Decodes a packet. * + * @return {Object} with `type` and `data` (if any) * @api private */ -Socket.prototype.onHeartbeat = function (timeout) { - clearTimeout(this.pingTimeoutTimer); - var self = this; - self.pingTimeoutTimer = setTimeout(function () { - if ('closed' == self.readyState) return; - self.onClose('ping timeout'); - }, timeout || (self.pingInterval + self.pingTimeout)); +exports.decodePacket = function (data) { + var type = data.charAt(0); + + if (Number(type) != type || !packetslist[type]) { + return err; + } + + if (data.length > 1) { + return { type: packetslist[type], data: data.substring(1) }; + } else { + return { type: packetslist[type] }; + } }; /** - * Pings server every `this.pingInterval` and expects response - * within `this.pingTimeout` or closes connection. + * Encodes multiple messages (payload). + * + * :data * + * Example: + * + * 11:hello world2:hi + * + * @param {Array} packets * @api private */ -Socket.prototype.setPing = function () { - var self = this; - clearTimeout(self.pingIntervalTimer); - self.pingIntervalTimer = setTimeout(function () { - debug('writing ping packet - expecting pong within %sms', self.pingTimeout); - self.ping(); - self.onHeartbeat(self.pingTimeout); - }, self.pingInterval); +exports.encodePayload = function (packets) { + if (!packets.length) { + return '0:'; + } + + var encoded = ''; + var message; + + for (var i = 0, l = packets.length; i < l; i++) { + message = exports.encodePacket(packets[i]); + encoded += message.length + ':' + message; + } + + return encoded; }; -/** -* Sends a ping packet. -* -* @api public -*/ +/* + * Decodes data when a payload is maybe expected. + * + * @param {String} data, callback method + * @api public + */ + +exports.decodePayload = function (data, callback) { + var packet; + if (data == '') { + // parser error - ignoring payload + return callback(err, 0, 1); + } + + var length = '' + , n, msg; + + for (var i = 0, l = data.length; i < l; i++) { + var chr = data.charAt(i); + + if (':' != chr) { + length += chr; + } else { + if ('' == length || (length != (n = Number(length)))) { + // parser error - ignoring payload + return callback(err, 0, 1); + } + + msg = data.substr(i + 1, n); + + if (length != msg.length) { + // parser error - ignoring payload + return callback(err, 0, 1); + } + + if (msg.length) { + packet = exports.decodePacket(msg); + + if (err.type == packet.type && err.data == packet.data) { + // parser error in individual packet - ignoring payload + return callback(err, 0, 1); + } + + var ret = callback(packet, i + n, l); + if (false === ret) return; + } + + // advance cursor + i += n; + length = ''; + } + } + + if (length != '') { + // parser error - ignoring payload + return callback(err, 0, 1); + } -Socket.prototype.ping = function () { - this.sendPacket('ping'); }; +}); +require.register("LearnBoost-engine.io-protocol/lib/keys.js", function(exports, require, module){ + /** - * Called on `drain` event + * Gets the keys for an object. * + * @return {Array} keys * @api private */ - Socket.prototype.onDrain = function() { - for (var i = 0; i < this.prevBufferLen; i++) { - if (this.callbackBuffer[i]) { - this.callbackBuffer[i](); +module.exports = Object.keys || function keys (obj){ + var arr = []; + var has = Object.prototype.hasOwnProperty; + + for (var i in obj) { + if (has.call(obj, i)) { + arr.push(i); } } + return arr; +}; - this.writeBuffer.splice(0, this.prevBufferLen); - this.callbackBuffer.splice(0, this.prevBufferLen); +}); +require.register("visionmedia-debug/index.js", function(exports, require, module){ +if ('undefined' == typeof window) { + module.exports = require('./lib/debug'); +} else { + module.exports = require('./debug'); +} - // setting prevBufferLen = 0 is very important - // for example, when upgrading, upgrade packet is sent over, - // and a nonzero prevBufferLen could cause problems on `drain` - this.prevBufferLen = 0; +}); +require.register("visionmedia-debug/debug.js", function(exports, require, module){ - if (this.writeBuffer.length == 0) { - this.emit('drain'); - } else { - this.flush(); - } -}; +/** + * Expose `debug()` as the module. + */ + +module.exports = debug; /** - * Flush write buffers. + * Create a debugger with the given `name`. * - * @api private + * @param {String} name + * @return {Type} + * @api public */ -Socket.prototype.flush = function () { - if ('closed' != this.readyState && this.transport.writable && - !this.upgrading && this.writeBuffer.length) { - debug('flushing %d packets in socket', this.writeBuffer.length); - this.transport.send(this.writeBuffer); - // keep track of current length of writeBuffer - // splice writeBuffer and callbackBuffer on `drain` - this.prevBufferLen = this.writeBuffer.length; - this.emit('flush'); +function debug(name) { + if (!debug.enabled(name)) return function(){}; + + return function(fmt){ + fmt = coerce(fmt); + + var curr = new Date; + var ms = curr - (debug[name] || curr); + debug[name] = curr; + + fmt = name + + ' ' + + fmt + + ' +' + debug.humanize(ms); + + // This hackery is required for IE8 + // where `console.log` doesn't have 'apply' + window.console + && console.log + && Function.prototype.apply.call(console.log, console, arguments); } -}; +} /** - * Sends a message. + * The currently active debug mode names. + */ + +debug.names = []; +debug.skips = []; + +/** + * Enables a debug mode by name. This can include modes + * separated by a colon and wildcards. * - * @param {String} message. - * @param {Function} callback function. - * @return {Socket} for chaining. + * @param {String} name * @api public */ -Socket.prototype.write = -Socket.prototype.send = function (msg, fn) { - this.sendPacket('message', msg, fn); - return this; +debug.enable = function(name) { + try { + localStorage.debug = name; + } catch(e){} + + var split = (name || '').split(/[\s,]+/) + , len = split.length; + + for (var i = 0; i < len; i++) { + name = split[i].replace('*', '.*?'); + if (name[0] === '-') { + debug.skips.push(new RegExp('^' + name.substr(1) + '$')); + } + else { + debug.names.push(new RegExp('^' + name + '$')); + } + } }; /** - * Sends a packet. + * Disable debug output. * - * @param {String} packet type. - * @param {String} data. - * @param {Function} callback function. - * @api private + * @api public */ -Socket.prototype.sendPacket = function (type, data, fn) { - var packet = { type: type, data: data }; - this.emit('packetCreate', packet); - this.writeBuffer.push(packet); - this.callbackBuffer.push(fn); - this.flush(); +debug.disable = function(){ + debug.enable(''); }; /** - * Closes the connection. + * Humanize the given `ms`. * + * @param {Number} m + * @return {String} * @api private */ -Socket.prototype.close = function () { - if ('opening' == this.readyState || 'open' == this.readyState) { - this.onClose('forced close'); - debug('socket closing - telling transport to close'); - this.transport.close(); - } +debug.humanize = function(ms) { + var sec = 1000 + , min = 60 * 1000 + , hour = 60 * min; - return this; + if (ms >= hour) return (ms / hour).toFixed(1) + 'h'; + if (ms >= min) return (ms / min).toFixed(1) + 'm'; + if (ms >= sec) return (ms / sec | 0) + 's'; + return ms + 'ms'; }; /** - * Called upon transport error + * Returns true if the given mode name is enabled, false otherwise. * - * @api private + * @param {String} name + * @return {Boolean} + * @api public */ -Socket.prototype.onError = function (err) { - debug('socket error %j', err); - this.emit('error', err); - this.onerror && this.onerror.call(this, err); - this.onClose('transport error', err); +debug.enabled = function(name) { + for (var i = 0, len = debug.skips.length; i < len; i++) { + if (debug.skips[i].test(name)) { + return false; + } + } + for (var i = 0, len = debug.names.length; i < len; i++) { + if (debug.names[i].test(name)) { + return true; + } + } + return false; }; /** - * Called upon transport close. - * - * @api private + * Coerce `val`. */ -Socket.prototype.onClose = function (reason, desc) { - if ('opening' == this.readyState || 'open' == this.readyState) { - debug('socket close with reason: "%s"', reason); - var self = this; - - // clear timers - clearTimeout(this.pingIntervalTimer); - clearTimeout(this.pingTimeoutTimer); - - // clean buffers in next tick, so developers can still - // grab the buffers on `close` event - setTimeout(function() { - self.writeBuffer = []; - self.callbackBuffer = []; - self.prevBufferLen = 0; - }, 0); +function coerce(val) { + if (val instanceof Error) return val.stack || val.message; + return val; +} - // ignore further transport communication - this.transport.removeAllListeners(); +// persist - // set ready state - this.readyState = 'closed'; +if (window.localStorage) debug.enable(localStorage.debug); - // clear session id - this.id = null; +}); +require.register("engine.io/lib/index.js", function(exports, require, module){ - // emit close event - this.emit('close', reason, desc); - this.onclose && this.onclose.call(this); - } -}; +module.exports = require('./socket'); /** - * Filters upgrades, returning only those matching client transports. + * Exports parser * - * @param {Array} server upgrades - * @api private + * @api public * */ +module.exports.parser = require('engine.io-parser'); -Socket.prototype.filterUpgrades = function (upgrades) { - var filteredUpgrades = []; - for (var i = 0, j = upgrades.length; i