-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect.js
63 lines (53 loc) · 1.3 KB
/
connect.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
'use strict'
const View = require('./src/View')
const Dazzar = require('./src/Dazaar.js')
const HLS = require('./src/HLS-Gen.js')
const { openInvoice } = require('./src/util')
const config = {
STATION_KEY: process.argv[2],
HLS_SERVER: new (require('url').URL)(process.argv[3] || 'http://localhost:8021'),
STREAM_COST: 10,
MENU: [1, 10, 60, 90, 120]
}
if (!config.STATION_KEY) throw new Error('You must pass station key as argument to the script ')
console.log(config)
const hls = new HLS(config)
hls.init((err) => {
if (err) throw err
})
hls.startHLS()
const dazaar = new Dazzar(config)
dazaar.buyerLn.on('stream-invoice', (invoice) => {
openInvoice(invoice, (err) => {
if (err) throw err
})
})
const render = new View({
state: {
stationKey: config.STATION_KEY,
input: null,
streamAuth: 'Connecting to station ....'
},
config: {}
})
render.forceRender()
dazaar.on('stream-validate', () => {
dazaar.startStream({
start: 0
})
render.streamIsValid()
})
dazaar.on('stream-data', (data) => {
hls.appendData(data)
})
render.on('enter-key', (line) => {
if (render.state.menu) {
const amt = dazaar.getMenuAmount(+line)
if (!amt) return
dazaar.buy(amt)
}
})
dazaar.on('stream-invalid', () => {
render.showMenu(config.MENU, config.STREAM_COST)
})
dazaar.start()