Exemplo n.º 1
0
function fetch(feed) {
  // Define our streams
  var req = request(feed, {timeout: 10000, pool: false});
  req.setMaxListeners(50);
  // Some feeds do not respond without user-agent and accept headers.
  req.setHeader('user-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36')
     .setHeader('accept', 'text/html,application/xhtml+xml');

  var feedparser = new FeedParser();

  // Define our handlers
  req.on('error', done);
  req.on('response', function(res) {
    if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
    var charset = getParams(res.headers['content-type'] || '').charset;
    res = maybeTranslate(res, charset);
    // And boom goes the dynamite
    res.pipe(feedparser);
  });

  feedparser.on('error', done);
  feedparser.on('end', done);
  feedparser.on('readable', function() {
    var post;
    while (post = this.read()) {
      console.log(post);
    }
  });
}
Exemplo n.º 2
0
 supported_modules.forEach(function(item) {
   var mod = require(item);
   var m = new mod();
   m.on('deviceonline', _mm.onDeviceOnline.bind(_mm));
   m.on('deviceoffline', _mm.onDeviceOffline.bind(_mm));
   _mm.emit('moduleload', item, m);
 });
Exemplo n.º 3
0
		getSplitExperimentById : function(id, callback){
			var bus = new Bus();
			
			var ref = this;
			bus.on('start', function(){
				ref.getById(id, function(err, data){
					if(err){
						callback(err, null);// Respond back with error
					}else{
						//Get Links
						var experiment = data.data;
						bus.fire('experiment_fetched', experiment);
					}
				});
			});
			
			bus.on('experiment_fetched', function(experiment){
				linksImpl.search(function(err, data){
					if(err){
						callback(err);
					}else{
						var links = data.data;
						experiment.links = links;
						callback(null,response.success(experiment, 1, codes.success.RECORD_FETCHED([ref.displayName, id])));
					}
				}, 'experimentId:eq:' + experiment.id + "___isDisabled:eq:0");
			});
			
			bus.fire('start');
		},
Exemplo n.º 4
0
Arquivo: walk.js Projeto: jmoyers/goat
  it('should also emit when recursing into subdirectories', function (done) {
    var walk = new Walk(join(__dirname, 'fixtures', 'recursive'));

    var results = [];

    walk.on('file', function (file) {
      results.push(file);
    });

    walk.on('done', function (files) {
      var real = [
        join(__dirname, 'fixtures', 'recursive', '1.mp3'),
        join(__dirname, 'fixtures', 'recursive', '2.mp3'),
        join(__dirname, 'fixtures', 'recursive', '3.m4a'),
        join(__dirname, 'fixtures', 'recursive', 'one', '1.mp3'),
        join(__dirname, 'fixtures', 'recursive', 'one', '2.mp3'),
        join(__dirname, 'fixtures', 'recursive', 'one', '3.m4a'),
        join(__dirname, 'fixtures', 'recursive', 'one', 'two', '1.mp3'),
        join(__dirname, 'fixtures', 'recursive', 'one', 'two', '2.mp3'),
        join(__dirname, 'fixtures', 'recursive', 'one', 'two', '3.m4a')
      ];

      var diffEach = _.difference(results, real);
      var diffAll = _.difference(files, real);

      assert(diffEach.length == 0);
      assert(diffAll.length == 0);
      done();
    });

    walk.fetch();
  });
Exemplo n.º 5
0
    it("should pass the additional arguments to all callbacks", function()
    {
      var mb = new MessageBroker();
      var expectedArgs = [];
      var actualArgs = [];

      function pushActualArgs()
      {
        actualArgs.push(Array.prototype.slice.call(arguments));
      }

      mb.on('message', pushActualArgs);
      mb.on('message', pushActualArgs);

      function emitMessageEvent(args)
      {
        expectedArgs.push(args);
        expectedArgs.push(args);

        mb.emit.apply(mb, [].concat('message', args));
      }

      emitMessageEvent([1]);
      emitMessageEvent([1, 2]);
      emitMessageEvent([1, 2, 3]);
      emitMessageEvent([1, 2, 3, 4]);
      emitMessageEvent([1, 2, 3, 4, 5]);

      actualArgs.should.eql(expectedArgs);
    });
Exemplo n.º 6
0
Arquivo: walk.js Projeto: jmoyers/goat
  it('should emit each file in a directory', function (done) {
    var walk = new Walk(join(__dirname, 'fixtures', 'flat'));

    var results = [];

    walk.on('file', function (file) {
      results.push(file);
    });

    walk.on('done', function (files) {
      var real = [
        join(__dirname, 'fixtures', 'flat', '1.mp3'),
        join(__dirname, 'fixtures', 'flat', '2.mp3'),
        join(__dirname, 'fixtures', 'flat', '3.m4a')
      ];

      var diffEach = _.difference(real, results);
      var diffAll = _.difference(real, files);

      assert(diffEach.length == 0);
      assert(diffAll.length == 0);
      done();
    });

    walk.fetch();
  });
Exemplo n.º 7
0
        }).forEach(function (file) {
            var workerName = path.basename(file, '.js');
            var workerCommands = require(applicationFacade.basePath + '/' + self._workersDir + '/' + file);

            var worker = self._client.worker([workerName], { collection: self._workersCollection});

            worker.register(workerCommands);
            self._logger.log('## Loading worker: %s', workerName);

            if (events) {
                if (events.complete && typeof events.complete === "function") {
                    self._logger.debug('  ## Registered \'complete\' handler for worker: %s', workerName);
                    worker.on('complete', events.complete);
                }

                if (events.failed && typeof events.failed === "function") {
                    self._logger.debug('  ## Registered \'failed\' handler for worker: %s', workerName);
                    worker.on('failed', events.failed);
                }

                if (events.error && typeof events.error === "function") {
                    self._logger.debug('  ## Registered \'error\' handler for worker: %s', workerName);
                    worker.on('error', events.error);
                }

                if (events.dequeued && typeof events.dequeued === "function") {
                    self._logger.debug('  ## Registered \'dequeued\' handler for worker: %s', workerName);
                    worker.on('dequeued', events.dequeued);
                }
            }

            worker.start();
        });
 grunt.registerMultiTask('validate-desktop-update', 'Validates desktop update package', function () {
     var path = require('path');
     var done = this.async();
     var StreamZip = require(path.resolve(__dirname, '../../electron/node_modules/node-stream-zip'));
     var zip = new StreamZip({ file: this.options().file, storeEntries: true });
     var expFiles = this.options().expected;
     zip.on('error', function(err) {
         grunt.warn(err);
     });
     zip.on('ready', function() {
         var valid = true;
         expFiles.forEach(function(entry) {
             try {
                 if (!zip.entryDataSync(entry)) {
                     grunt.warn('Corrupted entry in desktop update archive: ' + entry);
                     valid = false;
                 }
             } catch (e) {
                 grunt.warn('Entry not found in desktop update archive: ' + entry);
                 valid = false;
             }
         });
         if (valid) {
             done();
         }
     });
 });
Exemplo n.º 9
0
CollectorConnection.prototype.createDataSender = function (methodName, data) {
  var sender = new DataSender(this.agent.config, this.agentRunId);

  sender.on('response', function (response) {
    this.emit(methodName + 'Response', response);
  }.bind(this));

  // shutdown's error is expected and thus a special case
  if (methodName === 'shutdown') {
    sender.on('error', function (remoteName, error) {
      // observers might want to know when shutdown is handled
      this.once('shutdown', this.onShutdown.bind(this));
      this.emit('shutdown', error);
    }.bind(this));
  }
  else {
    sender.on('error', function (remoteName, error) {
      this.emit('error', methodName, remoteName, error);
      this.emit(methodName + 'Error', data, error);
    }.bind(this));

    // Some of the errors have special types -- be sure to handle them
    sender.once('error', this.onNRException.bind(this));
  }

  return sender;
};
Exemplo n.º 10
0
    it('should retry if the peripheral is not ready',function(done){
        test.mocknet.connectException = 'test error';

        var count = 0;
        var reader = new DataReader(testPeripheral);
        reader.on('error',function(error){
            console.log(error);
        });
        reader.on('retry',function(error){
            error.should.eql(new Error('test error'));
            if (count++ > 0) {
                reader.stop();
                test.pp.snapshot().should.eql([
                    '[reader    ] start watching',
                    '[reader    ] retry: test error',
                    '[reader    ] retry: test error',
                    '[reader    ] stop watching'
                ]);
                test.mocknet.snapshot().should.eql([
                    {end: null}
                ]);
                done();
            }
        });
        reader.start();
    });
exports.init = function init(options, dependencies) {
	var i, len,
		platform;
	for (i = 0, len = dependencies.length; i < len; i++) {
		if (dependencies[i].name === 'ti-api-provider') {
			platform = dependencies[i].platform;
		}
	}

	results = {
		summary: '',
		invalidAPIs: {}
	};

	Runtime.on('tiPropertyReferenced', function(e) {
		var platformList = e.data.node.userAgents,
			location = e.filename + ':' + e.line + ':' + e.column,
			i, len,
			isSupported = false,
			name = e.data.name,
			invalidAPI;

		for (i = 0, len = platformList.length; i < len; i++) {
			if (platform === platformList[i].platform) {
				isSupported = true;
			}
		}
		if (!isSupported) {
			Runtime.reportWarning('invalidPlatformReferenced', 'Property "' + name +
				'" is not supported on ' + platform, {
					property: name,
					platform: platform
				});

			invalidAPI = results.invalidAPIs[name];
			if (invalidAPI) {
				invalidAPI.numInstances++;
				if (invalidAPI.locations.hasOwnProperty(location)) {
					invalidAPI.locations[location]++;
				} else {
					invalidAPI.locations[location] = 1;
				}
			} else {
				results.invalidAPIs[name] = {
					numInstances: 1,
					locations: {}
				};
				results.invalidAPIs[name].locations[location] = 1;
			}
		}
	});
	Runtime.on('projectProcessingEnd', function () {
		generateResultsData();
		generateRenderData();
	});
};
Exemplo n.º 12
0
exports.start = function(opts, cb) {
  hooks.on('geofencing_start', function(fences) {
    if (!fences) return;

    zones = fences;

    if (!location) return;

    if (zones.length == 0) {
      attempts = 0;
      clearTimeout(retryTimeOut)
      return;
    }

    check_zones();
  });

  hooks.on('new_location', function(coords) {
    // Only check zones on significant location changes
    if (!coords || (coords.delta && coords.delta < 30)) return;

    // When a new trustful location comes it has to be saved, even if there are no fences
    if (coords.method == 'wifi' && coords.accuracy < 300)
      location = coords;

    if (!zones || zones.length == 0) return;

    // If the location isn't trustworthy ask the location again
    if (coords.method != 'wifi' || coords.accuracy > 300)
      return check_location(fibonacci(attempts));

    clearTimeout(retryTimeOut)
    attempts = 0;

    check_zones();
  })

  // Fetch geofences and stop previous location check
  hooks.on('connected', function() {
    clearTimeout(retryTimeOut)
    attempts = 0;

    action.start();
  })

  // No need to keep checking the location until it's connected again
  hooks.on('disconnected', function() {
    clearTimeout(retryTimeOut)
    attempts = 0;
  })

  emitter = new Emitter();
  cb(null, emitter);

};