forked from antirek/hugu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
74 lines (53 loc) · 1.83 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
64
65
66
67
68
69
70
71
72
73
74
var express = require('express'),
http = require('http'),
io = require('socket.io'),
path = require('path'),
md5 = require('MD5'),
Client = require('./application/client'),
Pool = require('./application/pool'),
Manager = require('./application/manager');
var app = express();
var pool = new Pool();
var manager = new Manager();
app.set('port_http', 80);
app.set('port_websocket', 3001);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set('client_id', '3668304')
app.use(express.favicon());
app.use(express.logger());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', function(request, response){
response.render('index', {client_id: app.get('client_id')});
});
app.listen(app.get('port_http'), function() {
console.log('Express server listening on port ' + app.get('port_http'));
});
WebsocketServer = http.createServer(app);
WebsocketServer.listen(app.get('port_websocket'), function() {
console.log('WebSockets server listening on port ' + app.get('port_websocket'));
});
WebsocketListener = io.listen(WebsocketServer);
WebsocketListener.sockets.on('connection', function (socket) {
var client = new Client({
socket: socket,
manager: manager,
app: app
});
pool.addClient(client);
});
manager.on('updatePlaylist', function(){
pool.emitSocket('playlist', manager.getPlaylist());
});
manager.on('currentTrack', function(){
pool.emitSocket('currentTrack', manager.getCurrentTrack());
});
manager.on('currentVolume', function(value){
pool.emitSocket('currentVolume', value);
});