Page MenuHomeSealhub

bin_node_modules_socket.io-client_lib_manager.js.html
No OneTemporary

Authored By
Unknown
Size
28 KB
Referenced Files
None
Subscribers
None

bin_node_modules_socket.io-client_lib_manager.js.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bin/node_modules/socket.io-client/lib/manager.js - Prometheus Framework</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/3.9.1/build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="http://yui.yahooapis.com/combo?3.9.1/build/yui/yui-min.js"></script>
</head>
<body class="yui3-skin-sam">
<div id="doc">
<div id="hd" class="yui3-g header">
<div class="yui3-u-3-4">
<h1><img src="../assets/css/logo.png" title="Prometheus Framework"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 0.1</em>
</div>
</div>
<div id="bd" class="yui3-g">
<div class="yui3-u-1-4">
<div id="docs-sidebar" class="sidebar apidocs">
<div id="api-list">
<h2 class="off-left">APIs</h2>
<div id="api-tabview" class="tabview">
<ul class="tabs">
<li><a href="#api-classes">Classes</a></li>
<li><a href="#api-modules">Modules</a></li>
</ul>
<div id="api-tabview-filter">
<input type="search" id="api-filter" placeholder="Type to filter APIs">
</div>
<div id="api-tabview-panel">
<ul id="api-classes" class="apis classes">
<li><a href="../classes/Represents a
Replicaset Configuration.html">Represents a
Replicaset Configuration</a></li>
<li><a href="../classes/Represents a BatchWriteResult.html">Represents a BatchWriteResult</a></li>
<li><a href="../classes/Represents a Collection.html">Represents a Collection</a></li>
<li><a href="../classes/Represents a Cursor..html">Represents a Cursor.</a></li>
<li><a href="../classes/Represents a CursorStream..html">Represents a CursorStream.</a></li>
<li><a href="../classes/Represents a Db.html">Represents a Db</a></li>
<li><a href="../classes/Represents a GridFS File Stream..html">Represents a GridFS File Stream.</a></li>
<li><a href="../classes/.html"></a></li>
<li><a href="../classes/Represents a MongoClient.html">Represents a MongoClient</a></li>
<li><a href="../classes/Represents a Mongos connection with failover to backup proxies.html">Represents a Mongos connection with failover to backup proxies</a></li>
<li><a href="../classes/Represents a OrderedBulkOperation.html">Represents a OrderedBulkOperation</a></li>
<li><a href="../classes/Represents a Read Preference..html">Represents a Read Preference.</a></li>
<li><a href="../classes/Represents a Server connection..html">Represents a Server connection.</a></li>
<li><a href="../classes/Represents a UnorderedBulkOperation.html">Represents a UnorderedBulkOperation</a></li>
<li><a href="../classes/Represents the Admin methods of MongoDB..html">Represents the Admin methods of MongoDB.</a></li>
<li><a href="../classes/Represents the Grid..html">Represents the Grid.</a></li>
<li><a href="../classes/Represents the GridStore..html">Represents the GridStore.</a></li>
</ul>
<ul id="api-modules" class="apis modules">
<li><a href="../modules/association.html">association</a></li>
<li><a href="../modules/database-accessor.html">database-accessor</a></li>
<li><a href="../modules/field-type-manager.html">field-type-manager</a></li>
<li><a href="../modules/resource-type-manager.html">resource-type-manager</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="yui3-u-3-4">
<div id="api-options">
Show:
<label for="api-show-inherited">
<input type="checkbox" id="api-show-inherited" checked>
Inherited
</label>
<label for="api-show-protected">
<input type="checkbox" id="api-show-protected">
Protected
</label>
<label for="api-show-private">
<input type="checkbox" id="api-show-private">
Private
</label>
<label for="api-show-deprecated">
<input type="checkbox" id="api-show-deprecated">
Deprecated
</label>
</div>
<div class="apidocs">
<div id="docs-main">
<div class="content">
<h1 class="file-heading">File: bin/node_modules/socket.io-client/lib/manager.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
/**
* Module dependencies.
*/
var url = require(&#x27;./url&#x27;);
var eio = require(&#x27;engine.io-client&#x27;);
var Socket = require(&#x27;./socket&#x27;);
var Emitter = require(&#x27;component-emitter&#x27;);
var parser = require(&#x27;socket.io-parser&#x27;);
var on = require(&#x27;./on&#x27;);
var bind = require(&#x27;component-bind&#x27;);
var object = require(&#x27;object-component&#x27;);
var debug = require(&#x27;debug&#x27;)(&#x27;socket.io-client:manager&#x27;);
var indexOf = require(&#x27;indexof&#x27;);
/**
* Module exports
*/
module.exports = Manager;
/**
* &#x60;Manager&#x60; constructor.
*
* @param {String} engine instance or engine uri/opts
* @param {Object} options
* @api public
*/
function Manager(uri, opts){
if (!(this instanceof Manager)) return new Manager(uri, opts);
if (uri &amp;&amp; (&#x27;object&#x27; == typeof uri)) {
opts = uri;
uri = undefined;
}
opts = opts || {};
opts.path = opts.path || &#x27;/socket.io&#x27;;
this.nsps = {};
this.subs = [];
this.opts = opts;
this.reconnection(opts.reconnection !== false);
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
this.reconnectionDelay(opts.reconnectionDelay || 1000);
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
this.timeout(null == opts.timeout ? 20000 : opts.timeout);
this.readyState = &#x27;closed&#x27;;
this.uri = uri;
this.connected = [];
this.attempts = 0;
this.encoding = false;
this.packetBuffer = [];
this.encoder = new parser.Encoder();
this.decoder = new parser.Decoder();
this.autoConnect = opts.autoConnect !== false;
if (this.autoConnect) this.open();
}
/**
* Propagate given event to sockets and emit on &#x60;this&#x60;
*
* @api private
*/
Manager.prototype.emitAll = function() {
this.emit.apply(this, arguments);
for (var nsp in this.nsps) {
this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
}
};
/**
* Mix in &#x60;Emitter&#x60;.
*/
Emitter(Manager.prototype);
/**
* Sets the &#x60;reconnection&#x60; config.
*
* @param {Boolean} true/false if it should automatically reconnect
* @return {Manager} self or value
* @api public
*/
Manager.prototype.reconnection = function(v){
if (!arguments.length) return this._reconnection;
this._reconnection = !!v;
return this;
};
/**
* Sets the reconnection attempts config.
*
* @param {Number} max reconnection attempts before giving up
* @return {Manager} self or value
* @api public
*/
Manager.prototype.reconnectionAttempts = function(v){
if (!arguments.length) return this._reconnectionAttempts;
this._reconnectionAttempts = v;
return this;
};
/**
* Sets the delay between reconnections.
*
* @param {Number} delay
* @return {Manager} self or value
* @api public
*/
Manager.prototype.reconnectionDelay = function(v){
if (!arguments.length) return this._reconnectionDelay;
this._reconnectionDelay = v;
return this;
};
/**
* Sets the maximum delay between reconnections.
*
* @param {Number} delay
* @return {Manager} self or value
* @api public
*/
Manager.prototype.reconnectionDelayMax = function(v){
if (!arguments.length) return this._reconnectionDelayMax;
this._reconnectionDelayMax = v;
return this;
};
/**
* Sets the connection timeout. &#x60;false&#x60; to disable
*
* @return {Manager} self or value
* @api public
*/
Manager.prototype.timeout = function(v){
if (!arguments.length) return this._timeout;
this._timeout = v;
return this;
};
/**
* Starts trying to reconnect if reconnection is enabled and we have not
* started reconnecting yet
*
* @api private
*/
Manager.prototype.maybeReconnectOnOpen = function() {
// Only try to reconnect if it&#x27;s the first time we&#x27;re connecting
if (!this.openReconnect &amp;&amp; !this.reconnecting &amp;&amp; this._reconnection &amp;&amp; this.attempts === 0) {
// keeps reconnection from firing twice for the same reconnection loop
this.openReconnect = true;
this.reconnect();
}
};
/**
* Sets the current transport &#x60;socket&#x60;.
*
* @param {Function} optional, callback
* @return {Manager} self
* @api public
*/
Manager.prototype.open =
Manager.prototype.connect = function(fn){
debug(&#x27;readyState %s&#x27;, this.readyState);
if (~this.readyState.indexOf(&#x27;open&#x27;)) return this;
debug(&#x27;opening %s&#x27;, this.uri);
this.engine = eio(this.uri, this.opts);
var socket = this.engine;
var self = this;
this.readyState = &#x27;opening&#x27;;
this.skipReconnect = false;
// emit &#x60;open&#x60;
var openSub = on(socket, &#x27;open&#x27;, function() {
self.onopen();
fn &amp;&amp; fn();
});
// emit &#x60;connect_error&#x60;
var errorSub = on(socket, &#x27;error&#x27;, function(data){
debug(&#x27;connect_error&#x27;);
self.cleanup();
self.readyState = &#x27;closed&#x27;;
self.emitAll(&#x27;connect_error&#x27;, data);
if (fn) {
var err = new Error(&#x27;Connection error&#x27;);
err.data = data;
fn(err);
}
self.maybeReconnectOnOpen();
});
// emit &#x60;connect_timeout&#x60;
if (false !== this._timeout) {
var timeout = this._timeout;
debug(&#x27;connect attempt will timeout after %d&#x27;, timeout);
// set timer
var timer = setTimeout(function(){
debug(&#x27;connect attempt timed out after %d&#x27;, timeout);
openSub.destroy();
socket.close();
socket.emit(&#x27;error&#x27;, &#x27;timeout&#x27;);
self.emitAll(&#x27;connect_timeout&#x27;, timeout);
}, timeout);
this.subs.push({
destroy: function(){
clearTimeout(timer);
}
});
}
this.subs.push(openSub);
this.subs.push(errorSub);
return this;
};
/**
* Called upon transport open.
*
* @api private
*/
Manager.prototype.onopen = function(){
debug(&#x27;open&#x27;);
// clear old subs
this.cleanup();
// mark as open
this.readyState = &#x27;open&#x27;;
this.emit(&#x27;open&#x27;);
// add new subs
var socket = this.engine;
this.subs.push(on(socket, &#x27;data&#x27;, bind(this, &#x27;ondata&#x27;)));
this.subs.push(on(this.decoder, &#x27;decoded&#x27;, bind(this, &#x27;ondecoded&#x27;)));
this.subs.push(on(socket, &#x27;error&#x27;, bind(this, &#x27;onerror&#x27;)));
this.subs.push(on(socket, &#x27;close&#x27;, bind(this, &#x27;onclose&#x27;)));
};
/**
* Called with data.
*
* @api private
*/
Manager.prototype.ondata = function(data){
this.decoder.add(data);
};
/**
* Called when parser fully decodes a packet.
*
* @api private
*/
Manager.prototype.ondecoded = function(packet) {
this.emit(&#x27;packet&#x27;, packet);
};
/**
* Called upon socket error.
*
* @api private
*/
Manager.prototype.onerror = function(err){
debug(&#x27;error&#x27;, err);
this.emitAll(&#x27;error&#x27;, err);
};
/**
* Creates a new socket for the given &#x60;nsp&#x60;.
*
* @return {Socket}
* @api public
*/
Manager.prototype.socket = function(nsp){
var socket = this.nsps[nsp];
if (!socket) {
socket = new Socket(this, nsp);
this.nsps[nsp] = socket;
var self = this;
socket.on(&#x27;connect&#x27;, function(){
if (!~indexOf(self.connected, socket)) {
self.connected.push(socket);
}
});
}
return socket;
};
/**
* Called upon a socket close.
*
* @param {Socket} socket
*/
Manager.prototype.destroy = function(socket){
var index = indexOf(this.connected, socket);
if (~index) this.connected.splice(index, 1);
if (this.connected.length) return;
this.close();
};
/**
* Writes a packet.
*
* @param {Object} packet
* @api private
*/
Manager.prototype.packet = function(packet){
debug(&#x27;writing packet %j&#x27;, packet);
var self = this;
if (!self.encoding) {
// encode, then write to engine with result
self.encoding = true;
this.encoder.encode(packet, function(encodedPackets) {
for (var i = 0; i &lt; encodedPackets.length; i++) {
self.engine.write(encodedPackets[i]);
}
self.encoding = false;
self.processPacketQueue();
});
} else { // add packet to the queue
self.packetBuffer.push(packet);
}
};
/**
* If packet buffer is non-empty, begins encoding the
* next packet in line.
*
* @api private
*/
Manager.prototype.processPacketQueue = function() {
if (this.packetBuffer.length &gt; 0 &amp;&amp; !this.encoding) {
var pack = this.packetBuffer.shift();
this.packet(pack);
}
};
/**
* Clean up transport subscriptions and packet buffer.
*
* @api private
*/
Manager.prototype.cleanup = function(){
var sub;
while (sub = this.subs.shift()) sub.destroy();
this.packetBuffer = [];
this.encoding = false;
this.decoder.destroy();
};
/**
* Close the current socket.
*
* @api private
*/
Manager.prototype.close =
Manager.prototype.disconnect = function(){
this.skipReconnect = true;
this.readyState = &#x27;closed&#x27;;
this.engine &amp;&amp; this.engine.close();
};
/**
* Called upon engine close.
*
* @api private
*/
Manager.prototype.onclose = function(reason){
debug(&#x27;close&#x27;);
this.cleanup();
this.readyState = &#x27;closed&#x27;;
this.emit(&#x27;close&#x27;, reason);
if (this._reconnection &amp;&amp; !this.skipReconnect) {
this.reconnect();
}
};
/**
* Attempt a reconnection.
*
* @api private
*/
Manager.prototype.reconnect = function(){
if (this.reconnecting || this.skipReconnect) return this;
var self = this;
this.attempts++;
if (this.attempts &gt; this._reconnectionAttempts) {
debug(&#x27;reconnect failed&#x27;);
this.emitAll(&#x27;reconnect_failed&#x27;);
this.reconnecting = false;
} else {
var delay = this.attempts * this.reconnectionDelay();
delay = Math.min(delay, this.reconnectionDelayMax());
debug(&#x27;will wait %dms before reconnect attempt&#x27;, delay);
this.reconnecting = true;
var timer = setTimeout(function(){
if (self.skipReconnect) return;
debug(&#x27;attempting reconnect&#x27;);
self.emitAll(&#x27;reconnect_attempt&#x27;, self.attempts);
self.emitAll(&#x27;reconnecting&#x27;, self.attempts);
// check again for the case socket closed in above events
if (self.skipReconnect) return;
self.open(function(err){
if (err) {
debug(&#x27;reconnect attempt error&#x27;);
self.reconnecting = false;
self.reconnect();
self.emitAll(&#x27;reconnect_error&#x27;, err.data);
} else {
debug(&#x27;reconnect success&#x27;);
self.onreconnect();
}
});
}, delay);
this.subs.push({
destroy: function(){
clearTimeout(timer);
}
});
}
};
/**
* Called upon successful reconnect.
*
* @api private
*/
Manager.prototype.onreconnect = function(){
var attempt = this.attempts;
this.attempts = 0;
this.reconnecting = false;
this.emitAll(&#x27;reconnect&#x27;, attempt);
};
</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script src="../assets/js/yui-prettify.js"></script>
<script src="../assets/../api.js"></script>
<script src="../assets/js/api-filter.js"></script>
<script src="../assets/js/api-list.js"></script>
<script src="../assets/js/api-search.js"></script>
<script src="../assets/js/apidocs.js"></script>
</body>
</html>

File Metadata

Mime Type
text/html
Expires
Fri, Nov 27, 16:57 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1223096
Default Alt Text
bin_node_modules_socket.io-client_lib_manager.js.html (28 KB)

Event Timeline