-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
63 lines (53 loc) · 1.73 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
63
global._ = require('underscore');
var machina = require('machina')(global._);
var Monologue = require('monologue.js')(global._);
var postal = require("postal")(global._);
var monopost = require('monopost')(global._, Monologue, postal);
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var Searcher = require('./lib/twitterSearch')(global._, Monologue);
var io = require('socket.io').listen(server);
var CountByUser = require('./lib/countByUser')(global._, Monologue);
var CountByHashtag = require('./lib/countByHashtag')(global._, Monologue);
var PercentByLang = require('./lib/percentageByLanguage')(global._, Monologue);
var BatchManager = require('./lib/batchManager')(global._, machina, Monologue, io);
var main = module.exports = {
init: function() {
server.listen(8088);
app.use(express.static(__dirname + '/public'));
io.set('log level', 1);
this.searcher.on("search.started", function(data){
io.sockets.emit( "search.started", data );
});
io.sockets.on('connection', function (socket) {
console.log("client connected");
postal.publish({
channel: "search",
topic: "stop"
});
socket.on('search.start', function (data) {
data = data || {};
postal.publish({
channel: "search",
topic: "start",
data: data.searchQry || "JavaScript"
});
});
});
},
batchManager: new BatchManager(),
searcher: new Searcher(),
postal: postal,
processors: [
new CountByUser(),
new CountByHashtag(),
new PercentByLang()
]
};
main.searcher.on("#", function(d, e) {
if( e.topic !== "batch.results") {
console.log( e.topic + " " + (d||""));
}
});
main.init();