diff --git a/dist/main.js b/dist/main.js index 9ddcfb9..9c7eb0f 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1 +1 @@ -(()=>{var e={626:e=>{async function t(e,t){let a=await chrome.storage.local.get("levels"),o=null;null==a.levels?o={[e]:t}:(o=a.levels,o[e]=t),await chrome.storage.local.set({levels:o})}async function a(e){let t=(await chrome.storage.local.get("levels")).levels;return null!=t&&null!=t[e]&&(console.log("tablevels: "+t),!0)}async function o(e){let t=(await chrome.storage.local.get("levels")).levels;return!await a(e)||t[e]<0?(console.log("!!Level not found for tabId: ",e),100):(console.log("!!Level found for tabId: ",e),100*t[e])}async function s(){let[e]=await chrome.tabs.query({active:!0,currentWindow:!0});return e}e.exports={worker:function(e,t){return e+t},sum:function(e,t){return e+t},getTabLevel:o,containsTab:a,getCurrentTab:s},chrome.runtime.onStartup.addListener((function(){console.log("Browser opened CLEARING CACHE"),chrome.storage.local.clear()})),new Map,chrome.runtime.onMessage.addListener((async e=>{switch(console.log("Message received from popup"),e.type){case"popup-loaded":let n=await s();var r=await o(n.id);console.log("[SERVICE-WORKER] Popup loaded message received sending level: ",r),chrome.runtime.sendMessage({type:"popup-level",level:r});break;case"adjust-level":console.log("[SERVICE-WORKER] Adjust level message received");var l=await s();await async function(e,o){await chrome.offscreen.hasDocument()?console.log("Offscreen document already exists"):(console.log("Creating offscreen document"),await chrome.offscreen.createDocument({url:"offscreen.html",reasons:["USER_MEDIA"],justification:"Adjust tab audio volume"}),console.log("Created offscreen document"));let s=e.toString(),r=o.toString();if(await a(s))console.log("[WORKER] tab found in activeStreams W/ tabId: ",e),chrome.runtime.sendMessage({type:"adjust-level",target:"offscreen",tabId:e,level:o}),await t(s,r);else{console.log("[WORKER] tab not found in activeStreams W/ tabId: ",e);const a=await chrome.tabCapture.getMediaStreamId({targetTabId:e});chrome.runtime.sendMessage({type:"start-recording",target:"offscreen",data:a,tabId:e,level:o}),await t(s,r)}}(l.id,e.level);break;case"testSave":console.log("[SERVICE-WORKER] Test save message received"),l=await s(),await testSave(l.id);break;case"testGet":console.log("[SERVICE-WORKER] Test get message received"),l=await s(),await testGet(l.id);break;case"clear-storage":console.log("[SERVICE-WORKER] Clear storage message received"),await chrome.storage.local.clear()}}))}},t={};!function a(o){var s=t[o];if(void 0!==s)return s.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,a),r.exports}(626)})(); \ No newline at end of file +(()=>{var e={626:e=>{async function a(e){console.log("[SERVICE-WORKER] Lowshelf function called")}async function t(e,a){let t=await chrome.storage.local.get("levels"),o=null;null==t.levels?o={[e]:a}:(o=t.levels,o[e]=a),await chrome.storage.local.set({levels:o})}async function o(e){let a=(await chrome.storage.local.get("levels")).levels;return null!=a&&null!=a[e]&&(console.log("tablevels: "+a),!0)}async function s(e){let a=(await chrome.storage.local.get("levels")).levels;return!await o(e)||a[e]<0?(console.log("!!Level not found for tabId: ",e),100):(console.log("!!Level found for tabId: ",e),100*a[e])}async function l(){let[e]=await chrome.tabs.query({active:!0,currentWindow:!0});return e}e.exports={worker:function(e,a){return e+a},sum:function(e,a){return e+a},getTabLevel:s,containsTab:o,getCurrentTab:l},chrome.runtime.onStartup.addListener((function(){console.log("Browser opened CLEARING CACHE"),chrome.storage.local.clear()})),new Map,chrome.runtime.onMessage.addListener((async e=>{switch(console.log("Message received from popup"),e.type){case"popup-loaded":let c=await l();var r=await s(c.id);console.log("[SERVICE-WORKER] Popup loaded message received sending level: ",r),chrome.runtime.sendMessage({type:"popup-level",level:r});break;case"adjust-level":console.log("[SERVICE-WORKER] Adjust level message received");var n=await l();await async function(e,a){await async function(){await chrome.offscreen.hasDocument()?console.log("Offscreen document already exists"):(console.log("Creating offscreen document"),await chrome.offscreen.createDocument({url:"offscreen.html",reasons:["USER_MEDIA"],justification:"Adjust tab audio volume"}),console.log("Created offscreen document"))}();let s=e.toString(),l=a.toString();if(await o(s))console.log("[WORKER] tab found in activeStreams W/ tabId: ",e),chrome.runtime.sendMessage({type:"adjust-level",target:"offscreen",tabId:e,level:a}),await t(s,l);else{console.log("[WORKER] tab not found in activeStreams W/ tabId: ",e);const o=await chrome.tabCapture.getMediaStreamId({targetTabId:e});chrome.runtime.sendMessage({type:"start-recording",target:"offscreen",data:o,tabId:e,level:a}),await t(s,l)}}(n.id,e.level);break;case"testSave":console.log("[SERVICE-WORKER] Test save message received"),n=await l(),await testSave(n.id);break;case"testGet":console.log("[SERVICE-WORKER] Test get message received"),n=await l(),await testGet(n.id);break;case"clear-storage":console.log("[SERVICE-WORKER] Clear storage message received"),await chrome.storage.local.clear();break;case"lowshelf-worker":console.log("[SERVICE-WORKER] Lowshelf message received"),await a(),await a(n.id)}}))}},a={};!function t(o){var s=a[o];if(void 0!==s)return s.exports;var l=a[o]={exports:{}};return e[o](l,l.exports,t),l.exports}(626)})(); \ No newline at end of file diff --git a/src/js/worker.js b/src/js/worker.js index 4271ce6..a997854 100644 --- a/src/js/worker.js +++ b/src/js/worker.js @@ -53,9 +53,21 @@ chrome.runtime.onMessage.addListener(async (msg) => { console.log("[SERVICE-WORKER] Clear storage message received"); await chrome.storage.local.clear(); break; + + case "lowshelf-worker": + console.log("[SERVICE-WORKER] Lowshelf message received"); + await lowshelf(); + + await lowshelf(currTab.id); + break; } }); +// Adjust bass frequencies with lowshelf filter +async function lowshelf(tabId){ + console.log("[SERVICE-WORKER] Lowshelf function called"); +} + async function saveTabLevel(tabId, level){ let items = await chrome.storage.local.get('levels'); let tabLevels = null; @@ -100,7 +112,8 @@ async function getTabLevel(tabId){ } } -async function updateTabVolume(tabId, volume){ +// Create offscreen document if it doesn't exist +async function createOffscreenDocument(){ // OFFSCREEN document if (await chrome.offscreen.hasDocument()) { console.log("Offscreen document already exists"); @@ -115,28 +128,30 @@ async function updateTabVolume(tabId, volume){ }); console.log("Created offscreen document"); } +} - let tabIdS = tabId.toString(); - let volumeS = volume.toString(); - // Tab already exits - if(await containsTab(tabIdS)){ - console.log("[WORKER] tab found in activeStreams W/ tabId: ", tabId); - chrome.runtime.sendMessage({ type: 'adjust-level', target: 'offscreen', tabId: tabId, level: volume}); - await saveTabLevel(tabIdS, volumeS); - } - - // Tab doesn't exist - else{ - console.log("[WORKER] tab not found in activeStreams W/ tabId: ", tabId); - // Get a MediaStream for the Active Tab - const streamId = await chrome.tabCapture.getMediaStreamId({ - targetTabId: tabId - }); - - // Send the stream ID to the offscreen document to start recording - chrome.runtime.sendMessage({ type: 'start-recording', target: 'offscreen', data: streamId, tabId: tabId, level: volume}); - await saveTabLevel(tabIdS, volumeS); - } +async function updateTabVolume(tabId, volume){ + await createOffscreenDocument(); + let tabIdS = tabId.toString(); + let volumeS = volume.toString(); + // Tab already exits + if(await containsTab(tabIdS)){ + console.log("[WORKER] tab found in activeStreams W/ tabId: ", tabId); + chrome.runtime.sendMessage({ type: 'adjust-level', target: 'offscreen', tabId: tabId, level: volume}); + await saveTabLevel(tabIdS, volumeS); + } + // Tab doesn't exist + else{ + console.log("[WORKER] tab not found in activeStreams W/ tabId: ", tabId); + // Get a MediaStream for the Active Tab + const streamId = await chrome.tabCapture.getMediaStreamId({ + targetTabId: tabId + }); + + // Send the stream ID to the offscreen document to start recording + chrome.runtime.sendMessage({ type: 'start-recording', target: 'offscreen', data: streamId, tabId: tabId, level: volume}); + await saveTabLevel(tabIdS, volumeS); + } } async function getCurrentTab() {