-
Notifications
You must be signed in to change notification settings - Fork 44
/
draw.js
52 lines (44 loc) · 1.51 KB
/
draw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ,--. ,--. ,--.
// ,-| ,--.--.,--,--,--. ,--| |-. ,---.,-' '-.
// ' .-. | .--' ,-. | |.'.| | .-. | .-. '-. .-'
// \ `-' | | \ '-' | .'. | `-' ' '-' ' | |
// `---'`--' `--`--'--' '--'`---' `---' `--'
// Created by Andy Wise
//
// import external and node-specific modules
var Config = require('./modules/Config')
var BotController = require('./modules/BotController')
var LocalServer = require('./modules/LocalServer')
// var BotClient = require('./modules/BotClient') // for optional remote drawbot relay server client
// SETUP
var botController, botClient, localServer
var config = Config('config.json', () => {
// Main Controller
botController = BotController(config)
// Local Server
localServer = LocalServer(config, botController)
botController.localio = localServer.io
// Optional: Remote Drawbot Relay Server (requires "BotClient" import above, and "remoteURL" value in config.json)
// botClient = BotClient(config, botController)
// botController.client = botClient
// Initialize!
go()
})
// START
var go = () => {
botController.updateStringLengths()
localServer.start()
}
// GRACEFUL EXIT
// per http://joseoncode.com/2014/07/21/graceful-shutdown-in-node-dot-js/
// and https://github.com/fivdi/pigpio/issues/6
var shutdown = () => {
console.log('stopping the drawbot app...')
localServer.server.close()
process.exit(0)
}
process.on('SIGHUP', shutdown)
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
process.on('SIGCONT', shutdown)