Initial api access functionality
This commit is contained in:
parent
9ef10153c9
commit
658c676be8
3 changed files with 64 additions and 4 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/bower_components/
|
||||
/node_modules/
|
||||
/node_modules/
|
||||
resources/data.js
|
11
index.html
11
index.html
|
@ -13,9 +13,14 @@
|
|||
|
||||
<body>
|
||||
<header></header>
|
||||
<main></main>
|
||||
<main>
|
||||
<p>Current Viewers: <span id="currentViewers"></span>. Session Peak Viewers: <span id="sessionPeak"></span>.</p>
|
||||
<p>Stream Online? <span id="online"></span></p>
|
||||
</main>
|
||||
<footer></footer>
|
||||
<script type="text/javascript" src=""></script>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript" src="resources/data.js"></script>
|
||||
<script type="text/javascript" src="resources/script.js"></script>
|
||||
|
||||
</html>
|
||||
</html>
|
54
resources/script.js
Normal file
54
resources/script.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
const headers = new Headers();
|
||||
// note, userName and streamKey are both derived in a file called data.js
|
||||
headers.append('Authorization', 'Basic ' + btoa(userName + ":" + streamKey));
|
||||
|
||||
async function getEndpoint(url = '') {
|
||||
const response = await fetch(url, {method:'GET', headers: headers})
|
||||
const data = await response.json()
|
||||
return data
|
||||
}
|
||||
|
||||
async function postEndpoint(url = '', data = {}) {
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data), // serialized data
|
||||
headers: headers // authentication header
|
||||
})
|
||||
return response
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
return getEndpoint(api_url + 'admin/status')
|
||||
}
|
||||
|
||||
async function updateElements(data) {
|
||||
var {online, viewerCount, sessionPeakViewerCount} = data
|
||||
updateViewers(viewerCount);
|
||||
updateOnline(online);
|
||||
updateSessionPeak(sessionPeakViewerCount);
|
||||
|
||||
}
|
||||
|
||||
async function updateOnline(online) {
|
||||
document.getElementById('online').innerHTML = online
|
||||
}
|
||||
async function updateViewers(viewers) {
|
||||
document.getElementById('currentViewers').innerHTML = viewers
|
||||
}
|
||||
async function updateSessionPeak(viewers) {
|
||||
document.getElementById('sessionPeak').innerHTML = viewers
|
||||
}
|
||||
|
||||
async function Main() {
|
||||
// update visual elements using data from 'api/admin/status'
|
||||
updateElements(await getStatus())
|
||||
|
||||
// update the broadcast title
|
||||
// postEndpoint(``
|
||||
// api_url + 'admin/config/streamtitle',
|
||||
// {value: "testing" + Math.floor(Math.random() * 1000)}
|
||||
// ).then(response => response.status)
|
||||
// .then(data => console.log(data))
|
||||
}
|
||||
|
||||
Main()
|
Loading…
Reference in a new issue