private _setReceiverOptions()

in device/transport/http/src/http.ts [761:812]


  private _setReceiverOptions(opts?: HttpReceiverOptions): void {
    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_019: [If the receiver is already running with a previous configuration, the existing receiver should be restarted with the new configuration]*/
    const restartReceiver = this._receiverStarted;
    if (this._receiverStarted) {
      this.disableC2D(() => {
        debug('Http c2d message polling disabled');
      });
    }

    if (!opts) {
      this._opts = defaultOptions;
    }

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_008: [Only one of the interval, at, and cron fields should be populated: if more than one is populated, an ArgumentError shall be thrown.]*/
    if ((opts.interval && opts.cron) ||
        (opts.interval && opts.at) ||
        (opts.interval && opts.manualPolling) ||
        (opts.at && opts.cron) ||
        (opts.at && opts.manualPolling) ||
        (opts.cron && opts.manualPolling)) {
      throw new errors.ArgumentError('Only one of the (interval|at|cron) fields should be set.');
    }

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_002: [opts.interval is not a number, an ArgumentError should be thrown.]*/
    if (opts.interval && typeof (opts.interval) !== 'number') {
      throw new errors.ArgumentError('The \'interval\' parameter must be a number');
    }

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_005: [If opts.interval is a negative number, an ArgumentError should be thrown.]*/
    if (opts.interval && opts.interval <= 0) {
      throw new errors.ArgumentError('the \'interval\' parameter must be strictly greater than 0 (zero)');
    }

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_022: [If opts.at is not a Date object, an ArgumentError should be thrown]*/
    if (opts.at && !(opts.at instanceof Date)) {
      throw new errors.ArgumentError('The \'at\' parameter must be a Date');
    }

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_004: [if opts.cron is set it shall be a string that can be interpreted as a cron expression]*/
    if (opts.cron && typeof (opts.cron) !== 'string') {
      throw new errors.ArgumentError('The \'at\' parameter must be a String and use the cron syntax (see https://www.npmjs.com/package/node-crontab)');
    }

    this._opts = opts;

    /*Codes_SRS_NODE_DEVICE_HTTP_RECEIVER_16_019: [If the receiver is already running with a previous configuration, the existing receiver should be restarted with the new configuration]*/
    if (restartReceiver) {
      this.enableC2D(() => {
        debug('Http c2d message polling enabled');
      });
    }
  }