Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / lib / io.js
1
2 /**
3  * socket.io
4  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 (function (exports, global) {
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.9.16';
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 = require('./events').EventEmitter;
96
97     /**
98      * Expose SocketNamespace
99      *
100      * @api private
101      */
102
103      io.SocketNamespace = require('./namespace').SocketNamespace;
104
105     /**
106      * Expose Transport
107      *
108      * @api public
109      */
110
111     io.Transport = require('./transport').Transport;
112
113     /**
114      * Default enabled transports
115      *
116      * @api public
117      */
118
119     io.transports = ['websocket', 'xhr-polling'];
120
121     /**
122      * Expose all transports
123      *
124      * @api public
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      * Expose Socket
135      *
136      * @api public
137      */
138
139     io.Socket = require('./socket').Socket;
140
141     /**
142      * Location of `dist/` directory.
143      *
144      * @api private
145      */
146
147     io.dist = __dirname + '/../dist';
148
149     /**
150      * Expose our build system which can generate
151      * socket.io files on the fly with different transports
152      *
153      * @api private
154      */
155
156     io.builder = require('../bin/builder');
157
158   }
159   // end node
160
161   /**
162    * Manages connections to hosts.
163    *
164    * @param {String} uri
165    * @Param {Boolean} force creation of new socket (defaults to false)
166    * @api public
167    */
168
169   io.connect = function (host, details) {
170     var uri = io.util.parseUri(host)
171       , uuri
172       , socket;
173
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;
179     }
180
181     uuri = io.util.uniqueUri(uri);
182
183     var options = {
184         host: uri.host
185       , secure: 'https' == uri.protocol
186       , port: uri.port || ('https' == uri.protocol ? 443 : 80)
187       , query: uri.query || ''
188     };
189
190     io.util.merge(options, details);
191
192     if (options['force new connection'] || !io.sockets[uuri]) {
193       socket = new io.Socket(options);
194     }
195
196     if (!options['force new connection'] && socket) {
197       io.sockets[uuri] = socket;
198     }
199
200     socket = socket || io.sockets[uuri];
201
202     // if path is different from '' or /
203     return socket.of(uri.path.length > 1 ? uri.path : '');
204   };
205
206 })('object' === typeof module ? module.exports : (this.io = {}), this);