fix: AudioContext warning when loading widget on Chrome (#3956)
* fix: AudioContext warning when loading widget on Chrome * minor fixes * Minor fixes * adds event on document * Play audio from parent window through SDK * Adds notification to dashboard Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> Co-authored-by: Vishnu Narayanan <vishnu@chatwoot.com>
This commit is contained in:
parent
eee89bf0d8
commit
a3cb26a317
4 changed files with 58 additions and 11 deletions
|
@ -1,9 +1,10 @@
|
|||
import { MESSAGE_TYPE } from 'shared/constants/messages';
|
||||
import axios from 'axios';
|
||||
import { IFrameHelper } from 'widget/helpers/utils';
|
||||
|
||||
import { showBadgeOnFavicon } from './faviconHelper';
|
||||
|
||||
export const initOnEvents = ['click', 'touchstart', 'keypress'];
|
||||
export const getAlertAudio = async () => {
|
||||
window.playAudioAlert = () => {};
|
||||
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const playsound = audioBuffer => {
|
||||
window.playAudioAlert = () => {
|
||||
|
@ -16,11 +17,14 @@ export const getAlertAudio = async () => {
|
|||
};
|
||||
|
||||
try {
|
||||
const response = await axios.get('/dashboard/audios/ding.mp3', {
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
const audioRequest = new Request('/dashboard/audios/ding.mp3');
|
||||
|
||||
audioCtx.decodeAudioData(response.data).then(playsound);
|
||||
fetch(audioRequest)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => {
|
||||
audioCtx.decodeAudioData(buffer).then(playsound);
|
||||
return new Promise(res => res());
|
||||
});
|
||||
} catch (error) {
|
||||
// error
|
||||
}
|
||||
|
@ -89,6 +93,7 @@ export const newMessageNotification = data => {
|
|||
currentUserId,
|
||||
assigneeId
|
||||
);
|
||||
|
||||
if (playAudio && isNotificationEnabled) {
|
||||
window.playAudioAlert();
|
||||
showBadgeOnFavicon();
|
||||
|
@ -96,5 +101,7 @@ export const newMessageNotification = data => {
|
|||
};
|
||||
|
||||
export const playNewMessageNotificationInWidget = () => {
|
||||
window.playAudioAlert();
|
||||
IFrameHelper.sendMessage({
|
||||
event: 'playAudio',
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue