-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
45 lines (36 loc) · 1.13 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
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: true,
mainPort: port,
login: 'localhost', // this optional, if you not define value, server generate auto
password: 'hackme' // this optional, if you not define value, server generate auto
})
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}`)
})