endo-core
Version:
Put some description here
89 lines (76 loc) • 2.94 kB
text/coffeescript
_ = require 'lodash'
MeshbluHTTP = require 'meshblu-http'
CredentialsDeviceService = require './services/credentials-device-service'
MessagesService = require './services/messages-service'
MessageRouter = require './models/message-router'
Server = require './server'
FirehoseMessageProcessor = require './firehose-message-processor'
class Endo
constructor: (options) ->
{
} = options
throw new Error('messageHandler is required') unless ?
throw new Error('deviceType is required') unless ?
throw new Error('serviceUrl is required') unless ?
unless
throw new Error 'healthcheckService is required' unless ?
throw new Error 'healthcheckService.healthcheck is not a function (and must be)' unless _.isFunction .healthcheck
address: =>
?.address()
run: (callback) =>
meshblu = new MeshbluHTTP
meshblu.whoami (error, device) =>
return callback new Error("Could not authenticate with meshblu: #{error.message}") if error?
{imageUrl} = device.options ? {}
credentialsDeviceService = new CredentialsDeviceService {, , , , imageUrl}
messagesService = new MessagesService {, }
messageRouter = new MessageRouter {, messagesService, credentialsDeviceService}
callback = _.after callback, 2 if && !
unless
= new Server {
credentialsDeviceService
messagesService
messageRouter
}
.run callback
if
?=
= new FirehoseMessageProcessor {meshbluConfig: , messageRouter}
.run callback
stop: (callback) =>
callback = _.after callback, 2 if && !
?.stop callback
?.stop callback
module.exports = Endo