-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
77 lines (65 loc) · 1.72 KB
/
main.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
var express = require('express'),
client = require('radiodan-client');
console.log('Hello');
/*
Web
This makes a web server available at
localhost on the specified port, the
default is 5000 so going to
http://localhost:5000/ in a web browser
will load `index.html` in ./static.
*/
var web = express(),
port = process.env.WEB_PORT || process.env.PORT || 5000;
// Use the radiodan middleware to enable
// the web pages to send commands to this
// radio
web.use('/radiodan',
client.middleware({
crossOrigin: true
})
);
// Make all files in ./static available to web
// pages
web.use(express.static(__dirname + '/static'));
web.listen(port);
console.log('Listening on port ' + port);
var radiodan = client.create();
// Get the player object called `main`
// as specified in ./config/radiodan-config.json
var player = radiodan.player.get('main');
// Listen for updates to the music database
// to make sure that we've loaded any
// audio files in `./audio` before we try
// and play them
player.on('database.update.start', function() {
console.log('database.update.start');
});
player.on('database.update.end', function() {
console.log('database.update.end');
init();
});
player.on('database.modified', function() {
console.log('database.update.modified');
});
// Tell the player to update it's database, discovering
// any audio files in the music directory specified in
// the config file.
player
.updateDatabase();
// When the music database is updated then
// this will run (see `player.on` code above)
function init() {
play('crowd.mp3');
}
/*
General helper function to play a file or
stream
*/
function play(fileOrStream) {
player
.add({
playlist: [fileOrStream]
})
.then(player.play);
}