-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
100 lines (78 loc) · 2.2 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var express = require('express');
var nko = require('nko')('hfu9xf2WkLaqCx+T');
var sio = require('socket.io');
var fs = require('fs');
require("./normalize");
var Podcast = require("./Podcast").Podcast;
var app = express.createServer();
app.set('views', __dirname + '/views');
app.set('views', __dirname + '/views');
app.register('.html', require('ejs'));
app.set('view engine', 'html');
app.use(express.methodOverride());
app.use(express.bodyParser());
app.use(app.router);
var users = {
milfont: {
podcasts: []
}
};
app.get('/:user', function(req, res, next){
console.log("params >>", req.params);
if(req.params.user && users[req.params.user]) {
res.render("listen", {username:req.params.user});
} else {
next();
}
});
app.get('/', function(req, res, next){
res.render("index");
});
app.get('/restart', function(req, res, next){
res.redirect("/");
});
app.get('/talk', function(req, res, next){
res.render("talk");
});
app.get('/listen', function(req, res, next){
res.render("listen");
});
app.use(express.errorHandler({ showStack: true }));
app.use(express.static(__dirname));
app.listen(80, function () {
var addr = app.address();
console.log(' app listening on http://' + addr.address + ':' + addr.port);
});
var io = sio.listen(app);
io.set('log level', 1);
io.sockets.on('connection', function (client) {
client.on('user message', function (user, file, msg) {
//client.broadcast.emit('podcast', "milfont", msg);
client.broadcast.emit(user, "milfont", msg);
var podcast = users[user].podcasts.filter(function(podcast){
return podcast.file === file;
}).first();
if(podcast) podcast.append(msg);
});
client.on('start', function(user, name) {
var userTemp = users[user];
if(typeof userTemp === "undefined") {
users[user] = {
podcasts: []
}
}
console.log(users, user);
var podcast = new Podcast(user, name);
podcast.record();
users[user].podcasts.add(podcast);
});
client.on('stop', function(user, file) {
console.log("stop");
users[user].podcasts.each(function(podcast){
if(podcast.isOpen) podcast.stop();
});
});
client.on('listen', function(){
console.log("listen");
})
});