Page MenuHomeSealhub

bin_node_modules_socket.io_lib_socket.js.html
No OneTemporary

Authored By
Unknown
Size
25 KB
Referenced Files
None
Subscribers
None

bin_node_modules_socket.io_lib_socket.js.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>bin/node_modules/socket.io/lib/socket.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/lib/socket.js</h1>
<div class="file">
<pre class="code prettyprint linenums">
/**
* Module dependencies.
*/
var Emitter = require(&#x27;events&#x27;).EventEmitter;
var parser = require(&#x27;socket.io-parser&#x27;);
var url = require(&#x27;url&#x27;);
var debug = require(&#x27;debug&#x27;)(&#x27;socket.io:socket&#x27;);
var hasBin = require(&#x27;has-binary-data&#x27;);
/**
* Module exports.
*/
module.exports = exports = Socket;
/**
* Blacklisted events.
*
* @api public
*/
exports.events = [
&#x27;error&#x27;,
&#x27;connect&#x27;,
&#x27;disconnect&#x27;,
&#x27;newListener&#x27;,
&#x27;removeListener&#x27;
];
/**
* Flags.
*
* @api private
*/
var flags = [
&#x27;json&#x27;,
&#x27;volatile&#x27;,
&#x27;broadcast&#x27;
];
/**
* &#x60;EventEmitter#emit&#x60; reference.
*/
var emit = Emitter.prototype.emit;
/**
* Interface to a &#x60;Client&#x60; for a given &#x60;Namespace&#x60;.
*
* @param {Namespace} nsp
* @param {Client} client
* @api public
*/
function Socket(nsp, client){
this.nsp = nsp;
this.server = nsp.server;
this.adapter = this.nsp.adapter;
this.id = client.id;
this.request = client.request;
this.client = client;
this.conn = client.conn;
this.rooms = [];
this.acks = {};
this.connected = true;
this.disconnected = false;
this.handshake = this.buildHandshake();
}
/**
* Inherits from &#x60;EventEmitter&#x60;.
*/
Socket.prototype.__proto__ = Emitter.prototype;
/**
* Apply flags from &#x60;Socket&#x60;.
*/
flags.forEach(function(flag){
Socket.prototype.__defineGetter__(flag, function(){
this.flags = this.flags || {};
this.flags[flag] = true;
return this;
});
});
/**
* &#x60;request&#x60; engine.io shorcut.
*
* @api public
*/
Socket.prototype.__defineGetter__(&#x27;request&#x27;, function(){
return this.conn.request;
});
/**
* Builds the &#x60;handshake&#x60; BC object
*
* @api private
*/
Socket.prototype.buildHandshake = function(){
return {
headers: this.request.headers,
time: (new Date) + &#x27;&#x27;,
address: this.conn.remoteAddress,
xdomain: !!this.request.headers.origin,
secure: !!this.request.connection.encrypted,
issued: +(new Date),
url: this.request.url,
query: url.parse(this.request.url, true).query || {}
};
};
/**
* Emits to this client.
*
* @return {Socket} self
* @api public
*/
Socket.prototype.emit = function(ev){
if (~exports.events.indexOf(ev)) {
emit.apply(this, arguments);
} else {
var args = Array.prototype.slice.call(arguments);
var packet = {};
packet.type = hasBin(args) ? parser.BINARY_EVENT : parser.EVENT;
packet.data = args;
// access last argument to see if it&#x27;s an ACK callback
if (&#x27;function&#x27; == typeof args[args.length - 1]) {
if (this._rooms || (this.flags &amp;&amp; this.flags.broadcast)) {
throw new Error(&#x27;Callbacks are not supported when broadcasting&#x27;);
}
debug(&#x27;emitting packet with ack id %d&#x27;, this.nsp.ids);
this.acks[this.nsp.ids] = args.pop();
packet.id = this.nsp.ids++;
}
if (this._rooms || (this.flags &amp;&amp; this.flags.broadcast)) {
this.adapter.broadcast(packet, {
except: [this.id],
rooms: this._rooms,
flags: this.flags
});
} else {
// dispatch packet
this.packet(packet);
}
// reset flags
delete this._rooms;
delete this.flags;
}
return this;
};
/**
* Targets a room when broadcasting.
*
* @param {String} name
* @return {Socket} self
* @api public
*/
Socket.prototype.to =
Socket.prototype.in = function(name){
this._rooms = this._rooms || [];
if (!~this._rooms.indexOf(name)) this._rooms.push(name);
return this;
};
/**
* Sends a &#x60;message&#x60; event.
*
* @return {Socket} self
* @api public
*/
Socket.prototype.send =
Socket.prototype.write = function(){
var args = Array.prototype.slice.call(arguments);
args.unshift(&#x27;message&#x27;);
this.emit.apply(this, args);
return this;
};
/**
* Writes a packet.
*
* @param {Object} packet object
* @api private
*/
Socket.prototype.packet = function(packet, preEncoded){
packet.nsp = this.nsp.name;
var volatile = this.flags &amp;&amp; this.flags.volatile;
this.client.packet(packet, preEncoded, volatile);
};
/**
* Joins a room.
*
* @param {String} room
* @param {Function} optional, callback
* @return {Socket} self
* @api private
*/
Socket.prototype.join = function(room, fn){
debug(&#x27;joining room %s&#x27;, room);
var self = this;
if (~this.rooms.indexOf(room)) return this;
this.adapter.add(this.id, room, function(err){
if (err) return fn &amp;&amp; fn(err);
debug(&#x27;joined room %s&#x27;, room);
self.rooms.push(room);
fn &amp;&amp; fn(null);
});
return this;
};
/**
* Leaves a room.
*
* @param {String} room
* @param {Function} optional, callback
* @return {Socket} self
* @api private
*/
Socket.prototype.leave = function(room, fn){
debug(&#x27;leave room %s&#x27;, room);
var self = this;
this.adapter.del(this.id, room, function(err){
if (err) return fn &amp;&amp; fn(err);
debug(&#x27;left room %s&#x27;, room);
self.rooms.splice(self.rooms.indexOf(room), 1);
fn &amp;&amp; fn(null);
});
return this;
};
/**
* Leave all rooms.
*
* @api private
*/
Socket.prototype.leaveAll = function(){
this.adapter.delAll(this.id);
this.rooms = [];
};
/**
* Called by &#x60;Namespace&#x60; upon succesful
* middleware execution (ie: authorization).
*
* @api private
*/
Socket.prototype.onconnect = function(){
debug(&#x27;socket connected - writing packet&#x27;);
this.join(this.id);
this.packet({ type: parser.CONNECT });
this.nsp.connected[this.id] = this;
};
/**
* Called with each packet. Called by &#x60;Client&#x60;.
*
* @param {Object} packet
* @api private
*/
Socket.prototype.onpacket = function(packet){
debug(&#x27;got packet %j&#x27;, packet);
switch (packet.type) {
case parser.EVENT:
this.onevent(packet);
break;
case parser.BINARY_EVENT:
this.onevent(packet);
break;
case parser.ACK:
this.onack(packet);
break;
case parser.BINARY_ACK:
this.onack(packet);
break;
case parser.DISCONNECT:
this.ondisconnect();
break;
case parser.ERROR:
this.emit(&#x27;error&#x27;, packet.data);
}
};
/**
* Called upon event packet.
*
* @param {Object} packet object
* @api private
*/
Socket.prototype.onevent = function(packet){
var args = packet.data || [];
debug(&#x27;emitting event %j&#x27;, args);
if (null != packet.id) {
debug(&#x27;attaching ack callback to event&#x27;);
args.push(this.ack(packet.id));
}
emit.apply(this, args);
};
/**
* Produces an ack callback to emit with an event.
*
* @param {Number} packet id
* @api private
*/
Socket.prototype.ack = function(id){
var self = this;
var sent = false;
return function(){
// prevent double callbacks
if (sent) return;
var args = Array.prototype.slice.call(arguments);
debug(&#x27;sending ack %j&#x27;, args);
var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
self.packet({
id: id,
type: type,
data: args
});
};
};
/**
* Called upon ack packet.
*
* @api private
*/
Socket.prototype.onack = function(packet){
var ack = this.acks[packet.id];
if (&#x27;function&#x27; == typeof ack) {
debug(&#x27;calling ack %s with %j&#x27;, packet.id, packet.data);
ack.apply(this, packet.data);
delete this.acks[packet.id];
} else {
debug(&#x27;bad ack %s&#x27;, packet.id);
}
};
/**
* Called upon client disconnect packet.
*
* @api private
*/
Socket.prototype.ondisconnect = function(){
debug(&#x27;got disconnect packet&#x27;);
this.onclose(&#x27;client namespace disconnect&#x27;);
};
/**
* Called upon closing. Called by &#x60;Client&#x60;.
*
* @param {String} reason
* @api private
*/
Socket.prototype.onclose = function(reason){
if (!this.connected) return this;
debug(&#x27;closing socket - reason %s&#x27;, reason);
this.leaveAll();
this.nsp.remove(this);
this.client.remove(this);
this.connected = false;
this.disconnected = true;
delete this.nsp.connected[this.id];
this.emit(&#x27;disconnect&#x27;, reason);
};
/**
* Produces an &#x60;error&#x60; packet.
*
* @param {Object} error object
* @api private
*/
Socket.prototype.error = function(err){
this.packet({ type: parser.ERROR, data: err });
};
/**
* Disconnects this client.
*
* @param {Boolean} if &#x60;true&#x60;, closes the underlying connection
* @return {Socket} self
* @api public
*/
Socket.prototype.disconnect = function(close){
if (!this.connected) return this;
if (close) {
this.client.disconnect();
} else {
this.packet({ type: parser.DISCONNECT });
this.onclose(&#x27;server namespace disconnect&#x27;);
}
return this;
};
</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, 19:09 (21 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1227240
Default Alt Text
bin_node_modules_socket.io_lib_socket.js.html (25 KB)

Event Timeline