aboutsummaryrefslogtreecommitdiff
path: root/bin/tomato_sauce.js
blob: 5a416d5fd8a1f209312c9a055d01cfe8c5ad4f94 (plain)
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
#!/usr/bin/env node

'use strict';

/* eslint no-console: 0 */

const Path = require('path');
const Getenv = require('getenv');

const TomatoSauce = require('..');
const Util = require('../lib/util');

const config = {
  port: Getenv.int('TOMATO_SAUCE_PORT', 9999),
  frequency: Getenv.int('TOMATO_SAUCE_FREQUENCY', 333),
  modulation: Getenv.int('TOMATO_SAUCE_MODULATION_SPEED', 5)
};

const screenPath = Getenv('TOMATO_SAUCE_SCREEN_PATH', Path.join(__dirname, '../lib/screens'));
const rendererPath = Getenv('TOMATO_SAUCE_RENDERER_PATH', Path.join(__dirname, '../lib/renderers'));

Util.loadFiles(screenPath).then(function (screens) {
  config.screens = screens;
  return Util.loadFiles(rendererPath);
}).then(function (renderers) {
  config.renderers = renderers;
}).then(function () {
  let tomatoSauce = new TomatoSauce(config);

  tomatoSauce.on('listening', function (event) {
    const address = event.data.server.address();
    console.log(`Tomato Sauce listening on: ${address.address}:${address.port}`);
  });

  tomatoSauce.on('error', function (error) {
    console.error(error.stack || error.message || error);
    process.exit(1);
  });

  tomatoSauce.run();
});