-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (35 loc) · 979 Bytes
/
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
const fs = require('fs')
const configureFile = require('./configureFile');
const initServer = (options) => {
fs.stat('resonance.json',(err, status)=>{
if(err){
configureFile(null, server);
}
if(!err){
server()
}
})
}
const server = ()=>{
var config = require(process.cwd()+'/resonance.json');
var io = require('socket.io')(config.port)
var redis = require('redis')
var sub = redis.createClient();
var chans = config.channels.map(function(chan){
var chan = io.of('/'+chan)
return chan
})
sub.on("message",function(channel, data){
var message = JSON.parse(data)
chans.map(function(chan){
if(chan.name == '/'+channel){
chan.emit(message.event, message.music)
}
})
});
config.channels.map(function(chan){
sub.subscribe(chan)
})
console.log('Serving on port '+config.port)
}
module.exports = exports = initServer