endo-core
Version:
Put some description here
82 lines (70 loc) • 2.56 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 ?
address: =>
?.address()
run: (callback) =>
callback = _.after callback, 2 if && !
meshblu = new MeshbluHTTP
meshblu.whoami (error, device) =>
throw new Error('Could not authenticate with meshblu!') if error?
{imageUrl} = device.options ? {}
credentialsDeviceService = new CredentialsDeviceService {, , , imageUrl}
messagesService = new MessagesService {, }
messageRouter = new MessageRouter {, messagesService, credentialsDeviceService}
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