
/**
 * Module dependencies.
 */

var Queue = require('./queue');

/**
 * Expose `PushSocket`.
 */

module.exports = PushSocket;

/**
 * Initialzie a new `PushSocket`.
 *
 * @api private
 */

function PushSocket() {
  Queue.call(this);
  this.n = 0;
  this.on('connection', this.flush.bind(this));
}

/**
 * Inherits from `Queue.prototype`.
 */

PushSocket.prototype.__proto__ = Queue.prototype;

PushSocket.prototype.sendToPeers = function(msg){
  var socks = this.socks
    , len = socks.length
    , sock = socks[this.n++ % len]
    , codec = this.parser.codec;

  if (sock) {
    sock.write(this.parser.pack(codec.encode(msg), codec.id));
  } else {
    this.buf.push(msg);
  }
};

PushSocket.prototype.sendToPeer = function(msg){
  var sock = this.sock
    , codec = this.parser.codec;

  if (sock) {
    sock.write(this.parser.pack(codec.encode(msg), codec.id));
  } else {
    this.buf.push(msg);
  }
};

/**
 * Send `msg` round-robin to established peers.
 *
 * @param {Mixed} msg
 * @api public
 */

PushSocket.prototype.send = function(msg){
  if ('server' == this.type) this.sendToPeers(msg);
  else this.sendToPeer(msg);
};
@@ -390,16 +390,106 @@
 otype;%0A%0A
+/**%0A * Send %60msg%60 to all established peers.%0A *%0A * @param %7BMixed%7D msg%0A * @api private%0A */%0A%0A
 PushSock
@@ -769,16 +769,101 @@
   %7D%0A%7D;%0A%0A
+/**%0A * Send %60msg%60 to established peer.%0A *%0A * @param %7BMixed%7D msg%0A * @api private%0A */%0A%0A
 PushSock

add docs