Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io-client / components / learnboost-engine.io-client / lib / transport.js
1
2 /**
3  * Module dependencies.
4  */
5
6 var util = require('./util')
7   , parser = require('./parser')
8   , Emitter = require('./emitter');
9
10 /**
11  * Module exports.
12  */
13
14 module.exports = Transport;
15
16 /**
17  * Transport abstract constructor.
18  *
19  * @param {Object} options.
20  * @api private
21  */
22
23 function Transport (opts) {
24   this.path = opts.path;
25   this.host = opts.host;
26   this.port = opts.port;
27   this.secure = opts.secure;
28   this.query = opts.query;
29   this.timestampParam = opts.timestampParam;
30   this.timestampRequests = opts.timestampRequests;
31   this.readyState = '';
32 };
33
34 /**
35   * Mix in `Emitter`.
36  */
37
38 Emitter(Transport.prototype);
39
40 /**
41  * Emits an error.
42  *
43  * @param {String} str
44  * @return {Transport} for chaining
45  * @api public
46  */
47
48 Transport.prototype.onError = function (msg, desc) {
49   var err = new Error(msg);
50   err.type = 'TransportError';
51   err.description = desc;
52   this.emit('error', err);
53   return this;
54 };
55
56 /**
57  * Opens the transport.
58  *
59  * @api public
60  */
61
62 Transport.prototype.open = function () {
63   if ('closed' == this.readyState || '' == this.readyState) {
64     this.readyState = 'opening';
65     this.doOpen();
66   }
67
68   return this;
69 };
70
71 /**
72  * Closes the transport.
73  *
74  * @api private
75  */
76
77 Transport.prototype.close = function () {
78   if ('opening' == this.readyState || 'open' == this.readyState) {
79     this.doClose();
80     this.onClose();
81   }
82
83   return this;
84 };
85
86 /**
87  * Sends multiple packets.
88  *
89  * @param {Array} packets
90  * @api private
91  */
92
93 Transport.prototype.send = function(packets){
94   if ('open' == this.readyState) {
95     this.write(packets);
96   } else {
97     throw new Error('Transport not open');
98   }
99 };
100
101 /**
102  * Called upon open
103  *
104  * @api private
105  */
106
107 Transport.prototype.onOpen = function () {
108   this.readyState = 'open';
109   this.writable = true;
110   this.emit('open');
111 };
112
113 /**
114  * Called with data.
115  *
116  * @param {String} data
117  * @api private
118  */
119
120 Transport.prototype.onData = function (data) {
121   this.onPacket(parser.decodePacket(data));
122 };
123
124 /**
125  * Called with a decoded packet.
126  */
127
128 Transport.prototype.onPacket = function (packet) {
129   this.emit('packet', packet);
130 };
131
132 /**
133  * Called upon close.
134  *
135  * @api private
136  */
137
138 Transport.prototype.onClose = function () {
139   this.readyState = 'closed';
140   this.emit('close');
141 };