Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 129 additions & 95 deletions src/APIFunctions/Speaker.js
Original file line number Diff line number Diff line change
@@ -1,167 +1,201 @@
import axios from 'axios';
import { ApiResponse } from './ApiResponses';
import { BASE_API_URL } from '../Enums';


export async function queued(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/queued', BASE_API_URL);
await axios
.get(url.href, {
try {
const res = await fetch(url.href, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status.responseData = res.data.queue;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch(err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function addUrl(urlToAdd, token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/stream', BASE_API_URL);
await axios
.post(url.href, {
url: urlToAdd
}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
url: urlToAdd
})
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch(err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function skip(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/skip', BASE_API_URL);
await axios
.post(url.href, {}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch(err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function pause(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/pause', BASE_API_URL);
await axios
.post(url.href, {}, {
try {
const res = await fetch(url.rhef, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch(err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function resume(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/resume', BASE_API_URL);
await axios
.post(url.href, {}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function setVolume(volumeToSet, token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/volume', BASE_API_URL);
await axios
.post(url.href, {
volume: volumeToSet
}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
body: JSON.stringify({
volume: volumeToSet
})
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch(err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function rewind(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/rewind', BASE_API_URL);
await axios
.post(url.href, {}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = error;
}
return status;
}

export async function forward(token) {
let status = new ApiResponse();
const url = new URL('/api/Speaker/forward', BASE_API_URL);
await axios
.post(url.href, {}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
}
}
)
.then(res => {
status = res.data;
})
.catch(err => {
status.responseData = err;
status.error = true;
});
if (res.ok) {
const result = await res.json();
status.responseData = result;
} else {
status.error = true;
}
} catch (err) {
status.error = true;
status.responseData = error;
}
return status;
}