1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function (exports) {
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var io = exports;
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | io.version = '0.7.9';
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | io.protocol = 1;
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | io.transports = [];
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | io.j = [];
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 | io.sockets = {};
|
56 |
|
57 |
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 | if ('object' === typeof module && 'function' === typeof require) {
|
64 |
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | io.util = require('./util').util;
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | io.JSON = require('./json').JSON;
|
80 |
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | io.parser = require('./parser').parser;
|
88 |
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | io.EventEmitter = process.EventEmitter;
|
96 |
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | io.SocketNamespace = require('./namespace').SocketNamespace;
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | io.Transport = require('./transport').Transport;
|
112 |
|
113 | |
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | io.transports = ['websocket', 'xhr-polling'];
|
120 |
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | io.Transport.XHR = require('./transports/xhr').XHR;
|
128 |
|
129 | io.transports.forEach(function (t) {
|
130 | io.Transport[t] = require('./transports/' + t)[t];
|
131 | });
|
132 |
|
133 | |
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | io.Socket = require('./socket').Socket;
|
140 |
|
141 | |
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | io.dist = __dirname + '/../dist';
|
148 |
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | io.builder = require('../bin/builder');
|
157 |
|
158 | }
|
159 |
|
160 |
|
161 | |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | io.connect = function (host, details) {
|
170 | var uri = io.util.parseUri(host)
|
171 | , uuri
|
172 | , socket;
|
173 |
|
174 | if ('undefined' != typeof document) {
|
175 | uri.protocol = uri.protocol || document.location.protocol.slice(0, -1);
|
176 | uri.host = uri.host || document.domain;
|
177 | uri.port = uri.port || document.location.port;
|
178 | }
|
179 |
|
180 | uuri = io.util.uniqueUri(uri);
|
181 |
|
182 | var options = {
|
183 | host: uri.host
|
184 | , secure: 'https' == uri.protocol
|
185 | , port: uri.port || ('https' == uri.protocol ? 443 : 80)
|
186 | , query: uri.query || ''
|
187 | };
|
188 |
|
189 | io.util.merge(options, details);
|
190 |
|
191 | if (options['force new connection'] || !io.sockets[uuri]) {
|
192 | socket = new io.Socket(options);
|
193 | }
|
194 |
|
195 | if (!options['force new connection'] && socket) {
|
196 | io.sockets[uuri] = socket;
|
197 | }
|
198 |
|
199 | socket = socket || io.sockets[uuri];
|
200 |
|
201 |
|
202 | return socket.of(uri.path.length > 1 ? uri.path : '');
|
203 | };
|
204 |
|
205 | })('object' === typeof module ? module.exports : (window.io = {}));
|