コード例 #1
0
ファイル: digs.js プロジェクト: gitter-badger/digs
  /**
   * Instantiates Digs plugin; configures Board(s) for use
   * @param {(Object.<string,BoardDef>|Array.<BoardDef>)} opts Board Definition
   *     objects; keyed on ID, or an Array
   * @constructor
   */
  constructor(opts) {
    super();

    /**
     * Plugin Configuration
     * @type {Object}
     */
    opts = _.merge(DEFAULTS, opts || {});
    _.extend(this, _.pick(opts, 'namespace', 'project'));

    /**
     * Mapping of {@link Board} {@link Board#id Board ID's} to Boards.
     * @type {Object.<string,Board>}
     */
    this.boards = _(opts.boards)
      .pick(function (value) {
        return _.isObject(value) && value !== '_' && !_.isArray(value) &&
          !_.isFunction(value);
      })
      .map(this.createBoard, this)
      .indexBy('id')
      .value();

    if (opts.mqtt.broker.type === 'internal') {
      debug('%s: using internal MQTT broker', this);
      this._brokerReady = new Promise(function (resolve, reject) {
        this.broker = require('digs-broker')(opts.mqtt)
          .on('listening', resolve)
          .on('error', reject);
      }.bind(this));
    } else {
      this._brokerReady = Promise.resolve();
    }

    this.opts = opts;
    debug('%s: instantiated w/ options:', this, this.opts);

    Digs.serialPorts()
      .then(function (ports) {
        debug('Serial ports', ports);
      });
  }
コード例 #2
0
ファイル: component.js プロジェクト: gitter-badger/digs
 toJSON() {
   return _.pick(this, Component.fields);
 }