4 * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
8 (function (exports, global) {
24 io.version = '0.9.16';
27 * Protocol implemented.
35 * Available transports, these will be populated with the available transports
43 * Keep track of jsonp callbacks.
51 * Keep track of our io.Sockets
60 * Expose constructors if in Node
63 if ('object' === typeof module && 'function' === typeof require) {
71 io.util = require('./util').util;
79 io.JSON = require('./json').JSON;
87 io.parser = require('./parser').parser;
95 io.EventEmitter = require('./events').EventEmitter;
98 * Expose SocketNamespace
103 io.SocketNamespace = require('./namespace').SocketNamespace;
111 io.Transport = require('./transport').Transport;
114 * Default enabled transports
119 io.transports = ['websocket', 'xhr-polling'];
122 * Expose all transports
127 io.Transport.XHR = require('./transports/xhr').XHR;
129 io.transports.forEach(function (t) {
130 io.Transport[t] = require('./transports/' + t)[t];
139 io.Socket = require('./socket').Socket;
142 * Location of `dist/` directory.
147 io.dist = __dirname + '/../dist';
150 * Expose our build system which can generate
151 * socket.io files on the fly with different transports
156 io.builder = require('../bin/builder');
162 * Manages connections to hosts.
164 * @param {String} uri
165 * @Param {Boolean} force creation of new socket (defaults to false)
169 io.connect = function (host, details) {
170 var uri = io.util.parseUri(host)
174 if (global && global.location) {
175 uri.protocol = uri.protocol || global.location.protocol.slice(0, -1);
176 uri.host = uri.host || (global.document
177 ? global.document.domain : global.location.hostname);
178 uri.port = uri.port || global.location.port;
181 uuri = io.util.uniqueUri(uri);
185 , secure: 'https' == uri.protocol
186 , port: uri.port || ('https' == uri.protocol ? 443 : 80)
187 , query: uri.query || ''
190 io.util.merge(options, details);
192 if (options['force new connection'] || !io.sockets[uuri]) {
193 socket = new io.Socket(options);
196 if (!options['force new connection'] && socket) {
197 io.sockets[uuri] = socket;
200 socket = socket || io.sockets[uuri];
202 // if path is different from '' or /
203 return socket.of(uri.path.length > 1 ? uri.path : '');
206 })('object' === typeof module ? module.exports : (this.io = {}), this);