Andela Notifications Updated
This commit is contained in:
21
job-notifier/offscreen.js
Normal file
21
job-notifier/offscreen.js
Normal file
@@ -0,0 +1,21 @@
|
||||
let audioContext;
|
||||
let audioBuffer;
|
||||
|
||||
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (message.action === 'playSound') {
|
||||
playNotificationSound();
|
||||
}
|
||||
});
|
||||
|
||||
async function playNotificationSound() {
|
||||
if (!audioContext) {
|
||||
audioContext = new AudioContext();
|
||||
const response = await fetch(chrome.runtime.getURL('notify.wav'));
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
||||
}
|
||||
const source = audioContext.createBufferSource();
|
||||
source.buffer = audioBuffer;
|
||||
source.connect(audioContext.destination);
|
||||
source.start(0);
|
||||
}
|
||||
Reference in New Issue
Block a user