-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
47 lines (37 loc) · 1.03 KB
/
index.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
const express = require('express')
, app = express()
, http = require('http')
, path = require('path')
, { Server } = require('socket.io')
, RadioStation = require('radio-station')
const server = http.createServer(app)
, io = new Server(server)
const port = 8080
;(async () => {
const radio = await RadioStation.create({
pathWorkDir: path.join(__dirname, 'tracks-data-folder'),
isLauncher: false,
mainPort: port
})
await radio.track.loads(
path.join(__dirname, '/tracks-for-load')
)
app.get('/radio', (req, res) => {
radio.addListener(req, res)
})
io.on('connection', async socket => {
radio.onUse(info => {
socket.emit('onUse', info)
})
})
app.get('/picture', async (req, res) => {
radio.picture(req, res)
})
app.get('/info', async (req, res) => {
radio.info(req, res)
})
})()
app.use('/', express.static(__dirname+'/public'))
server.listen(port, () => {
console.log(`open: http://localhost:${port}`)
})