checkGrowl.js 536 B

123456789101112131415161718192021222324
  1. var net = require('net');
  2. var hasGrowl = false;
  3. module.exports = function(growlConfig, cb) {
  4. if (typeof cb === 'undefined') {
  5. cb = growlConfig;
  6. growlConfig = {};
  7. }
  8. if (hasGrowl) return cb(null, hasGrowl);
  9. var port = growlConfig.port || 23053;
  10. var host = growlConfig.host || 'localhost';
  11. var socket = net.connect(port, host);
  12. socket.setTimeout(100);
  13. socket.on('connect', function() {
  14. socket.end();
  15. cb(null, true);
  16. });
  17. socket.on('error', function() {
  18. socket.end();
  19. cb(null, false);
  20. });
  21. };