1 |
|
2 | /**
|
3 | * socket.io
|
4 | * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
5 | * MIT Licensed
|
6 | */
|
7 |
|
8 | (function (exports) {
|
9 |
|
10 | /**
|
11 | * IO namespace.
|
12 | *
|
13 | * @namespace
|
14 | */
|
15 |
|
16 | var io = exports;
|
17 |
|
18 | /**
|
19 | * Socket.IO version
|
20 | *
|
21 | * @api public
|
22 | */
|
23 |
|
24 | io.version = '0.7.3';
|
25 |
|
26 | /**
|
27 | * Protocol implemented.
|
28 | *
|
29 | * @api public
|
30 | */
|
31 |
|
32 | io.protocol = 1;
|
33 |
|
34 | /**
|
35 | * Available transports, these will be populated with the available transports
|
36 | *
|
37 | * @api public
|
38 | */
|
39 |
|
40 | io.transports = [];
|
41 |
|
42 | /**
|
43 | * Keep track of jsonp callbacks.
|
44 | *
|
45 | * @api private
|
46 | */
|
47 |
|
48 | io.j = [];
|
49 |
|
50 | /**
|
51 | * Keep track of our io.Sockets
|
52 | *
|
53 | * @api private
|
54 | */
|
55 | io.sockets = {};
|
56 |
|
57 | // if node
|
58 |
|
59 | /**
|
60 | * Expose constructors if in Node
|
61 | */
|
62 |
|
63 | if ('object' === typeof module && 'function' === typeof require) {
|
64 |
|
65 | /**
|
66 | * Expose utils
|
67 | *
|
68 | * @api private
|
69 | */
|
70 |
|
71 | io.util = require('./util').util;
|
72 |
|
73 | /**
|
74 | * Expose JSON.
|
75 | *
|
76 | * @api private
|
77 | */
|
78 |
|
79 | io.JSON = require('./json').JSON;
|
80 |
|
81 | /**
|
82 | * Expose parser.
|
83 | *
|
84 | * @api private
|
85 | */
|
86 |
|
87 | io.parser = require('./parser').parser;
|
88 |
|
89 | /**
|
90 | * Expose EventEmitter
|
91 | *
|
92 | * @api private
|
93 | */
|
94 |
|
95 | io.EventEmitter = process.EventEmitter;
|
96 |
|
97 | /**
|
98 | * Expose Transport
|
99 | *
|
100 | * @api public
|
101 | */
|
102 |
|
103 | io.Transport = require('./transport').Transport;
|
104 |
|
105 | /**
|
106 | * Expose all transports
|
107 | */
|
108 |
|
109 | io.transports.forEach(function (t) {
|
110 | //io.Transport[t] = require('./transports/node/' + t);
|
111 | });
|
112 |
|
113 | /**
|
114 | * Expose Socket
|
115 | *
|
116 | * @api public
|
117 | */
|
118 |
|
119 | io.Socket = require('./socket').Socket;
|
120 |
|
121 | /**
|
122 | * Location of `dist/` directory.
|
123 | *
|
124 | * @api private
|
125 | */
|
126 |
|
127 | io.dist = __dirname + '/../dist';
|
128 |
|
129 | /**
|
130 | * Expose our build system which can generate
|
131 | * socket.io files on the fly with different transports
|
132 | *
|
133 | * @api private
|
134 | */
|
135 |
|
136 | io.builder = require('../bin/builder');
|
137 |
|
138 | }
|
139 | // end node
|
140 |
|
141 | /**
|
142 | * Manages connections to hosts.
|
143 | *
|
144 | * @param {String} uri
|
145 | * @Param {Boolean} force creation of new socket (defaults to false)
|
146 | * @api public
|
147 | */
|
148 |
|
149 | io.connect = function (host, details) {
|
150 | var uri = io.util.parseUri(host)
|
151 | , uuri
|
152 | , socket;
|
153 |
|
154 | if ('undefined' != typeof document) {
|
155 | uri.host = uri.host || document.domain;
|
156 | uri.port = uri.port || document.location.port;
|
157 | }
|
158 |
|
159 | uuri = io.util.uniqueUri(uri);
|
160 |
|
161 | var options = {
|
162 | host: uri.host
|
163 | , secure: uri.protocol == 'https'
|
164 | , port: uri.port || 80
|
165 | };
|
166 | io.util.merge(options, details);
|
167 |
|
168 | if (options['force new connection'] || !io.sockets[uuri]) {
|
169 | socket = new io.Socket(options);
|
170 | }
|
171 |
|
172 | if (!options['force new connection'] && socket) {
|
173 | io.sockets[uuri] = socket;
|
174 | }
|
175 |
|
176 | socket = socket || io.sockets[uuri];
|
177 |
|
178 | // if path is different from '' or /
|
179 | return socket.of(uri.path.length > 1 ? uri.path : '');
|
180 | };
|
181 |
|
182 | })('object' === typeof module ? module.exports : (window.io = {}));
|