]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - apps/tidep0084.git/blob - example/iot-gateway/node_modules/engine.io/lib/transport.js
Updated to use the latest TI 15.4-Stack v2.1.0 from the SimpleLink CC13x0 SDK v1.30.
[apps/tidep0084.git] / example / iot-gateway / node_modules / engine.io / lib / transport.js
2 /**
3  * Module dependencies.
4  */
6 var EventEmitter = require('events').EventEmitter
7   , parser = require('engine.io-parser')
8   , debug = require('debug')('engine:transport');
10 /**
11  * Expose the constructor.
12  */
14 module.exports = Transport;
16 /**
17  * Noop function.
18  *
19  * @api private
20  */
22 function noop () {}
24 /**
25  * Transport constructor.
26  *
27  * @param {http.ServerRequest} request
28  * @api public
29  */
31 function Transport (req) {
32   this.readyState = 'open';
33   this.discarded = false;
34 }
36 /**
37  * Inherits from EventEmitter.
38  */
40 Transport.prototype.__proto__ = EventEmitter.prototype;
42 /**
43  * Flags the transport as discarded.
44  *
45  * @api private
46  */
48 Transport.prototype.discard = function () {
49   this.discarded = true;
50 };
52 /**
53  * Called with an incoming HTTP request.
54  *
55  * @param {http.ServerRequest} request
56  * @api private
57  */
59 Transport.prototype.onRequest = function (req) {
60   debug('setting request');
61   this.req = req;
62 };
64 /**
65  * Closes the transport.
66  *
67  * @api private
68  */
70 Transport.prototype.close = function (fn) {
71   if ('closed' == this.readyState || 'closing' == this.readyState) return;
73   this.readyState = 'closing';
74   this.doClose(fn || noop);
75 };
77 /**
78  * Called with a transport error.
79  *
80  * @param {String} message error
81  * @param {Object} error description
82  * @api private
83  */
85 Transport.prototype.onError = function (msg, desc) {
86   if (this.listeners('error').length) {
87     var err = new Error(msg);
88     err.type = 'TransportError';
89     err.description = desc;
90     this.emit('error', err);
91   } else {
92     debug('ignored transport error %s (%s)', msg, desc);
93   }
94 };
96 /**
97  * Called with parsed out a packets from the data stream.
98  *
99  * @param {Object} packet
100  * @api private
101  */
103 Transport.prototype.onPacket = function (packet) {
104   this.emit('packet', packet);
105 };
107 /**
108  * Called with the encoded packet data.
109  *
110  * @param {String} data
111  * @api private
112  */
114 Transport.prototype.onData = function (data) {
115   this.onPacket(parser.decodePacket(data));
116 };
118 /**
119  * Called upon transport close.
120  *
121  * @api private
122  */
124 Transport.prototype.onClose = function () {
125   this.readyState = 'closed';
126   this.emit('close');
127 };