diff --git a/package.json b/package.json index 621717a0..756254a8 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "knex": "~0.5.1", "lodash": "~2.4.1", "mixpanel": "0.0.20", + "network-checker": "git+ssh://git@bitbucket.org:rulemotion/network-checker.git#v0.0.1", "ngrok": "~0.1.97", "pubnub": "~3.6.4", "request": "^2.51.0", diff --git a/src/lib/network-check.coffee b/src/lib/network-check.coffee deleted file mode 100644 index 0e8efb1b..00000000 --- a/src/lib/network-check.coffee +++ /dev/null @@ -1,36 +0,0 @@ -Promise = require 'bluebird' -request = Promise.promisifyAll require 'request' - -# options: The url to check, or an object of request options. -# timeout: 10s -# gzip: true -exports.checkURL = checkURL = (options) -> - if typeof options is 'string' - options = - url: options - options.timeout ?= 10000 - options.gzip ?= true - request - .getAsync(options) - .spread (response) -> - return response.statusCode in [ 200, 304 ] - .catch (e) -> - return false - -# options: The url to monitor, or an object of: -# interval: The time between each check. -# checkURL options -# fn(bool connected): The function that will be called each time the state changes. -exports.monitorURL = (options, fn) -> - interval = options?.interval or 0 - connectivityState = null # Used to prevent multiple messages when disconnected - _check = -> - checkURL(options) - .then (connected) -> - return if connected == connectivityState - connectivityState = connected - fn(connected) - return # Do not wait on fn if it returns a promise - .finally -> - setTimeout(_check, interval) - _check() diff --git a/src/utils.coffee b/src/utils.coffee index 2564f0e0..b3a1d035 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -4,7 +4,7 @@ fs = Promise.promisifyAll require 'fs' config = require './config' mixpanel = require 'mixpanel' request = require './request' -networkCheck = require './lib/network-check' +networkCheck = require 'network-checker' blink = require('blinker')(config.ledFile) utils = exports