Skip to content

Commit

Permalink
fix(overlays): correct link to files
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed May 2, 2024
1 parent f0c5e02 commit 3ded745
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions frontend/overlays/src/pages/alerts.vue
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
<script lang="ts" setup>
import { useWebSocket } from '@vueuse/core';
import { ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useWebSocket } from '@vueuse/core'
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { generateSocketUrlWithParams } from '@/helpers.js';
import { generateSocketUrlWithParams } from '@/helpers.js'
declare global {
interface Window {
webkitAudioContext: typeof AudioContext;
webkitAudioContext: typeof AudioContext
}
}
const queue = ref<Array<{
id: string,
channel_id: string,
audio_id: string,
id: string
channel_id: string
audio_id: string
audio_volume: number
}>>([]);
}>>([])
const currentAudioBuffer = ref<AudioBufferSourceNode | null>(null);
const route = useRoute();
const currentAudioBuffer = ref<AudioBufferSourceNode | null>(null)
const route = useRoute()
const apiKey = route.params.apiKey as string;
const apiKey = route.params.apiKey as string
const alertsUrl = generateSocketUrlWithParams('/overlays/alerts', {
apiKey,
});
apiKey
})
const socket = useWebSocket(alertsUrl, {
immediate: true,
autoReconnect: {
delay: 500,
},
});
delay: 500
}
})
watch(socket.data, (message) => {
const parsedData = JSON.parse(message);
const parsedData = JSON.parse(message)
if (parsedData.eventName === 'trigger') {
queue.value.push(parsedData.data);
queue.value.push(parsedData.data)
if (queue.value.length === 1) {
processQueue();
processQueue()
}
}
});
})
async function processQueue(): Promise<void> {
if (queue.value.length === 0) {
return;
return
}
const current = queue.value[0];
const current = queue.value[0]
if (current.audio_id) {
await playAudio(current.channel_id, current.audio_id, current.audio_volume);
await playAudio(current.channel_id, current.audio_id, current.audio_volume)
}
// change next val
queue.value = queue.value.slice(1);
queue.value = queue.value.slice(1)
// Process the next item in the queue
processQueue();
processQueue()
}
async function playAudio(channelId: string, audioId: string, volume: number): Promise<unknown> {
const query = new URLSearchParams({
channel_id: channelId,
file_id: audioId,
});
const req = await fetch(`${window.location.origin}/api/files/?${query}`);
file_id: audioId
})
const req = await fetch(`${window.location.origin}/api-old/files/?${query}`)
if (!req.ok) {
console.error(await req.text());
return;
console.error(await req.text())
return
}
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
const gainNode = audioContext.createGain();
const audioContext = new (window.AudioContext || window.webkitAudioContext)()
const gainNode = audioContext.createGain()
const data = await req.arrayBuffer();
const data = await req.arrayBuffer()
const source = audioContext.createBufferSource();
currentAudioBuffer.value = source;
const source = audioContext.createBufferSource()
currentAudioBuffer.value = source
source.buffer = await audioContext.decodeAudioData(data);
source.buffer = await audioContext.decodeAudioData(data)
gainNode.gain.value = volume / 100;
source.connect(gainNode);
gainNode.connect(audioContext.destination);
gainNode.gain.value = volume / 100
source.connect(gainNode)
gainNode.connect(audioContext.destination)
return new Promise((resolve) => {
source.onended = () => {
currentAudioBuffer.value = null;
resolve(null);
};
currentAudioBuffer.value = null
resolve(null)
}
source.start(0);
});
source.start(0)
})
}
</script>

0 comments on commit 3ded745

Please sign in to comment.