Esempio n. 1
0
  constructor (app) {
    log('constructor run with: ', app);

    this.pid = app.pluginId;

    this.config = {
      local: app.localModules || ctor.array()
    };

    this.t = {
      e: app.errTimeout,
      n: app.timeout
    };

    this.location = {
      protocol: app.protocol,
      host: app.host,
      path: app.path,
      ptm: app.pathToModule,
      ptc: app.pathToConfig
    };

    this.modules = ctor.object();
    this.missingModules = ctor.array();
    this.talker = new Talker(this.pid);

    this.talker.addListener();
    this.getConfigurationFromCache();
  }
Esempio n. 2
0
  constructor (remote, local) {
    if (Array.isArray(remote)) {
      this.cfg = remote;
    } else {
      this.cfg = ctor.array(ctor.object({v: 0, k: ''}));
    }

    if (Array.isArray(local)) {
      this.cfg = this.cfg.concat(local);
    }

    return this.cfg;
  }
Esempio n. 3
0
      m.l.forEach((l) => {
        log('loadModulesFromCache module %s', l);

        let module = this.talker.api.localStorage.get(`${this.pid}${l}`);
        let __ttl = ctor.number(module);

        if ('string' === typeof module && Number.isNaN(__ttl)) {
          log('loadModulesFromCache module from LS key: %s, len: %d', l, module.length);

          this.modules[l] = module;
        } else {
          log('loadModulesFromCache module from LS key: %s, value: %s', l, module);

          this.missingModules.push(
            ctor.object({
              url: l,
              needLoad: (helper.getCurrentTime() + this.t.n) > (__ttl || 0)
            })
          );
        }
      });
Esempio n. 4
0
  getConfigurationFromCache () {
    log('getConfigurationFromCache');

    let rawConfiguration = this.talker.api.localStorage.get(`${this.pid}cfg`);
    let configuration = helper.parseJson(rawConfiguration);

    if(!configuration) {
      configuration = new Configuration(null, this.config.local);
      this.talker.api.localStorage.set(`${this.pid}cfg`, configuration);
      this.talker.api.localStorage.set(`${this.pid}ttl`, 0);
      this.config.global = ctor.array(ctor.object({v: 0, k: ''}));
    } else {
      configuration = new Configuration(this.config.global, this.config.local);
    }

    this.config.all = {
      key: configuration[0].k,
      ttl: ctor.number(this.talker.api.localStorage.get(`${this.pid}ttl`) || 0),
      version: configuration[0].v,
      modules: [],
      raw: configuration
    };
  }