lib/session.js
function Session(identity, connection, options) {
  if (!(this instanceof Session)) {
    return new Session(identity, connection, options);
  }

  assert(identity instanceof Identity, 'Invalid identity supplied');

  if (!(connection instanceof Connection)) {
    options = connection || {};
    options.passive = true;
  }

  this.options = merge(Object.create(Session.DEFAULTS), options);
  this.client = new Client(identity);
  this._identity = identity;

  if (!this.options.passive) {
    this._connection = connection;
    this._connection.open(this._onConnect.bind(this));
  } else {
    this._onConnect();
  }

  if (this.options.subscribe) {
    this.client.on('message', this._onMessage.bind(this)).subscribe();
  }
}
function Session(identity, connection, options) {
  if (!(this instanceof Session)) {
    return new Session(identity, connection, options);
  }

  assert(identity instanceof Identity, 'Invalid identity supplied');

  if (!(connection instanceof Connection)) {
    options = connection || {};
    options.passive = true;
  }

  this.options = merge(Object.create(Session.DEFAULTS), options);
  this.client = new Client(identity);
  this._identity = identity;

  if (!this.options.passive) {
    this._connection = connection;
    this._connection.open(this._onConnect.bind(this));
  } else {
    this._onConnect();
  }

  if (this.options.subscribe) {
    this.client.on('message', this._onMessage.bind(this)).subscribe();
  }
}
function Session ( identity , connection , options ) { if ( ! ( this instanceof Session ) ) { return new Session ( identity , connection , options ) ; } assert ( identity instanceof Identity , 'Invalid identity supplied' ) ; if ( ! ( connection instanceof Connection ) ) { options = connection || { } ; options . passive = true ; } this . options = merge ( Object . create ( Session . DEFAULTS ) , options ) ; this . client = new Client ( identity ) ; this . _identity = identity ; if ( ! this . options . passive ) { this . _connection = connection ; this . _connection . open ( this . _onConnect . bind ( this ) ) ; } else { this . _onConnect ( ) ; } if ( this . options . subscribe ) { this . client . on ( 'message' , this . _onMessage . bind ( this ) ) . subscribe ( ) ; } }
Creates a sandbox for Muttr apps by the given identity
@constructor
@param {Identity} identity
@param {Connection} connection
@param {object} options
Creates a sandbox for Muttr apps by the given identity