-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
62 lines (50 loc) · 1.45 KB
/
server.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
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')
, playlist = require("./playlist");
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.broadcast.emit('user', {user:"join"});
socket.on('requestPlaylist', function(data)
{
socket.emit('playlistnew', playlist.tracks);
});
socket.on('changeVolume', function(data) {
socket.broadcast.emit('changeVolume', data);
});
socket.on('disconnect', function () {
socket.broadcast.emit('user', {user:"leave"});
});
socket.on('addTrack', function (data) {
console.log(data);
playlist.addTrack(data);
socket.broadcast.emit('addTrack', data);
});
socket.on('changevideonext', function() {
playlist.nextTrack();
socket.broadcast.emit('changevideonext', "test");
});
socket.on('changevideolast' ,function() {
playlist.lastTrack();
socket.broadcast.emit('changevideolast', "test");
});
socket.on('changevideo', function(data) {
socket.broadcast.emit('changevideo', data);
playlist.setCurrentTrack(data);
});
socket.on('playlistaddlink', function(data) {
playlist.addLink(data.url);
socket.broadcast.emit('playlistaddlink', { url: data.url });
});
});