-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
48 lines (40 loc) · 1.41 KB
/
worker.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
var fs = require('fs');
var express = require('express');
var serveStatic = require('serve-static');
var path = require('path');
var config = require(__dirname + '/config.json');
var Places = require(__dirname + '/places/places.js');
var Scanner = require(__dirname + '/scanner/scanner.js');
var PlacePersister = require(__dirname + '/places/persister.js');
var PlaceIndexer = require(__dirname + '/places/indexer.js');
var Logger = require(__dirname + '/logger/logger.js');
module.exports.run = function (worker) {
console.log(' >> Worker PID:', process.pid);
var app = require('express')();
app.set('view engine', 'jade');
app.set('views', './views');
app.use(serveStatic(path.resolve(__dirname, 'public')));
var httpServer = worker.httpServer;
var scServer = worker.scServer;
var scanner = new Scanner();
var placePersister = new PlacePersister();
var placeIndexer = new PlaceIndexer();
var places = new Places();
app.get('/', function(req, res) {
res.render('index', {
});
});
httpServer.on('request', app);
scServer.on('connection', function (socket) {
socket.on('player:screen-move', function (data) {
places.search(data.topLeft, data.bottomRight, function (err, places) {
if (err) {
// todo: handle err
console.error(err);
} else {
socket.emit('places:near', { places: places } );
}
});
});
});
};