current listeners
Signed-off-by: ale <ale@manalejandro.com>
This commit is contained in:
parent
b4ac7a333d
commit
e62cd11eae
23
src/App.js
23
src/App.js
@ -11,6 +11,8 @@ const App = () => {
|
|||||||
[muted, setMuted] = useState(false),
|
[muted, setMuted] = useState(false),
|
||||||
[link, setLink] = useState(''),
|
[link, setLink] = useState(''),
|
||||||
[title, setTitle] = useState('Stream Radio'),
|
[title, setTitle] = useState('Stream Radio'),
|
||||||
|
[currentListeners, setCurrentListeners] = useState(0),
|
||||||
|
[maxListeners, setMaxListeners] = useState(0),
|
||||||
audioElmRef = useRef(null),
|
audioElmRef = useRef(null),
|
||||||
once = useRef(false),
|
once = useRef(false),
|
||||||
audioAnalyzer = () => {
|
audioAnalyzer = () => {
|
||||||
@ -43,6 +45,20 @@ const App = () => {
|
|||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('Error fetching data: ' + err.message)
|
console.error('Error fetching data: ' + err.message)
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
loadListeners = () => {
|
||||||
|
fetch('/status.xsl').then(response => response.text()).then(data => {
|
||||||
|
const parser = new DOMParser(),
|
||||||
|
xmlDoc = parser.parseFromString(data, 'text/html'),
|
||||||
|
listeners = xmlDoc.getElementsByTagName('td')
|
||||||
|
for (let i = 0; i < listeners.length; i++) {
|
||||||
|
if (i === 9) {
|
||||||
|
setCurrentListeners(listeners[i].textContent)
|
||||||
|
} else if (i === 11) {
|
||||||
|
setMaxListeners(listeners[i].textContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (json?.media?.track[0] && bounce.search(json?.media?.track[0].Title) === -1) {
|
if (json?.media?.track[0] && bounce.search(json?.media?.track[0].Title) === -1) {
|
||||||
@ -72,9 +88,13 @@ const App = () => {
|
|||||||
}, [json])
|
}, [json])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadData()
|
loadData()
|
||||||
|
loadListeners()
|
||||||
setAudioUrl('/stream.mp3')
|
setAudioUrl('/stream.mp3')
|
||||||
audioAnalyzer()
|
audioAnalyzer()
|
||||||
const inter = setInterval(loadData, 15000)
|
const inter = setInterval(() => {
|
||||||
|
loadData()
|
||||||
|
loadListeners()
|
||||||
|
}, (Math.floor(Math.random() * 20) + 10) * 1000)
|
||||||
return () => clearInterval(inter)
|
return () => clearInterval(inter)
|
||||||
}, [])
|
}, [])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -86,6 +106,7 @@ const App = () => {
|
|||||||
<>
|
<>
|
||||||
<h1>📻 Stream Radio</h1>
|
<h1>📻 Stream Radio</h1>
|
||||||
{analyzerData && <WaveForm analyzerData={analyzerData} />}
|
{analyzerData && <WaveForm analyzerData={analyzerData} />}
|
||||||
|
<h2>Current Listeners: {currentListeners} - Peak: {maxListeners}</h2>
|
||||||
<h4><p className="bounce"><a href={link} target="_blank" title={title} alt={title}>{bounce}</a></p></h4>
|
<h4><p className="bounce"><a href={link} target="_blank" title={title} alt={title}>{bounce}</a></p></h4>
|
||||||
<div>
|
<div>
|
||||||
<h2>Audio Controls</h2>
|
<h2>Audio Controls</h2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user