4 * Require the given path.
7 * @return {Object} exports
11 function require(path
, parent
, orig
) {
12 var resolved
= require
.resolve(path
);
15 if (null == resolved
) {
17 parent
= parent
|| 'root';
18 var err
= new Error('Failed to require "' + orig
+ '" from "' + parent
+ '"');
25 var module
= require
.modules
[resolved
];
27 // perform real require()
28 // by invoking the module's
29 // registered function
30 if (!module
.exports
) {
32 module
.client
= module
.component
= true;
33 module
.call(this, module
.exports
, require
.relative(resolved
), module
);
36 return module
.exports
;
60 * @param {String} path
61 * @return {String} path or null
65 require
.resolve = function(path
) {
66 if (path
.charAt(0) === '/') path
= path
.slice(1);
67 var index
= path
+ '/index.js';
77 for (var i
= 0; i
< paths
.length
; i
++) {
79 if (require
.modules
.hasOwnProperty(path
)) return path
;
82 if (require
.aliases
.hasOwnProperty(index
)) {
83 return require
.aliases
[index
];
88 * Normalize `path` relative to the current path.
90 * @param {String} curr
91 * @param {String} path
96 require
.normalize = function(curr
, path
) {
99 if ('.' != path
.charAt(0)) return path
;
101 curr
= curr
.split('/');
102 path
= path
.split('/');
104 for (var i
= 0; i
< path
.length
; ++i
) {
105 if ('..' == path
[i
]) {
107 } else if ('.' != path
[i
] && '' != path
[i
]) {
112 return curr
.concat(segs
).join('/');
116 * Register module at `path` with callback `definition`.
118 * @param {String} path
119 * @param {Function} definition
123 require
.register = function(path
, definition
) {
124 require
.modules
[path
] = definition
;
128 * Alias a module definition.
130 * @param {String} from
135 require
.alias = function(from, to
) {
136 if (!require
.modules
.hasOwnProperty(from)) {
137 throw new Error('Failed to alias "' + from + '", it does not exist');
139 require
.aliases
[to
] = from;
143 * Return a require function relative to the `parent` path.
145 * @param {String} parent
150 require
.relative = function(parent
) {
151 var p
= require
.normalize(parent
, '..');
154 * lastIndexOf helper.
157 function lastIndexOf(arr
, obj
) {
160 if (arr
[i
] === obj
) return i
;
166 * The relative require() itself.
169 function localRequire(path
) {
170 var resolved
= localRequire
.resolve(path
);
171 return require(resolved
, parent
, path
);
175 * Resolve relative to the parent.
178 localRequire
.resolve = function(path
) {
179 var c
= path
.charAt(0);
180 if ('/' == c
) return path
.slice(1);
181 if ('.' == c
) return require
.normalize(p
, path
);
183 // resolve deps by returning
184 // the dep in the nearest "deps"
186 var segs
= parent
.split('/');
187 var i
= lastIndexOf(segs
, 'deps') + 1;
189 path
= segs
.slice(0, i
+ 1).join('/') + '/deps/' + path
;
194 * Check if module is defined at `path`.
197 localRequire
.exists = function(path
) {
198 return require
.modules
.hasOwnProperty(localRequire
.resolve(path
));
203 require
.register("component-emitter/index.js", function(exports
, require
, module
){
209 module
.exports
= Emitter
;
212 * Initialize a new `Emitter`.
217 function Emitter(obj
) {
218 if (obj
) return mixin(obj
);
222 * Mixin the emitter properties.
224 * @param {Object} obj
229 function mixin(obj
) {
230 for (var key
in Emitter
.prototype) {
231 obj
[key
] = Emitter
.prototype[key
];
237 * Listen on the given `event` with `fn`.
239 * @param {String} event
240 * @param {Function} fn
245 Emitter
.prototype.on = function(event
, fn
){
246 this._callbacks
= this._callbacks
|| {};
247 (this._callbacks
[event
] = this._callbacks
[event
] || [])
253 * Adds an `event` listener that will be invoked a single
254 * time then automatically removed.
256 * @param {String} event
257 * @param {Function} fn
262 Emitter
.prototype.once = function(event
, fn
){
264 this._callbacks
= this._callbacks
|| {};
268 fn
.apply(this, arguments
);
277 * Remove the given callback for `event` or all
278 * registered callbacks.
280 * @param {String} event
281 * @param {Function} fn
286 Emitter
.prototype.off
=
287 Emitter
.prototype.removeListener
=
288 Emitter
.prototype.removeAllListeners = function(event
, fn
){
289 this._callbacks
= this._callbacks
|| {};
292 if (0 == arguments
.length
) {
293 this._callbacks
= {};
298 var callbacks
= this._callbacks
[event
];
299 if (!callbacks
) return this;
301 // remove all handlers
302 if (1 == arguments
.length
) {
303 delete this._callbacks
[event
];
307 // remove specific handler
308 var i
= callbacks
.indexOf(fn
._off
|| fn
);
309 if (~i
) callbacks
.splice(i
, 1);
314 * Emit `event` with the given args.
316 * @param {String} event
321 Emitter
.prototype.emit = function(event
){
322 this._callbacks
= this._callbacks
|| {};
323 var args
= [].slice
.call(arguments
, 1)
324 , callbacks
= this._callbacks
[event
];
327 callbacks
= callbacks
.slice(0);
328 for (var i
= 0, len
= callbacks
.length
; i
< len
; ++i
) {
329 callbacks
[i
].apply(this, args
);
337 * Return array of callbacks for `event`.
339 * @param {String} event
344 Emitter
.prototype.listeners = function(event
){
345 this._callbacks
= this._callbacks
|| {};
346 return this._callbacks
[event
] || [];
350 * Check if this emitter has `event` handlers.
352 * @param {String} event
357 Emitter
.prototype.hasListeners = function(event
){
358 return !! this.listeners(event
).length
;
362 require
.register("component-indexof/index.js", function(exports
, require
, module
){
364 var indexOf
= [].indexOf
;
366 module
.exports = function(arr
, obj
){
367 if (indexOf
) return arr
.indexOf(obj
);
368 for (var i
= 0; i
< arr
.length
; ++i
) {
369 if (arr
[i
] === obj
) return i
;
374 require
.register("LearnBoost-engine.io-protocol/lib/index.js", function(exports
, require
, module
){
376 * Module dependencies.
379 var keys
= require('./keys');
382 * Current protocol version.
384 exports
.protocol
= 2;
390 var packets
= exports
.packets
= {
400 var packetslist
= keys(packets
);
403 * Premade error packet.
406 var err
= { type
: 'error', data
: 'parser error' };
411 * <packet type id> [ `:` <data> ]
422 exports
.encodePacket = function (packet
) {
423 var encoded
= packets
[packet
.type
];
425 // data fragment is optional
426 if (undefined !== packet
.data
) {
427 encoded
+= String(packet
.data
);
436 * @return {Object} with `type` and `data` (if any)
440 exports
.decodePacket = function (data
) {
441 var type
= data
.charAt(0);
443 if (Number(type
) != type
|| !packetslist
[type
]) {
447 if (data
.length
> 1) {
448 return { type
: packetslist
[type
], data
: data
.substring(1) };
450 return { type
: packetslist
[type
] };
455 * Encodes multiple messages (payload).
463 * @param {Array} packets
467 exports
.encodePayload = function (packets
) {
468 if (!packets
.length
) {
475 for (var i
= 0, l
= packets
.length
; i
< l
; i
++) {
476 message
= exports
.encodePacket(packets
[i
]);
477 encoded
+= message
.length
+ ':' + message
;
484 * Decodes data when a payload is maybe expected.
486 * @param {String} data, callback method
490 exports
.decodePayload = function (data
, callback
) {
493 // parser error - ignoring payload
494 return callback(err
, 0, 1);
500 for (var i
= 0, l
= data
.length
; i
< l
; i
++) {
501 var chr
= data
.charAt(i
);
506 if ('' == length
|| (length
!= (n
= Number(length
)))) {
507 // parser error - ignoring payload
508 return callback(err
, 0, 1);
511 msg
= data
.substr(i
+ 1, n
);
513 if (length
!= msg
.length
) {
514 // parser error - ignoring payload
515 return callback(err
, 0, 1);
519 packet
= exports
.decodePacket(msg
);
521 if (err
.type
== packet
.type
&& err
.data
== packet
.data
) {
522 // parser error in individual packet - ignoring payload
523 return callback(err
, 0, 1);
526 var ret
= callback(packet
, i
+ n
, l
);
527 if (false === ret
) return;
537 // parser error - ignoring payload
538 return callback(err
, 0, 1);
544 require
.register("LearnBoost-engine.io-protocol/lib/keys.js", function(exports
, require
, module
){
547 * Gets the keys for an object.
549 * @return {Array} keys
553 module
.exports
= Object
.keys
|| function keys (obj
){
555 var has
= Object
.prototype.hasOwnProperty
;
558 if (has
.call(obj
, i
)) {
566 require
.register("visionmedia-debug/index.js", function(exports
, require
, module
){
567 if ('undefined' == typeof window
) {
568 module
.exports
= require('./lib/debug');
570 module
.exports
= require('./debug');
574 require
.register("visionmedia-debug/debug.js", function(exports
, require
, module
){
577 * Expose `debug()` as the module.
580 module
.exports
= debug
;
583 * Create a debugger with the given `name`.
585 * @param {String} name
590 function debug(name
) {
591 if (!debug
.enabled(name
)) return function(){};
593 return function(fmt
){
597 var ms
= curr
- (debug
[name
] || curr
);
603 + ' +' + debug
.humanize(ms
);
605 // This hackery is required for IE8
606 // where `console.log` doesn't have 'apply'
609 && Function
.prototype.apply
.call(console
.log
, console
, arguments
);
614 * The currently active debug mode names.
621 * Enables a debug mode by name. This can include modes
622 * separated by a colon and wildcards.
624 * @param {String} name
628 debug
.enable = function(name
) {
630 localStorage
.debug
= name
;
633 var split
= (name
|| '').split(/[\s,]+/)
634 , len
= split
.length
;
636 for (var i
= 0; i
< len
; i
++) {
637 name
= split
[i
].replace('*', '.*?');
638 if (name
[0] === '-') {
639 debug
.skips
.push(new RegExp('^' + name
.substr(1) + '$'));
642 debug
.names
.push(new RegExp('^' + name
+ '$'));
648 * Disable debug output.
653 debug
.disable = function(){
658 * Humanize the given `ms`.
665 debug
.humanize = function(ms
) {
670 if (ms
>= hour
) return (ms
/ hour
).toFixed(1) + 'h';
671 if (ms
>= min
) return (ms
/ min
).toFixed(1) + 'm';
672 if (ms
>= sec
) return (ms
/ sec
| 0) + 's';
677 * Returns true if the given mode name is enabled, false otherwise.
679 * @param {String} name
684 debug
.enabled = function(name
) {
685 for (var i
= 0, len
= debug
.skips
.length
; i
< len
; i
++) {
686 if (debug
.skips
[i
].test(name
)) {
690 for (var i
= 0, len
= debug
.names
.length
; i
< len
; i
++) {
691 if (debug
.names
[i
].test(name
)) {
702 function coerce(val
) {
703 if (val
instanceof Error
) return val
.stack
|| val
.message
;
709 if (window
.localStorage
) debug
.enable(localStorage
.debug
);
712 require
.register("engine.io/lib/index.js", function(exports
, require
, module
){
714 module
.exports
= require('./socket');
722 module
.exports
.parser
= require('engine.io-parser');
725 require
.register("engine.io/lib/socket.js", function(exports
, require
, module
){
727 * Module dependencies.
730 var util
= require('./util')
731 , transports
= require('./transports')
732 , Emitter
= require('./emitter')
733 , debug
= require('debug')('engine-client:socket')
734 , index
= require('indexof')
735 , parser
= require('engine.io-parser');
741 module
.exports
= Socket
;
747 var global
= util
.global();
758 * Socket constructor.
760 * @param {String|Object} uri or options
761 * @param {Object} options
765 function Socket(uri
, opts
){
766 if (!(this instanceof Socket
)) return new Socket(uri
, opts
);
770 if ('object' == typeof uri
) {
776 uri
= util
.parseUri(uri
);
777 opts
.host
= uri
.host
;
778 opts
.secure
= uri
.protocol
== 'https' || uri
.protocol
== 'wss';
779 opts
.port
= uri
.port
;
780 if (uri
.query
) opts
.query
= uri
.query
;
783 this.secure
= null != opts
.secure
? opts
.secure
:
784 (global
.location
&& 'https:' == location
.protocol
);
787 var pieces
= opts
.host
.split(':');
788 opts
.hostname
= pieces
.shift();
789 if (pieces
.length
) opts
.port
= pieces
.pop();
792 this.hostname
= opts
.hostname
||
793 (global
.location
? location
.hostname
: 'localhost');
794 this.port
= opts
.port
|| (global
.location
&& location
.port
?
796 (this.secure
? 443 : 80));
797 this.query
= opts
.query
|| {};
798 if ('string' == typeof this.query
) this.query
= util
.qsParse(this.query
);
799 this.upgrade
= false !== opts
.upgrade
;
800 this.path
= (opts
.path
|| '/engine.io').replace(/\/$/, '') + '/';
801 this.forceJSONP = !!opts.forceJSONP;
802 this.timestampParam = opts.timestampParam || 't
';
803 this.timestampRequests = !!opts.timestampRequests;
804 this.flashPath = opts.flashPath || '';
805 this.transports = opts.transports || ['polling
', 'websocket
', 'flashsocket
'];
806 this.readyState = '';
807 this.writeBuffer = [];
808 this.callbackBuffer = [];
809 this.policyPort = opts.policyPort || 843;
812 Socket.sockets.push(this);
813 Socket.sockets.evs.emit('add
', this);
820 Emitter(Socket.prototype);
828 Socket.protocol = parser.protocol; // this is an int
831 * Static EventEmitter.
835 Socket.sockets.evs = new Emitter;
838 * Expose deps for legacy compatibility
839 * and standalone browser access.
842 Socket.Socket = Socket;
843 Socket.Transport = require('./transport
');
844 Socket.Emitter = require('./emitter
');
845 Socket.transports = require('./transports
');
846 Socket.util = require('./util
');
847 Socket.parser = require('engine
.io
-parser
');
850 * Creates transport of the given type.
852 * @param {String} transport name
853 * @return {Transport}
857 Socket.prototype.createTransport = function (name) {
858 debug('creating transport
"%s"', name);
859 var query = clone(this.query);
861 // append engine.io protocol identifier
862 query.EIO = parser.protocol;
865 query.transport = name;
867 // session id if we already have one
868 if (this.id) query.sid = this.id;
870 var transport = new transports[name]({
871 hostname: this.hostname,
876 forceJSONP: this.forceJSONP,
877 timestampRequests: this.timestampRequests,
878 timestampParam: this.timestampParam,
879 flashPath: this.flashPath,
880 policyPort: this.policyPort
886 function clone (obj) {
889 if (obj.hasOwnProperty(i)) {
897 * Initializes transport to use and starts probe.
902 Socket.prototype.open = function () {
903 this.readyState = 'opening
';
904 var transport = this.createTransport(this.transports[0]);
906 this.setTransport(transport);
910 * Sets the current transport. Disables the existing one (if any).
915 Socket.prototype.setTransport = function (transport) {
918 if (this.transport) {
919 debug('clearing existing transport
');
920 this.transport.removeAllListeners();
924 this.transport = transport;
926 // set up transport listeners
928 .on('drain
', function () {
931 .on('packet
', function (packet) {
932 self.onPacket(packet);
934 .on('error
', function (e) {
937 .on('close
', function () {
938 self.onClose('transport close
');
943 * Probes a transport.
945 * @param {String} transport name
949 Socket.prototype.probe = function (name) {
950 debug('probing transport
"%s"', name);
951 var transport = this.createTransport(name, { probe: 1 })
955 transport.once('open
', function () {
958 debug('probe transport
"%s" opened
', name);
959 transport.send([{ type: 'ping
', data: 'probe
' }]);
960 transport.once('packet
', function (msg) {
962 if ('pong
' == msg.type && 'probe
' == msg.data) {
963 debug('probe transport
"%s" pong
', name);
964 self.upgrading = true;
965 self.emit('upgrading
', transport);
967 debug('pausing current transport
"%s"', self.transport.name);
968 self.transport.pause(function () {
970 if ('closed
' == self.readyState || 'closing
' == self.readyState) {
973 debug('changing transport and sending upgrade packet
');
974 transport.removeListener('error
', onerror);
975 self.emit('upgrade
', transport);
976 self.setTransport(transport);
977 transport.send([{ type: 'upgrade
' }]);
979 self.upgrading = false;
983 debug('probe transport
"%s" failed
', name);
984 var err = new Error('probe error
');
985 err.transport = transport.name;
986 self.emit('error
', err);
991 transport.once('error
', onerror);
992 function onerror(err) {
995 // Any callback called by transport should be ignored since now
998 var error = new Error('probe error
: ' + err);
999 error.transport = transport.name;
1004 debug('probe transport
"%s" failed because
of error
: %s
', name, err);
1006 self.emit('error
', error);
1011 this.once('close
', function () {
1013 debug('socket closed prematurely
- aborting probe
');
1020 this.once('upgrading
', function (to) {
1021 if (transport && to.name != transport.name) {
1022 debug('"%s" works
- aborting
"%s"', to.name, transport.name);
1030 * Called when connection is deemed open.
1035 Socket.prototype.onOpen = function () {
1036 debug('socket open
');
1037 this.readyState = 'open
';
1039 this.onopen && this.onopen.call(this);
1042 // we check for `readyState` in case an `open`
1043 // listener alreay closed the socket
1044 if ('open
' == this.readyState && this.upgrade && this.transport.pause) {
1045 debug('starting upgrade probes
');
1046 for (var i = 0, l = this.upgrades.length; i < l; i++) {
1047 this.probe(this.upgrades[i]);
1058 Socket.prototype.onPacket = function (packet) {
1059 if ('opening
' == this.readyState || 'open
' == this.readyState) {
1060 debug('socket receive
: type
"%s", data
"%s"', packet.type, packet.data);
1062 this.emit('packet
', packet);
1064 // Socket is live - any packet counts
1065 this.emit('heartbeat
');
1067 switch (packet.type) {
1069 this.onHandshake(util.parseJSON(packet.data));
1077 var err = new Error('server error
');
1078 err.code = packet.data;
1079 this.emit('error
', err);
1083 this.emit('data
', packet.data);
1084 this.emit('message
', packet.data);
1085 var event = { data: packet.data };
1086 event.toString = function () {
1089 this.onmessage && this.onmessage.call(this, event);
1093 debug('packet received
with socket readyState
"%s"', this.readyState);
1098 * Called upon handshake completion.
1100 * @param {Object} handshake obj
1104 Socket.prototype.onHandshake = function (data) {
1105 this.emit('handshake
', data);
1107 this.transport.query.sid = data.sid;
1108 this.upgrades = this.filterUpgrades(data.upgrades);
1109 this.pingInterval = data.pingInterval;
1110 this.pingTimeout = data.pingTimeout;
1114 // Prolong liveness of socket on heartbeat
1115 this.removeListener('heartbeat
', this.onHeartbeat);
1116 this.on('heartbeat
', this.onHeartbeat);
1120 * Resets ping timeout.
1125 Socket.prototype.onHeartbeat = function (timeout) {
1126 clearTimeout(this.pingTimeoutTimer);
1128 self.pingTimeoutTimer = setTimeout(function () {
1129 if ('closed
' == self.readyState) return;
1130 self.onClose('ping timeout
');
1131 }, timeout || (self.pingInterval + self.pingTimeout));
1135 * Pings server every `this.pingInterval` and expects response
1136 * within `this.pingTimeout` or closes connection.
1141 Socket.prototype.setPing = function () {
1143 clearTimeout(self.pingIntervalTimer);
1144 self.pingIntervalTimer = setTimeout(function () {
1145 debug('writing ping packet
- expecting pong within
%sms
', self.pingTimeout);
1147 self.onHeartbeat(self.pingTimeout);
1148 }, self.pingInterval);
1152 * Sends a ping packet.
1157 Socket.prototype.ping = function () {
1158 this.sendPacket('ping
');
1162 * Called on `drain` event
1167 Socket.prototype.onDrain = function() {
1168 for (var i = 0; i < this.prevBufferLen; i++) {
1169 if (this.callbackBuffer[i]) {
1170 this.callbackBuffer[i]();
1174 this.writeBuffer.splice(0, this.prevBufferLen);
1175 this.callbackBuffer.splice(0, this.prevBufferLen);
1177 // setting prevBufferLen = 0 is very important
1178 // for example, when upgrading, upgrade packet is sent over,
1179 // and a nonzero prevBufferLen could cause problems on `drain`
1180 this.prevBufferLen = 0;
1182 if (this.writeBuffer.length == 0) {
1190 * Flush write buffers.
1195 Socket.prototype.flush = function () {
1196 if ('closed
' != this.readyState && this.transport.writable &&
1197 !this.upgrading && this.writeBuffer.length) {
1198 debug('flushing
%d packets
in socket
', this.writeBuffer.length);
1199 this.transport.send(this.writeBuffer);
1200 // keep track of current length of writeBuffer
1201 // splice writeBuffer and callbackBuffer on `drain`
1202 this.prevBufferLen = this.writeBuffer.length;
1210 * @param {String} message.
1211 * @param {Function} callback function.
1212 * @return {Socket} for chaining.
1216 Socket.prototype.write =
1217 Socket.prototype.send = function (msg, fn) {
1218 this.sendPacket('message
', msg, fn);
1225 * @param {String} packet type.
1226 * @param {String} data.
1227 * @param {Function} callback function.
1231 Socket.prototype.sendPacket = function (type, data, fn) {
1232 var packet = { type: type, data: data };
1233 this.emit('packetCreate
', packet);
1234 this.writeBuffer.push(packet);
1235 this.callbackBuffer.push(fn);
1240 * Closes the connection.
1245 Socket.prototype.close = function () {
1246 if ('opening
' == this.readyState || 'open
' == this.readyState) {
1247 this.onClose('forced close
');
1248 debug('socket closing
- telling transport to close
');
1249 this.transport.close();
1256 * Called upon transport error
1261 Socket.prototype.onError = function (err) {
1262 debug('socket error
%j
', err);
1263 this.emit('error
', err);
1264 this.onerror && this.onerror.call(this, err);
1265 this.onClose('transport error
', err);
1269 * Called upon transport close.
1274 Socket.prototype.onClose = function (reason, desc) {
1275 if ('opening
' == this.readyState || 'open
' == this.readyState) {
1276 debug('socket close
with reason
: "%s"', reason);
1280 clearTimeout(this.pingIntervalTimer);
1281 clearTimeout(this.pingTimeoutTimer);
1283 // clean buffers in next tick, so developers can still
1284 // grab the buffers on `close` event
1285 setTimeout(function() {
1286 self.writeBuffer = [];
1287 self.callbackBuffer = [];
1290 // ignore further transport communication
1291 this.transport.removeAllListeners();
1294 var prev = this.readyState;
1295 this.readyState = 'closed
';
1301 if (prev == 'open
') {
1302 this.emit('close
', reason, desc);
1303 this.onclose && this.onclose.call(this);
1309 * Filters upgrades, returning only those matching client transports.
1311 * @param {Array} server upgrades
1316 Socket.prototype.filterUpgrades = function (upgrades) {
1317 var filteredUpgrades = [];
1318 for (var i = 0, j = upgrades.length; i<j; i++) {
1319 if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
1321 return filteredUpgrades;
1325 require.register("engine.io/lib/transport.js", function(exports, require, module){
1328 * Module dependencies.
1331 var util = require('./util
')
1332 , parser = require('engine
.io
-parser
')
1333 , Emitter = require('./emitter
');
1339 module.exports = Transport;
1342 * Transport abstract constructor.
1344 * @param {Object} options.
1348 function Transport (opts) {
1349 this.path = opts.path;
1350 this.hostname = opts.hostname;
1351 this.port = opts.port;
1352 this.secure = opts.secure;
1353 this.query = opts.query;
1354 this.timestampParam = opts.timestampParam;
1355 this.timestampRequests = opts.timestampRequests;
1356 this.readyState = '';
1363 Emitter(Transport.prototype);
1368 * @param {String} str
1369 * @return {Transport} for chaining
1373 Transport.prototype.onError = function (msg, desc) {
1374 var err = new Error(msg);
1375 err.type = 'TransportError
';
1376 err.description = desc;
1377 this.emit('error
', err);
1382 * Opens the transport.
1387 Transport.prototype.open = function () {
1388 if ('closed
' == this.readyState || '' == this.readyState) {
1389 this.readyState = 'opening
';
1397 * Closes the transport.
1402 Transport.prototype.close = function () {
1403 if ('opening
' == this.readyState || 'open
' == this.readyState) {
1412 * Sends multiple packets.
1414 * @param {Array} packets
1418 Transport.prototype.send = function(packets){
1419 if ('open
' == this.readyState) {
1420 this.write(packets);
1422 throw new Error('Transport not open
');
1432 Transport.prototype.onOpen = function () {
1433 this.readyState = 'open
';
1434 this.writable = true;
1441 * @param {String} data
1445 Transport.prototype.onData = function (data) {
1446 this.onPacket(parser.decodePacket(data));
1450 * Called with a decoded packet.
1453 Transport.prototype.onPacket = function (packet) {
1454 this.emit('packet
', packet);
1458 * Called upon close.
1463 Transport.prototype.onClose = function () {
1464 this.readyState = 'closed
';
1469 require.register("engine.io/lib/emitter.js", function(exports, require, module){
1472 * Module dependencies.
1475 var Emitter = require('emitter
');
1481 module.exports = Emitter;
1484 * Compatibility with `WebSocket#addEventListener`.
1489 Emitter.prototype.addEventListener = Emitter.prototype.on;
1492 * Compatibility with `WebSocket#removeEventListener`.
1497 Emitter.prototype.removeEventListener = Emitter.prototype.off;
1500 * Node-compatible `EventEmitter#removeListener`
1505 Emitter.prototype.removeListener = Emitter.prototype.off;
1508 require.register("engine.io/lib/util.js", function(exports, require, module){
1510 * Status of page load.
1513 var pageLoaded = false;
1516 * Returns the global object
1521 exports.global = function () {
1522 return 'undefined' != typeof window ? window : global;
1528 * @param {Function} ctor a
1529 * @param {Function} ctor b
1533 exports.inherits = function inherits (a, b) {
1535 c.prototype = b.prototype;
1536 a.prototype = new c;
1543 exports.keys = Object.keys || function (obj) {
1545 var has = Object.prototype.hasOwnProperty;
1547 for (var i in obj) {
1548 if (has.call(obj, i)) {
1562 exports.on = function (element, event, fn, capture) {
1563 if (element.attachEvent) {
1564 element.attachEvent('on
' + event, fn);
1565 } else if (element.addEventListener) {
1566 element.addEventListener(event, fn, capture);
1576 exports.load = function (fn) {
1577 var global = exports.global();
1578 if (global.document && document.readyState === 'complete
' || pageLoaded) {
1582 exports.on(global, 'load
', fn, false);
1586 * Change the internal pageLoaded value.
1589 if ('undefined' != typeof window) {
1590 exports.load(function () {
1596 * Defers a function to ensure a spinner is not displayed by the browser.
1598 * @param {Function} fn
1602 exports.defer = function (fn) {
1603 if (!exports.ua.webkit || 'undefined' != typeof importScripts) {
1607 exports.load(function () {
1608 setTimeout(fn, 100);
1615 * @see Based on jQuery#parseJSON (MIT) and JSON2
1619 var rvalidchars = /^[\],:{}\s]*$/;
1620 var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
1621 var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
1622 var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
1623 var rtrimLeft = /^\s+/;
1624 var rtrimRight = /\s+$/;
1626 exports.parseJSON = function (data) {
1627 var global = exports.global();
1629 if ('string
' != typeof data || !data) {
1633 data = data.replace(rtrimLeft, '').replace(rtrimRight, '');
1635 // Attempt to parse using the native JSON parser first
1636 if (global.JSON && JSON.parse) {
1637 return JSON.parse(data);
1640 if (rvalidchars.test(data.replace(rvalidescape, '@')
1641 .replace(rvalidtokens, ']')
1642 .replace(rvalidbraces, ''))) {
1643 return (new Function('return ' + data))();
1648 * UA / engines detection namespace.
1656 * Whether the UA supports CORS for XHR.
1661 exports.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function () {
1664 a = new XMLHttpRequest();
1669 return a.withCredentials != undefined;
1678 exports.ua.webkit = 'undefined' != typeof navigator &&
1679 /webkit/i.test(navigator.userAgent);
1687 exports.ua.gecko = 'undefined' != typeof navigator &&
1688 /gecko/i.test(navigator.userAgent);
1694 exports.ua.android = 'undefined' != typeof navigator &&
1695 /android/i.test(navigator.userAgent);
1701 exports.ua.ios = 'undefined' != typeof navigator &&
1702 /^(iPad|iPhone|iPod)$/.test(navigator.platform);
1703 exports.ua.ios6 = exports.ua.ios && /OS 6_/.test(navigator.userAgent);
1706 * XHR request helper.
1708 * @param {Boolean} whether we need xdomain
1712 exports.request = function request (xdomain) {
1714 var _XMLHttpRequest = require('xmlhttprequest
').XMLHttpRequest;
1715 return new _XMLHttpRequest();
1718 if (xdomain && 'undefined' != typeof XDomainRequest && !exports.ua.hasCORS) {
1719 return new XDomainRequest();
1722 // XMLHttpRequest can be disabled on IE
1724 if ('undefined' != typeof XMLHttpRequest && (!xdomain || exports.ua.hasCORS)) {
1725 return new XMLHttpRequest();
1731 return new ActiveXObject('Microsoft
.XMLHTTP
');
1739 * @author Steven Levithan <stevenlevithan.com> (MIT license)
1743 var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
1746 'source
', 'protocol
', 'authority
', 'userInfo
', 'user
', 'password
', 'host
'
1747 , 'port
', 'relative
', 'path
', 'directory
', 'file
', 'query
', 'anchor
'
1750 exports.parseUri = function (str) {
1751 var m = re.exec(str || '')
1756 uri[parts[i]] = m[i] || '';
1763 * Compiles a querystring
1769 exports.qs = function (obj) {
1772 for (var i in obj) {
1773 if (obj.hasOwnProperty(i)) {
1774 if (str.length) str += '&';
1775 str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
1783 * Parses a simple querystring.
1785 * @param {String} qs
1789 exports.qsParse = function(qs){
1791 var pairs = qs.split('&');
1792 for (var i = 0, l = pairs.length; i < l; i++) {
1793 var pair = pairs[i].split('=');
1794 qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
1800 require.register("engine.io/lib/transports/index.js", function(exports, require, module){
1803 * Module dependencies
1806 var XHR = require('./polling
-xhr
')
1807 , JSONP = require('./polling
-jsonp
')
1808 , websocket = require('./websocket
')
1809 , flashsocket = require('./flashsocket
')
1810 , util = require('../util
');
1813 * Export transports.
1816 exports.polling = polling;
1817 exports.websocket = websocket;
1818 exports.flashsocket = flashsocket;
1824 var global = util.global()
1827 * Polling transport polymorphic constructor.
1828 * Decides on xhr vs jsonp based on feature detection.
1833 function polling (opts) {
1836 , isXProtocol = false;
1838 if (global.location) {
1839 var isSSL = 'https
:' == location.protocol;
1840 var port = location.port;
1842 // some user agents have empty `location.port`
1843 if (Number(port) !== port) {
1844 port = isSSL ? 443 : 80;
1847 xd = opts.hostname != location.hostname || port != opts.port;
1848 isXProtocol = opts.secure != isSSL;
1851 xhr = util.request(xd);
1852 /* See #7 at http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx */
1853 if (isXProtocol && global.XDomainRequest && xhr instanceof global.XDomainRequest) {
1854 return new JSONP(opts);
1857 if (xhr && !opts.forceJSONP) {
1858 return new XHR(opts);
1860 return new JSONP(opts);
1865 require.register("engine.io/lib/transports/polling.js", function(exports, require, module){
1867 * Module dependencies.
1870 var Transport = require('../transport
')
1871 , util = require('../util
')
1872 , parser = require('engine
.io
-parser
')
1873 , debug = require('debug
')('engine
.io
-client
:polling
');
1879 module.exports = Polling;
1885 var global = util.global();
1888 * Polling interface.
1890 * @param {Object} opts
1894 function Polling(opts){
1895 Transport.call(this, opts);
1899 * Inherits from Transport.
1902 util.inherits(Polling, Transport);
1908 Polling.prototype.name = 'polling
';
1911 * Opens the socket (triggers polling). We write a PING message to determine
1912 * when the transport is open.
1917 Polling.prototype.doOpen = function(){
1924 * @param {Function} callback upon buffers are flushed and transport is paused
1928 Polling.prototype.pause = function(onPause){
1932 this.readyState = 'pausing
';
1936 self.readyState = 'paused
';
1940 if (this.polling || !this.writable) {
1944 debug('we are currently polling
- waiting to pause
');
1946 this.once('pollComplete
', function(){
1947 debug('pre
-pause polling complete
');
1952 if (!this.writable) {
1953 debug('we are currently writing
- waiting to pause
');
1955 this.once('drain
', function(){
1956 debug('pre
-pause writing complete
');
1966 * Starts polling cycle.
1971 Polling.prototype.poll = function(){
1973 this.polling = true;
1979 * Overloads onData to detect payloads.
1984 Polling.prototype.onData = function(data){
1986 debug('polling got data
%s
', data);
1989 parser.decodePayload(data, function(packet, index, total) {
1990 // if its the first message we consider the transport open
1991 if ('opening
' == self.readyState) {
1995 // if its a close packet, we close the ongoing requests
1996 if ('close
' == packet.type) {
2001 // otherwise bypass onData and handle the message
2002 self.onPacket(packet);
2005 // if an event did not trigger closing
2006 if ('closed
' != this.readyState) {
2007 // if we got data we're not polling
2008 this.polling
= false;
2009 this.emit('pollComplete');
2011 if ('open' == this.readyState
) {
2014 debug('ignoring poll - transport state "%s"', this.readyState
);
2020 * For polling, send a close packet.
2025 Polling
.prototype.doClose = function(){
2029 debug('writing close packet');
2030 self
.write([{ type
: 'close' }]);
2034 debug('transport open - closing');
2037 // in case we're trying to close while
2038 // handshaking is in progress (GH-164)
2039 debug('transport not open - defering close');
2040 this.once('open', close
);
2045 * Writes a packets payload.
2047 * @param {Array} data packets
2048 * @param {Function} drain callback
2052 Polling
.prototype.write = function(packets
){
2054 this.writable
= false;
2055 this.doWrite(parser
.encodePayload(packets
), function(){
2056 self
.writable
= true;
2062 * Generates uri for connection.
2067 Polling
.prototype.uri = function(){
2068 var query
= this.query
|| {};
2069 var schema
= this.secure
? 'https' : 'http';
2072 // cache busting is forced for IE / android / iOS6 ಠ_à²
2073 if (global
.ActiveXObject
|| util
.ua
.android
|| util
.ua
.ios6
||
2074 this.timestampRequests
) {
2075 query
[this.timestampParam
] = +new Date
;
2078 query
= util
.qs(query
);
2080 // avoid port if default for schema
2081 if (this.port
&& (('https' == schema
&& this.port
!= 443) ||
2082 ('http' == schema
&& this.port
!= 80))) {
2083 port
= ':' + this.port
;
2086 // prepend ? to query
2088 query
= '?' + query
;
2091 return schema
+ '://' + this.hostname
+ port
+ this.path
+ query
;
2095 require
.register("engine.io/lib/transports/polling-xhr.js", function(exports
, require
, module
){
2097 * Module requirements.
2100 var Polling
= require('./polling')
2101 , util
= require('../util')
2102 , Emitter
= require('../emitter')
2103 , debug
= require('debug')('engine.io-client:polling-xhr');
2109 module
.exports
= XHR
;
2110 module
.exports
.Request
= Request
;
2116 var global
= util
.global();
2120 * Obfuscated key for Blue Coat.
2123 var xobject
= global
[['Active'].concat('Object').join('X')];
2132 * XHR Polling constructor.
2134 * @param {Object} opts
2139 Polling
.call(this, opts
);
2141 if (global
.location
) {
2142 var isSSL
= 'https:' == location
.protocol
;
2143 var port
= location
.port
;
2145 // some user agents have empty `location.port`
2146 if (Number(port
) !== port
) {
2147 port
= isSSL
? 443 : 80;
2150 this.xd
= opts
.hostname
!= global
.location
.hostname
||
2156 * Inherits from Polling.
2159 util
.inherits(XHR
, Polling
);
2167 XHR
.prototype.doOpen = function(){
2169 util
.defer(function(){
2170 Polling
.prototype.doOpen
.call(self
);
2175 * Creates a request.
2177 * @param {String} method
2181 XHR
.prototype.request = function(opts
){
2183 opts
.uri
= this.uri();
2185 return new Request(opts
);
2191 * @param {String} data to send.
2192 * @param {Function} called upon flush.
2196 XHR
.prototype.doWrite = function(data
, fn
){
2197 var req
= this.request({ method
: 'POST', data
: data
});
2199 req
.on('success', fn
);
2200 req
.on('error', function(err
){
2201 self
.onError('xhr post error', err
);
2207 * Starts a poll cycle.
2212 XHR
.prototype.doPoll = function(){
2214 var req
= this.request();
2216 req
.on('data', function(data
){
2219 req
.on('error', function(err
){
2220 self
.onError('xhr poll error', err
);
2226 * Request constructor
2228 * @param {Object} options
2232 function Request(opts
){
2233 this.method
= opts
.method
|| 'GET';
2234 this.uri
= opts
.uri
;
2235 this.xd
= !!opts
.xd
;
2236 this.async
= false !== opts
.async
;
2237 this.data
= undefined != opts
.data
? opts
.data
: null;
2245 Emitter(Request
.prototype);
2248 * Creates the XHR object and sends the request.
2253 Request
.prototype.create = function(){
2254 var xhr
= this.xhr
= util
.request(this.xd
);
2257 xhr
.open(this.method
, this.uri
, this.async
);
2259 if ('POST' == this.method
) {
2261 if (xhr
.setRequestHeader
) {
2263 xhr
.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
2266 xhr
.contentType
= 'text/plain';
2271 if (this.xd
&& global
.XDomainRequest
&& xhr
instanceof XDomainRequest
) {
2272 xhr
.onerror = function(e
){
2275 xhr
.onload = function(){
2276 self
.onData(xhr
.responseText
);
2278 xhr
.onprogress
= empty
;
2281 if ('withCredentials' in xhr
) {
2282 xhr
.withCredentials
= true;
2285 xhr
.onreadystatechange = function(){
2289 if (4 != xhr
.readyState
) return;
2290 if (200 == xhr
.status
|| 1223 == xhr
.status
) {
2291 data
= xhr
.responseText
;
2293 self
.onError(xhr
.status
);
2299 if (undefined !== data
) {
2305 debug('sending xhr with url %s | data %s', this.uri
, this.data
);
2306 xhr
.send(this.data
);
2309 this.index
= Request
.requestsCount
++;
2310 Request
.requests
[this.index
] = this;
2315 * Called upon successful response.
2320 Request
.prototype.onSuccess = function(){
2321 this.emit('success');
2326 * Called if we have data.
2331 Request
.prototype.onData = function(data
){
2332 this.emit('data', data
);
2337 * Called upon error.
2342 Request
.prototype.onError = function(err
){
2343 this.emit('error', err
);
2353 Request
.prototype.cleanup = function(){
2354 if ('undefined' == typeof this.xhr
) {
2358 this.xhr
.onreadystatechange
= empty
;
2361 this.xhr
.onload
= this.xhr
.onerror
= empty
;
2368 delete Request
.requests
[this.index
];
2375 * Aborts the request.
2380 Request
.prototype.abort = function(){
2385 Request
.requestsCount
= 0;
2386 Request
.requests
= {};
2388 global
.attachEvent('onunload', function(){
2389 for (var i
in Request
.requests
) {
2390 if (Request
.requests
.hasOwnProperty(i
)) {
2391 Request
.requests
[i
].abort();
2398 require
.register("engine.io/lib/transports/polling-jsonp.js", function(exports
, require
, module
){
2401 * Module requirements.
2404 var Polling
= require('./polling')
2405 , util
= require('../util');
2411 module
.exports
= JSONPPolling
;
2417 var global
= util
.global();
2420 * Cached regular expressions.
2423 var rNewline
= /\n/g;
2426 * Global JSONP callbacks.
2441 function empty () { }
2444 * JSONP Polling constructor.
2446 * @param {Object} opts.
2450 function JSONPPolling (opts
) {
2451 Polling
.call(this, opts
);
2453 // define global callbacks array if not present
2454 // we do this here (lazily) to avoid unneeded global pollution
2456 // we need to consider multiple engines in the same page
2457 if (!global
.___eio
) global
.___eio
= [];
2458 callbacks
= global
.___eio
;
2461 // callback identifier
2462 this.index
= callbacks
.length
;
2464 // add callback to jsonp global
2466 callbacks
.push(function (msg
) {
2470 // append to query string
2471 this.query
.j
= this.index
;
2475 * Inherits from Polling.
2478 util
.inherits(JSONPPolling
, Polling
);
2486 JSONPPolling
.prototype.doOpen = function () {
2488 util
.defer(function () {
2489 Polling
.prototype.doOpen
.call(self
);
2499 JSONPPolling
.prototype.doClose = function () {
2501 this.script
.parentNode
.removeChild(this.script
);
2506 this.form
.parentNode
.removeChild(this.form
);
2510 Polling
.prototype.doClose
.call(this);
2514 * Starts a poll cycle.
2519 JSONPPolling
.prototype.doPoll = function () {
2521 var script
= document
.createElement('script');
2524 this.script
.parentNode
.removeChild(this.script
);
2528 script
.async
= true;
2529 script
.src
= this.uri();
2530 script
.onerror = function(e
){
2531 self
.onError('jsonp poll error',e
);
2534 var insertAt
= document
.getElementsByTagName('script')[0];
2535 insertAt
.parentNode
.insertBefore(script
, insertAt
);
2536 this.script
= script
;
2539 if (util
.ua
.gecko
) {
2540 setTimeout(function () {
2541 var iframe
= document
.createElement('iframe');
2542 document
.body
.appendChild(iframe
);
2543 document
.body
.removeChild(iframe
);
2549 * Writes with a hidden iframe.
2551 * @param {String} data to send
2552 * @param {Function} called upon flush.
2556 JSONPPolling
.prototype.doWrite = function (data
, fn
) {
2560 var form
= document
.createElement('form');
2561 var area
= document
.createElement('textarea');
2562 var id
= this.iframeId
= 'eio_iframe_' + this.index
;
2565 form
.className
= 'socketio';
2566 form
.style
.position
= 'absolute';
2567 form
.style
.top
= '-1000px';
2568 form
.style
.left
= '-1000px';
2570 form
.method
= 'POST';
2571 form
.setAttribute('accept-charset', 'utf-8');
2573 form
.appendChild(area
);
2574 document
.body
.appendChild(form
);
2580 this.form
.action
= this.uri();
2582 function complete () {
2587 function initIframe () {
2590 self
.form
.removeChild(self
.iframe
);
2592 self
.onError('jsonp polling iframe removal error', e
);
2597 // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
2598 var html
= '<iframe src="javascript:0" name="'+ self
.iframeId
+'">';
2599 iframe
= document
.createElement(html
);
2601 iframe
= document
.createElement('iframe');
2602 iframe
.name
= self
.iframeId
;
2603 iframe
.src
= 'javascript:0';
2606 iframe
.id
= self
.iframeId
;
2608 self
.form
.appendChild(iframe
);
2609 self
.iframe
= iframe
;
2614 // escape \n to prevent it from being converted into \r\n by some UAs
2615 this.area
.value
= data
.replace(rNewline
, '\\n');
2621 if (this.iframe
.attachEvent
) {
2622 this.iframe
.onreadystatechange = function(){
2623 if (self
.iframe
.readyState
== 'complete') {
2628 this.iframe
.onload
= complete
;
2633 require
.register("engine.io/lib/transports/websocket.js", function(exports
, require
, module
){
2635 * Module dependencies.
2638 var Transport
= require('../transport')
2639 , parser
= require('engine.io-parser')
2640 , util
= require('../util')
2641 , debug
= require('debug')('engine.io-client:websocket');
2647 module
.exports
= WS
;
2653 var global
= util
.global();
2656 * WebSocket transport constructor.
2658 * @api {Object} connection options
2663 Transport
.call(this, opts
);
2667 * Inherits from Transport.
2670 util
.inherits(WS
, Transport
);
2678 WS
.prototype.name
= 'websocket';
2686 WS
.prototype.doOpen = function(){
2687 if (!this.check()) {
2688 // let probe timeout
2694 this.socket
= new (ws())(this.uri());
2695 this.socket
.onopen = function(){
2698 this.socket
.onclose = function(){
2701 this.socket
.onmessage = function(ev
){
2702 self
.onData(ev
.data
);
2704 this.socket
.onerror = function(e
){
2705 self
.onError('websocket error', e
);
2710 * Override `onData` to use a timer on iOS.
2711 * See: https://gist.github.com/mloughran/2052006
2716 if ('undefined' != typeof navigator
2717 && /iPad|iPhone|iPod/i.test(navigator
.userAgent
)) {
2718 WS
.prototype.onData = function(data
){
2720 setTimeout(function(){
2721 Transport
.prototype.onData
.call(self
, data
);
2727 * Writes data to socket.
2729 * @param {Array} array of packets.
2733 WS
.prototype.write = function(packets
){
2735 this.writable
= false;
2736 // encodePacket efficient as it uses WS framing
2737 // no need for encodePayload
2738 for (var i
= 0, l
= packets
.length
; i
< l
; i
++) {
2739 this.socket
.send(parser
.encodePacket(packets
[i
]));
2741 function ondrain() {
2742 self
.writable
= true;
2745 // check periodically if we're done sending
2746 if ('bufferedAmount' in this.socket
) {
2747 this.bufferedAmountId
= setInterval(function() {
2748 if (self
.socket
.bufferedAmount
== 0) {
2749 clearInterval(self
.bufferedAmountId
);
2755 // defer to next tick to allow Socket to clear writeBuffer
2756 setTimeout(ondrain
, 0);
2766 WS
.prototype.onClose = function(){
2767 // stop checking to see if websocket is done sending buffer
2768 clearInterval(this.bufferedAmountId
);
2769 Transport
.prototype.onClose
.call(this);
2778 WS
.prototype.doClose = function(){
2779 if (typeof this.socket
!== 'undefined') {
2780 this.socket
.close();
2785 * Generates uri for connection.
2790 WS
.prototype.uri = function(){
2791 var query
= this.query
|| {};
2792 var schema
= this.secure
? 'wss' : 'ws';
2795 // avoid port if default for schema
2796 if (this.port
&& (('wss' == schema
&& this.port
!= 443)
2797 || ('ws' == schema
&& this.port
!= 80))) {
2798 port
= ':' + this.port
;
2801 // append timestamp to URI
2802 if (this.timestampRequests
) {
2803 query
[this.timestampParam
] = +new Date
;
2806 query
= util
.qs(query
);
2808 // prepend ? to query
2810 query
= '?' + query
;
2813 return schema
+ '://' + this.hostname
+ port
+ this.path
+ query
;
2817 * Feature detection for WebSocket.
2819 * @return {Boolean} whether this transport is available.
2823 WS
.prototype.check = function(){
2824 var websocket
= ws();
2825 return !!websocket
&& !('__initialize' in websocket
&& this.name
=== WS
.prototype.name
);
2829 * Getter for WS constructor.
2835 if ('undefined' == typeof window
) {
2836 return require('ws');
2839 return global
.WebSocket
|| global
.MozWebSocket
;
2843 require
.register("engine.io/lib/transports/flashsocket.js", function(exports
, require
, module
){
2845 * Module dependencies.
2848 var WS
= require('./websocket')
2849 , util
= require('../util')
2850 , debug
= require('debug')('engine.io-client:flashsocket');
2856 module
.exports
= FlashWS
;
2862 var global
= util
.global()
2865 * Obfuscated key for Blue Coat.
2868 var xobject
= global
[['Active'].concat('Object').join('X')];
2871 * FlashWS constructor.
2876 function FlashWS (options
) {
2877 WS
.call(this, options
);
2878 this.flashPath
= options
.flashPath
;
2879 this.policyPort
= options
.policyPort
;
2883 * Inherits from WebSocket.
2886 util
.inherits(FlashWS
, WS
);
2894 FlashWS
.prototype.name
= 'flashsocket';
2897 * Opens the transport.
2902 FlashWS
.prototype.doOpen = function () {
2903 if (!this.check()) {
2904 // let the probe timeout
2908 // instrument websocketjs logging
2909 function log (type
) {
2911 var str
= Array
.prototype.join
.call(arguments
, ' ');
2912 debug('[websocketjs %s] %s', type
, str
);
2916 WEB_SOCKET_LOGGER
= { log
: log('debug'), error
: log('error') };
2917 WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR
= true;
2918 WEB_SOCKET_DISABLE_AUTO_INITIALIZATION
= true;
2920 if ('undefined' == typeof WEB_SOCKET_SWF_LOCATION
) {
2921 WEB_SOCKET_SWF_LOCATION
= this.flashPath
+ 'WebSocketMainInsecure.swf';
2925 var deps
= [this.flashPath
+ 'web_socket.js'];
2927 if ('undefined' == typeof swfobject
) {
2928 deps
.unshift(this.flashPath
+ 'swfobject.js');
2933 load(deps
, function () {
2934 self
.ready(function () {
2935 WebSocket
.__addTask(function () {
2936 WS
.prototype.doOpen
.call(self
);
2943 * Override to prevent closing uninitialized flashsocket.
2948 FlashWS
.prototype.doClose = function () {
2949 if (!this.socket
) return;
2951 WebSocket
.__addTask(function() {
2952 WS
.prototype.doClose
.call(self
);
2957 * Writes to the Flash socket.
2962 FlashWS
.prototype.write = function() {
2963 var self
= this, args
= arguments
;
2964 WebSocket
.__addTask(function () {
2965 WS
.prototype.write
.apply(self
, args
);
2970 * Called upon dependencies are loaded.
2975 FlashWS
.prototype.ready = function (fn
) {
2976 if (typeof WebSocket
== 'undefined' ||
2977 !('__initialize' in WebSocket
) || !swfobject
) {
2981 if (swfobject
.getFlashPlayerVersion().major
< 10) {
2986 // Only start downloading the swf file when the checked that this browser
2987 // actually supports it
2988 if (!FlashWS
.loaded
) {
2989 if (843 != self
.policyPort
) {
2990 WebSocket
.loadFlashPolicyFile('xmlsocket://' + self
.host
+ ':' + self
.policyPort
);
2993 WebSocket
.__initialize();
2994 FlashWS
.loaded
= true;
3001 if (document
.body
) {
3009 * Feature detection for flashsocket.
3011 * @return {Boolean} whether this transport is available.
3015 FlashWS
.prototype.check = function () {
3016 if ('undefined' == typeof window
) {
3020 if (typeof WebSocket
!= 'undefined' && !('__initialize' in WebSocket
)) {
3027 control
= new xobject('ShockwaveFlash.ShockwaveFlash');
3033 for (var i
= 0, l
= navigator
.plugins
.length
; i
< l
; i
++) {
3034 for (var j
= 0, m
= navigator
.plugins
[i
].length
; j
< m
; j
++) {
3035 if (navigator
.plugins
[i
][j
].description
== 'Shockwave Flash') {
3046 * Lazy loading of scripts.
3047 * Based on $script by Dustin Diaz - MIT
3053 * Injects a script. Keeps tracked of injected ones.
3055 * @param {String} path
3056 * @param {Function} callback
3060 function create (path
, fn
) {
3061 if (scripts
[path
]) return fn();
3063 var el
= document
.createElement('script');
3066 debug('loading "%s"', path
);
3067 el
.onload
= el
.onreadystatechange = function () {
3068 if (loaded
|| scripts
[path
]) return;
3069 var rs
= el
.readyState
;
3070 if (!rs
|| 'loaded' == rs
|| 'complete' == rs
) {
3071 debug('loaded "%s"', path
);
3072 el
.onload
= el
.onreadystatechange
= null;
3074 scripts
[path
] = true;
3082 var head
= document
.getElementsByTagName('head')[0];
3083 head
.insertBefore(el
, head
.firstChild
);
3087 * Loads scripts and fires a callback.
3089 * @param {Array} paths
3090 * @param {Function} callback
3093 function load (arr
, fn
) {
3094 function process (i
) {
3095 if (!arr
[i
]) return fn();
3096 create(arr
[i
], function () {
3105 require
.alias("component-emitter/index.js", "engine.io/deps/emitter/index.js");
3106 require
.alias("component-emitter/index.js", "emitter/index.js");
3108 require
.alias("component-indexof/index.js", "engine.io/deps/indexof/index.js");
3109 require
.alias("component-indexof/index.js", "indexof/index.js");
3111 require
.alias("LearnBoost-engine.io-protocol/lib/index.js", "engine.io/deps/engine.io-parser/lib/index.js");
3112 require
.alias("LearnBoost-engine.io-protocol/lib/keys.js", "engine.io/deps/engine.io-parser/lib/keys.js");
3113 require
.alias("LearnBoost-engine.io-protocol/lib/index.js", "engine.io/deps/engine.io-parser/index.js");
3114 require
.alias("LearnBoost-engine.io-protocol/lib/index.js", "engine.io-parser/index.js");
3115 require
.alias("LearnBoost-engine.io-protocol/lib/index.js", "LearnBoost-engine.io-protocol/index.js");
3117 require
.alias("visionmedia-debug/index.js", "engine.io/deps/debug/index.js");
3118 require
.alias("visionmedia-debug/debug.js", "engine.io/deps/debug/debug.js");
3119 require
.alias("visionmedia-debug/index.js", "debug/index.js");
3121 require
.alias("engine.io/lib/index.js", "engine.io/index.js");
3123 if (typeof exports
== "object") {
3124 module
.exports
= require("engine.io");
3125 } else if (typeof define
== "function" && define
.amd
) {
3126 define(function(){ return require("engine.io"); });
3128 this["eio"] = require("engine.io");