mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-09 16:46:11 +00:00
chore: commit local changes (voice cleanup, audio notifications)
This commit is contained in:
@@ -13,16 +13,35 @@ export const getAudioContext = () => {
|
||||
// eslint-disable-next-line default-param-last
|
||||
export const getAlertAudio = async (baseUrl = '', requestContext) => {
|
||||
const audioCtx = getAudioContext();
|
||||
let lastSource;
|
||||
const stopLast = () => {
|
||||
try {
|
||||
if (lastSource) {
|
||||
lastSource.stop();
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore stop errors
|
||||
} finally {
|
||||
lastSource = null;
|
||||
}
|
||||
};
|
||||
|
||||
const playSound = audioBuffer => {
|
||||
window.playAudioAlert = () => {
|
||||
if (audioCtx) {
|
||||
stopLast();
|
||||
const source = audioCtx.createBufferSource();
|
||||
source.buffer = audioBuffer;
|
||||
source.connect(audioCtx.destination);
|
||||
source.loop = false;
|
||||
source.start();
|
||||
lastSource = source;
|
||||
source.onended = () => {
|
||||
if (lastSource === source) lastSource = null;
|
||||
};
|
||||
}
|
||||
};
|
||||
window.stopAudioAlert = stopLast;
|
||||
};
|
||||
|
||||
if (audioCtx) {
|
||||
|
||||
Reference in New Issue
Block a user