36 lines
915 B
JavaScript
36 lines
915 B
JavaScript
|
|
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost/api';
|
||
|
|
|
||
|
|
async function fetchAPI(endpoint, options = {}) {
|
||
|
|
const response = await fetch(`${API_URL}${endpoint}`, {
|
||
|
|
...options,
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
...options.headers,
|
||
|
|
},
|
||
|
|
credentials: 'include', // Always include credentials
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error(`API error: ${response.statusText}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
return response.json();
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getStreamKey() {
|
||
|
|
return fetchAPI('/stream/key');
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function regenerateStreamKey() {
|
||
|
|
return fetchAPI('/stream/key/regenerate', {
|
||
|
|
method: 'POST',
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function validateStreamKey(key) {
|
||
|
|
return fetchAPI(`/stream/validate/${key}`);
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getStreamStats(streamKey) {
|
||
|
|
return fetchAPI(`/stream/stats/${streamKey}`);
|
||
|
|
}
|