-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
64 lines (54 loc) · 1.79 KB
/
index.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
64
var settings = require('./config');
var express = require("express");
var app = express();
var http = require("http").createServer(app);
var io = require("socket.io")(http);
var twitter = require("twitter");
var twitterClient = new twitter({
consumer_key: settings.twitterConsumerKey,
consumer_secret: settings.twitterConsumerSecret,
access_token_key: settings.twitterAccessKey,
access_token_secret: settings.twitterAccessSecret
});
// Websocket gubbins
io.sockets.on("connection", function(socket) {
socket.on("connect", function() {
io.emit("alert", "Connected to control panel.");
});
socket.on("disconnect", function() {
io.emit("alert", "Lost connection to control panel.");
});
socket.on("reconnect", function() {
io.emit("alert", "Reconnected to control panel.");
});
socket.on("command", function(cmd, params) {
console.log("command", cmd, params);
io.emit("command", cmd, params);
});
socket.on("alert", function(msg) {
io.emit("alert", msg);
});
});
app.use("/assets", express.static("assets"));
app.use("/screens", express.static("screens"));
app.use("/service", express.static("service"));
app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});
app.get("/admin", function(req, res) {
res.sendFile(__dirname + "/admin.html");
});
http.listen(settings.port, function() {
console.log("Listening on port " + settings.port + ".");
});
// Twitter streamin'
twitterClient.stream("statuses/filter", { track: settings.twitterSearch, follow: settings.twitterId }, function(stream) {
stream.on("data", function(tweet) {
//console.log("Received tweet from @" + tweet.user.screen_name + ": " + tweet.text);
io.emit("tweet", tweet);
});
stream.on("error", function(error) {
console.log("Twitter API returned error:");
console.log(error);
});
});