node_modules/sharedb/lib/agent.js
/**
 * Agent deserializes the wire protocol messages received from the stream and
 * calls the corresponding functions on its Agent. It uses the return values
 * to send responses back. Agent also handles piping the operation streams
 * provided by a Agent.
 *
 * @param {Backend} backend
 * @param {Duplex} stream connection to a client
 */
Agent deserializes the wire protocol messages received from the stream and
calls the corresponding functions on its Agent. It uses the return values
to send responses back. Agent also handles piping the operation streams
provided by a Agent.

@param {Backend} backend
@param {Duplex} stream connection to a client
Agent deserializes the wire protocol messages received from the stream and calls the corresponding functions on its Agent . It uses the return values to send responses back . Agent also handles piping the operation streams provided by a Agent . @param { Backend } backend @param { Duplex } stream connection to a client
function Agent(backend, stream) {
  this.backend = backend;
  this.stream = stream;
  this.clientId = hat();
  this.connectTime = Date.now();
  this.subscribedDocs = {};
  this.subscribedQueries = {};
  this.closed = false;
  this.custom = {};
  this.send({
    a: 'init',
    protocol: 1,
    id: this.clientId,
    type: types.defaultType.uri
  });
}
function Agent ( backend , stream ) { this . backend = backend ; this . stream = stream ; this . clientId = hat ( ) ; this . connectTime = Date . now ( ) ; this . subscribedDocs = { } ; this . subscribedQueries = { } ; this . closed = false ; this . custom = { } ; this . send ( { a : 'init' , protocol : 1 , id : this . clientId , type : types . defaultType . uri } ) ; }
Agent deserializes the wire protocol messages received from the stream and
 calls the corresponding functions on its Agent.
Agent deserializes the wire protocol messages received from the stream and calls the corresponding functions on its Agent .
// We need to track which documents are subscribed by the client. This is a // map of collection -> id -> stream // Map from queryId -> emitter // We need to track this manually to make sure we don't reply to messages // after the stream was closed. // For custom use in middleware. The agent is a convenient place to cache // session state in memory. It is in memory only as long as the session is // active, and it is passed to each middleware call // Initialize the remote client by sending it its agent Id.