summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2022-09-24 22:19:44 -0500
committerMark Powers <mark@marks.kitchen>2022-09-24 22:19:44 -0500
commite882d551d58cb873d11f0774a79b48b4490ecbce (patch)
treeee334966b828f746bc98279eaea9a1dfa55bdb5c /index.js
parent09a0be0bd5d119c177ee18b692e84fb4ba49a129 (diff)
Add volume slider
Diffstat (limited to 'index.js')
-rw-r--r--index.js44
1 files changed, 34 insertions, 10 deletions
diff --git a/index.js b/index.js
index 521a28d..3fe01cc 100644
--- a/index.js
+++ b/index.js
@@ -61,18 +61,30 @@ function enqueue(id){
.then(data => console.log(`Added ${id} to queue`));
}
-function playlist(){
- return fetch(`${config.baseURL}/playlist`, {
+function set_volume(value){
+ fetch(`${config.baseURL}/post`, {
+ "credentials": "include",
+ "headers": headers(),
+ "body": `action=volume_set_value&new_volume=${value}`,
+ "method": "POST",
+ })
+}
+
+async function playlist(){
+ let info_res = await fetch(`${config.baseURL}/post`, {
+ "credentials": "include",
+ "headers": headers(),
+ "method": "POST",
+ })
+ let info_json = await info_res.json()
+ let playlist_res = await fetch(`${config.baseURL}/playlist`, {
"credentials": "include",
"headers": headers(),
"method": "GET",
- }).then(response => {
- try {
- return response.json()
- } catch (error) {
- return {}
- }
})
+ let playlist_json = await playlist_res.json()
+ info_json.items = playlist_json.items
+ return info_json
}
async function get_all_sounds(){
@@ -193,6 +205,7 @@ server.get('/', async (req, res) => {
<ol id="playlist"><ol>
</div>
<button onclick="random()">random</button>
+ <input type="range" min="0" max="100" class="slider" id="volume">
<body>
`
try {
@@ -239,8 +252,14 @@ server.get('/random', async (req, res, next) => {
})
server.get('/playlist', async (req, res, next) => {
- let playlist_items = await playlist()
- res.send(playlist_items)
+ try {
+ let playlist_items = await playlist()
+ res.send(playlist_items)
+ } catch (error) {
+ console.error("problem getting current status")
+ console.error(error)
+ res.send({items: [], })
+ }
})
server.get('/main.js', async (req, res, next) => {
@@ -257,6 +276,11 @@ server.get('/delete/:id', async (req, res, next) => {
res.send("ok")
})
+server.get('/volume/:val', async (req, res, next) => {
+ set_volume(req.params.val)
+ res.send("ok")
+})
+
server.get('/:id', async (req, res, next) => {
enqueue(req.params.id)
res.send("ok")