Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / lib / transports / flashsocket.js
1
2 /**
3  * socket.io
4  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 (function (exports, io) {
9
10   /**
11    * Expose constructor.
12    */
13
14   exports.flashsocket = Flashsocket;
15
16   /**
17    * The FlashSocket transport. This is a API wrapper for the HTML5 WebSocket
18    * specification. It uses a .swf file to communicate with the server. If you want
19    * to serve the .swf file from a other server than where the Socket.IO script is
20    * coming from you need to use the insecure version of the .swf. More information
21    * about this can be found on the github page.
22    *
23    * @constructor
24    * @extends {io.Transport.websocket}
25    * @api public
26    */
27
28   function Flashsocket () {
29     io.Transport.websocket.apply(this, arguments);
30   };
31
32   /**
33    * Inherits from Transport.
34    */
35
36   io.util.inherit(Flashsocket, io.Transport.websocket);
37
38   /**
39    * Transport name
40    *
41    * @api public
42    */
43
44   Flashsocket.prototype.name = 'flashsocket';
45
46   /**
47    * Disconnect the established `FlashSocket` connection. This is done by adding a 
48    * new task to the FlashSocket. The rest will be handled off by the `WebSocket` 
49    * transport.
50    *
51    * @returns {Transport}
52    * @api public
53    */
54
55   Flashsocket.prototype.open = function () {
56     var self = this
57       , args = arguments;
58
59     WebSocket.__addTask(function () {
60       io.Transport.websocket.prototype.open.apply(self, args);
61     });
62     return this;
63   };
64   
65   /**
66    * Sends a message to the Socket.IO server. This is done by adding a new
67    * task to the FlashSocket. The rest will be handled off by the `WebSocket` 
68    * transport.
69    *
70    * @returns {Transport}
71    * @api public
72    */
73
74   Flashsocket.prototype.send = function () {
75     var self = this, args = arguments;
76     WebSocket.__addTask(function () {
77       io.Transport.websocket.prototype.send.apply(self, args);
78     });
79     return this;
80   };
81
82   /**
83    * Disconnects the established `FlashSocket` connection.
84    *
85    * @returns {Transport}
86    * @api public
87    */
88
89   Flashsocket.prototype.close = function () {
90     WebSocket.__tasks.length = 0;
91     io.Transport.websocket.prototype.close.call(this);
92     return this;
93   };
94
95   /**
96    * The WebSocket fall back needs to append the flash container to the body
97    * element, so we need to make sure we have access to it. Or defer the call
98    * until we are sure there is a body element.
99    *
100    * @param {Socket} socket The socket instance that needs a transport
101    * @param {Function} fn The callback
102    * @api private
103    */
104
105   Flashsocket.prototype.ready = function (socket, fn) {
106     function init () {
107       var options = socket.options
108         , port = options['flash policy port']
109         , path = [
110               'http' + (options.secure ? 's' : '') + ':/'
111             , options.host + ':' + options.port
112             , options.resource
113             , 'static/flashsocket'
114             , 'WebSocketMain' + (socket.isXDomain() ? 'Insecure' : '') + '.swf'
115           ];
116
117       // Only start downloading the swf file when the checked that this browser
118       // actually supports it
119       if (!Flashsocket.loaded) {
120         if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined') {
121           // Set the correct file based on the XDomain settings
122           WEB_SOCKET_SWF_LOCATION = path.join('/');
123         }
124
125         if (port !== 843) {
126           WebSocket.loadFlashPolicyFile('xmlsocket://' + options.host + ':' + port);
127         }
128
129         WebSocket.__initialize();
130         Flashsocket.loaded = true;
131       }
132
133       fn.call(self);
134     }
135
136     var self = this;
137     if (document.body) return init();
138
139     io.util.load(init);
140   };
141
142   /**
143    * Check if the FlashSocket transport is supported as it requires that the Adobe
144    * Flash Player plug-in version `10.0.0` or greater is installed. And also check if
145    * the polyfill is correctly loaded.
146    *
147    * @returns {Boolean}
148    * @api public
149    */
150
151   Flashsocket.check = function () {
152     if (
153         typeof WebSocket == 'undefined'
154       || !('__initialize' in WebSocket) || !swfobject
155     ) return false;
156
157     return swfobject.getFlashPlayerVersion().major >= 10;
158   };
159
160   /**
161    * Check if the FlashSocket transport can be used as cross domain / cross origin 
162    * transport. Because we can't see which type (secure or insecure) of .swf is used
163    * we will just return true.
164    *
165    * @returns {Boolean}
166    * @api public
167    */
168
169   Flashsocket.xdomainCheck = function () {
170     return true;
171   };
172
173   /**
174    * Disable AUTO_INITIALIZATION
175    */
176
177   if (typeof window != 'undefined') {
178     WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
179   }
180
181   /**
182    * Add the transport to your public io.transports array.
183    *
184    * @api private
185    */
186
187   io.transports.push('flashsocket');
188 })(
189     'undefined' != typeof io ? io.Transport : module.exports
190   , 'undefined' != typeof io ? io : module.parent.exports
191 );