2018-05-27 01:29:02 +02:00
if ( Debug . debug ) {
console . log ( "Loading Comms.js" )
}
2018-05-26 23:08:49 +02:00
class CommsClient {
constructor ( name ) {
this . port = browser . runtime . connect ( { name : name } ) ;
var ths = this ;
this . port . onMessage . addListener ( m => ths . processReceivedMessage ( m ) ) ;
this . hasSettings = false ;
}
setPageInfo ( pageInfo ) {
this . pageInfo = pageInfo ;
}
processReceivedMessage ( message ) {
if ( Debug . debug && Debug . comms ) {
console . log ( "[CommsClient.js::processMessage] Received message from background script!" , message ) ;
}
2018-07-15 16:22:32 +02:00
if ( message . cmd === "set-ar" ) {
2018-05-27 01:29:02 +02:00
this . pageInfo . setAr ( message . ratio ) ;
2018-07-15 16:22:32 +02:00
} else if ( message . cmd === 'set-video-float' ) {
ExtensionConf . miscFullscreenSettings . videoFloat = message . newFloat ;
this . pageInfo . restoreAr ( ) ;
2018-05-26 23:08:49 +02:00
} else if ( message . cmd === "has-videos" ) {
} else if ( message . cmd === "set-config" ) {
this . hasSettings = true ;
ExtensionConf = message . conf ;
2018-06-27 23:55:37 +02:00
// this.pageInfo.reset();
2018-05-26 23:08:49 +02:00
} else if ( message . cmd === "set-stretch" ) {
2018-05-27 21:41:08 +02:00
this . pageInfo . setStretchMode ( StretchMode [ message . mode ] ) ;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === "autoar-start" ) {
2018-05-26 23:08:49 +02:00
if ( message . enabled !== false ) {
this . pageInfo . initArDetection ( ) ;
this . pageInfo . startArDetection ( ) ;
} else {
this . pageInfo . stopArDetection ( ) ;
}
} else if ( message . cmd === "pause-processing" ) {
this . pageInfo . pauseProcessing ( ) ;
} else if ( message . cmd === "resume-processing" ) {
// todo: autoArStatus
this . pageInfo . resumeProcessing ( message . autoArStatus ) ;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === "reload-settings" ) {
ExtensionConf = message . newConf ;
this . pageInfo . reset ( ) ;
2018-06-27 23:55:37 +02:00
if ( ExtensionConf . arDetect . mode === "disabled" ) {
this . pageInfo . stopArDetection ( ) ;
} else {
this . pageInfo . startArDetection ( ) ;
}
2018-05-26 23:08:49 +02:00
}
}
async waitForSettings ( ) {
var t = this ;
return new Promise ( async ( resolve , reject ) => {
while ( true ) {
await t . sleep ( 100 ) ;
if ( this . hasSettings ) {
resolve ( ) ;
break ;
}
}
} ) ;
}
async sleep ( n ) {
return new Promise ( ( resolve , reject ) => setTimeout ( resolve , n ) ) ;
}
async sendMessage _nonpersistent ( message ) {
if ( BrowserDetect . firefox ) {
return browser . runtime . sendMessage ( message )
} else {
return new Promise ( ( resolve , reject ) => {
try {
if ( BrowserDetect . edge ) {
browser . runtime . sendMessage ( message , function ( response ) {
var r = response ;
resolve ( r ) ;
} ) ;
} else {
chrome . runtime . sendMessage ( message , function ( response ) {
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response ;
resolve ( r ) ;
} ) ;
}
}
catch ( e ) {
reject ( e ) ;
}
} ) ;
}
}
async requestSettings ( ) {
if ( Debug . debug ) {
2018-05-27 01:29:02 +02:00
console . log ( "%c[CommsClient::requestSettings] sending request for congif!" , "background: #11D; color: #aad" ) ;
2018-05-26 23:08:49 +02:00
}
var response = await this . sendMessage _nonpersistent ( { cmd : 'get-config' } ) ;
if ( Debug . debug ) {
2018-05-27 01:29:02 +02:00
console . log ( "%c[CommsClient::requestSettings] received settings response!" , "background: #11D; color: #aad" , response ) ;
2018-05-26 23:08:49 +02:00
}
if ( ! response || response . extensionConf ) {
return Promise . resolve ( false ) ;
}
ExtensionConf = JSON . parse ( response . extensionConf ) ;
return Promise . resolve ( true ) ;
}
async requestSettings _fallback ( ) {
this . port . postMessage ( { cmd : "get-config" } ) ;
}
registerVideo ( ) {
this . port . postMessage ( { cmd : "has-video" } ) ;
}
unregisterVideo ( ) {
this . port . postMessage ( { cmd : "noVideo" } ) ; // ayymd
}
}
class CommsServer {
constructor ( server ) {
this . server = server ;
this . ports = [ ] ;
var ths = this ;
if ( BrowserDetect . firefox ) {
browser . runtime . onConnect . addListener ( p => ths . onConnect ( p ) ) ;
browser . runtime . onMessage . addListener ( m => ths . processReceivedMessage _nonpersistent _ff ( m ) ) ;
} else {
chrome . runtime . onConnect . addListener ( p => ths . onConnect ( p ) ) ;
chrome . runtime . onMessage . addListener ( ( msg , sender , callback ) => ths . processReceivedMessage _nonpersistent _chrome ( m , sender , callback ) ) ;
}
}
2018-06-27 23:55:37 +02:00
async getCurrentTabUrl ( ) {
}
2018-05-26 23:56:50 +02:00
sendToAll ( message ) {
2018-06-28 23:43:52 +02:00
for ( var p of this . ports ) {
for ( var frame in p ) {
2018-05-26 23:56:50 +02:00
p [ frame ] . postMessage ( message ) ;
}
}
}
sendToActive ( message ) {
2018-05-27 01:29:02 +02:00
if ( Debug . debug && Debug . comms ) {
console . log ( "%c[CommsServer::sendToActive] trying to send a message to active tab. Message:" , "background: #dda; color: #11D" , message ) ;
}
2018-05-26 23:56:50 +02:00
if ( BrowserDetect . firefox ) {
this . _sendToActive _ff ( message ) ;
} else if ( BrowserDetect . chrome ) {
}
}
async _sendToActive _ff ( message ) {
2018-05-27 01:29:02 +02:00
var tabs = await browser . tabs . query ( { currentWindow : true , active : true } ) ;
if ( Debug . debug && Debug . comms ) {
console . log ( "[CommsServer::_sendToActive_ff] currently active tab(s)?" , tabs ) ;
for ( var key in this . ports [ tabs [ 0 ] . id ] ) {
console . log ( "key?" , key , this . ports [ tabs [ 0 ] . id ] ) ;
// this.ports[tabs[0].id][key].postMessage(message);
}
}
for ( var key in this . ports [ tabs [ 0 ] . id ] ) {
2018-05-26 23:56:50 +02:00
this . ports [ tabs [ 0 ] . id ] [ key ] . postMessage ( message ) ;
}
}
async queryTabs _chrome ( tabInfo ) {
return new Promise ( function ( resolve , reject ) {
browser . tabs . query ( tabInfo , function ( response ) {
browser . tabs . query ( tabInfo ) ;
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response ;
resolve ( r ) ;
} ) ;
} ) ;
}
2018-05-26 23:08:49 +02:00
onConnect ( port ) {
2018-05-27 01:29:02 +02:00
var ths = this ;
// poseben primer | special case
if ( port . name === 'popup-port' ) {
this . popupPort = port ;
this . popupPort . onMessage . addListener ( ( m , p ) => ths . processReceivedMessage ( m , p ) ) ;
return ;
}
2018-05-26 23:08:49 +02:00
var tabId = port . sender . tab . id ;
2018-05-26 23:56:50 +02:00
var frameId = port . sender . frameId ;
if ( ! this . ports [ tabId ] ) {
this . ports [ tabId ] = { } ;
}
this . ports [ tabId ] [ frameId ] = port ;
this . ports [ tabId ] [ frameId ] . onMessage . addListener ( ( m , p ) => ths . processReceivedMessage ( m , p ) ) ;
this . ports [ tabId ] [ frameId ] . onDisconnect . addListener ( ( p ) => {
delete ths . ports [ p . sender . tab . id ] [ p . sender . frameId ] ;
if ( Object . keys ( ths . ports [ p . sender . tab . id ] ) . length === 0 ) {
ths . ports [ tabId ] = undefined ;
}
} ) ;
2018-05-26 23:08:49 +02:00
}
processReceivedMessage ( message , port ) {
if ( Debug . debug && Debug . comms ) {
console . log ( "[CommsServer.js::processMessage] Received message from background script!" , message , "port" , port ) ;
}
if ( message . cmd === 'get-config' ) {
2018-06-27 23:55:37 +02:00
port . postMessage ( { cmd : "set-config" , conf : ExtensionConf , site : this . server . currentSite } )
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === 'set-stretch' ) {
2018-05-27 21:41:08 +02:00
this . sendToActive ( message ) ;
2018-06-29 00:30:42 +02:00
} else if ( message . cmd === 'set-stretch-default' ) {
ExtensionConf . stretch . initialMode = message . mode ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === 'set-ar' ) {
2018-05-27 01:29:02 +02:00
this . sendToActive ( message ) ;
2018-07-09 23:30:11 +02:00
} else if ( message . cmd === 'set-custom-ar' ) {
ExtensionConf . keyboard . shortcuts . q . arg = message . ratio ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-07-15 16:22:32 +02:00
} else if ( message . cmd === 'set-video-float' ) {
this . sendToActive ( message ) ;
ExtensionConf . miscFullscreenSettings . videoFloat = message . newFloat ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === 'autoar-start' ) {
2018-05-27 01:29:02 +02:00
this . sendToActive ( message ) ;
2018-06-27 23:55:37 +02:00
} else if ( message . cmd === "autoar-enable" ) { // LEGACY - can be removed prolly?
2018-06-15 00:33:10 +02:00
ExtensionConf . arDetect . mode = "blacklist" ;
Settings . save ( ExtensionConf ) ;
2018-06-29 00:30:42 +02:00
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-06-27 23:55:37 +02:00
} else if ( message . cmd === "autoar-disable" ) { // LEGACY - can be removed prolly?
2018-06-15 00:33:10 +02:00
ExtensionConf . arDetect . mode = "disabled" ;
if ( message . reason ) {
ExtensionConf . arDetect . disabledReason = message . reason ;
} else {
ExtensionConf . arDetect . disabledReason = 'User disabled' ;
}
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
} else if ( message . cmd === "autoar-set-interval" ) {
if ( Debug . debug )
console . log ( "[uw-bg] trying to set new interval for autoAr. New interval is" , message . timeout , "ms" ) ;
// set fairly liberal limit
var timeout = message . timeout < 4 ? 4 : message . timeout ;
ExtensionConf . arDetect . timer _playing = timeout ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-06-27 23:55:37 +02:00
} else if ( message . cmd === "set-autoar-defaults" ) {
ExtensionConf . arDetect . mode = message . mode ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } )
} else if ( message . cmd === "set-autoar-for-site" ) {
2018-06-28 23:43:52 +02:00
if ( ExtensionConf . sites [ this . server . currentSite ] ) {
ExtensionConf . sites [ this . server . currentSite ] . arStatus = message . mode ;
Settings . save ( ExtensionConf ) ;
} else {
ExtensionConf . sites [ this . server . currentSite ] = {
status : "default" ,
arStatus : message . mode ,
statusEmbedded : "default"
} ;
Settings . save ( ExtensionConf ) ;
}
2018-06-27 23:55:37 +02:00
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } ) ;
} else if ( message . cmd === "set-extension-defaults" ) {
2018-06-28 23:43:52 +02:00
ExtensionConf . extensionMode = message . mode ;
2018-06-27 23:55:37 +02:00
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } )
} else if ( message . cmd === "set-extension-for-site" ) {
2018-06-28 23:43:52 +02:00
if ( ExtensionConf . sites [ this . server . currentSite ] ) {
ExtensionConf . sites [ this . server . currentSite ] . status = message . mode ;
Settings . save ( ExtensionConf ) ;
} else {
ExtensionConf . sites [ this . server . currentSite ] = {
status : message . mode ,
arStatus : "default" ,
statusEmbedded : message . mode
} ;
Settings . save ( ExtensionConf ) ;
console . log ( "SAVING PER-SITE OPTIONS," , this . server . currentSite , ExtensionConf . sites [ this . server . currentSite ] )
}
2018-06-27 23:55:37 +02:00
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } ) ;
2018-05-27 01:29:02 +02:00
}
2018-06-28 23:43:52 +02:00
if ( message . cmd . startsWith ( 'set-' ) ) {
port . postMessage ( { cmd : "set-config" , conf : ExtensionConf , site : this . server . currentSite } ) ;
}
2018-05-26 23:08:49 +02:00
}
processReceivedMessage _nonpersistent _ff ( message , sender ) {
if ( Debug . debug && Debug . comms ) {
2018-05-27 01:29:02 +02:00
console . log ( "%c[CommsServer.js::processMessage_nonpersistent_ff] Received message from background script!" , "background-color: #11D; color: #aad" , message , sender ) ;
2018-05-26 23:08:49 +02:00
}
if ( message . cmd === 'get-config' ) {
var ret = { extensionConf : JSON . stringify ( ExtensionConf ) } ;
if ( Debug . debug && Debug . comms ) {
2018-05-27 01:29:02 +02:00
console . log ( "%c[CommsServer.js::processMessage_nonpersistent_ff] Returning this:" , "background-color: #11D; color: #aad" , ret ) ;
2018-05-26 23:08:49 +02:00
}
Promise . resolve ( ret ) ;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === "autoar-enable" ) {
ExtensionConf . arDetect . mode = "blacklist" ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } )
if ( Debug . debug ) {
console . log ( "[uw-bg] autoar set to enabled (blacklist). evidenz:" , ExtensionConf ) ;
}
} else if ( message . cmd === "autoar-disable" ) {
ExtensionConf . arDetect . mode = "disabled" ;
if ( message . reason ) {
ExtensionConf . arDetect . disabledReason = message . reason ;
} else {
ExtensionConf . arDetect . disabledReason = 'User disabled' ;
}
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
if ( Debug . debug ) {
console . log ( "[uw-bg] autoar set to disabled. evidenz:" , ExtensionConf ) ;
}
} else if ( message . cmd === "autoar-set-interval" ) {
if ( Debug . debug )
console . log ( "[uw-bg] trying to set new interval for autoAr. New interval is" , message . timeout , "ms" ) ;
// set fairly liberal limit
var timeout = message . timeout < 4 ? 4 : message . timeout ;
ExtensionConf . arDetect . timer _playing = timeout ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-05-26 23:56:50 +02:00
}
2018-05-26 23:08:49 +02:00
}
processReceivedMessage _nonpersistent _chrome ( message , sender , sendResponse ) {
if ( Debug . debug && Debug . comms ) {
console . log ( "[CommsServer.js::processMessage_nonpersistent_chrome] Received message from background script!" , message ) ;
}
if ( message . cmd === 'get-config' ) {
2018-06-27 23:55:37 +02:00
sendResponse ( { extensionConf : JSON . stringify ( ExtensionConf ) , site : getCurrentTabUrl ( ) } ) ;
2018-05-26 23:08:49 +02:00
// return true;
2018-06-15 00:33:10 +02:00
} else if ( message . cmd === "autoar-enable" ) {
ExtensionConf . arDetect . mode = "blacklist" ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : "reload-settings" , sender : "uwbg" } )
if ( Debug . debug ) {
console . log ( "[uw-bg] autoar set to enabled (blacklist). evidenz:" , ExtensionConf ) ;
}
} else if ( message . cmd === "autoar-disable" ) {
ExtensionConf . arDetect . mode = "disabled" ;
if ( message . reason ) {
ExtensionConf . arDetect . disabledReason = message . reason ;
} else {
ExtensionConf . arDetect . disabledReason = 'User disabled' ;
}
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
if ( Debug . debug ) {
console . log ( "[uw-bg] autoar set to disabled. evidenz:" , ExtensionConf ) ;
}
} else if ( message . cmd === "autoar-set-interval" ) {
if ( Debug . debug )
console . log ( "[uw-bg] trying to set new interval for autoAr. New interval is" , message . timeout , "ms" ) ;
// set fairly liberal limit
var timeout = message . timeout < 4 ? 4 : message . timeout ;
ExtensionConf . arDetect . timer _playing = timeout ;
Settings . save ( ExtensionConf ) ;
this . sendToAll ( { cmd : 'reload-settings' , newConf : ExtensionConf } ) ;
2018-05-26 23:08:49 +02:00
}
}
}
2018-05-27 01:29:02 +02:00
class Comms {
static async sendMessage ( message ) {
if ( BrowserDetect . firefox ) {
return browser . runtime . sendMessage ( message )
} else {
return new Promise ( ( resolve , reject ) => {
try {
if ( BrowserDetect . edge ) {
browser . runtime . sendMessage ( message , function ( response ) {
var r = response ;
resolve ( r ) ;
} ) ;
} else {
chrome . runtime . sendMessage ( message , function ( response ) {
// Chrome/js shittiness mitigation — remove this line and an empty array will be returned
var r = response ;
resolve ( r ) ;
} ) ;
}
}
catch ( e ) {
reject ( e ) ;
}
} ) ;
}
}
2018-01-06 22:58:31 +01:00
2018-05-27 01:29:02 +02:00
}
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_queryTabs = async function(tabInfo){
// if(BrowserDetect.usebrowser != "firefox"){
// return await _com_chrome_tabquery_wrapper(tabInfo);
// }
// else{
// return browser.tabs.query(tabInfo);
// }
// }
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_getActiveTab = async function(tabInfo){
// if(BrowserDetect.firefox){
// return await browser.tabs.query({currentWindow: true, active: true});
// }
// return _com_chrome_tabquery_wrapper({currentWindow: true, active: true});
// }
2018-01-26 00:09:08 +01:00
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_chrome_tabs_sendmsg_wrapper = async function(tab, message, options){
// return new Promise(function (resolve, reject){
// try{
// browser.tabs.sendMessage(tab, message, /*options, */function(response){
// console.log("TESTING what is this owo? (response)", response);
2018-01-08 22:48:45 +01:00
2018-06-15 00:33:10 +02:00
// // Chrome/js shittiness mitigation — remove this line and an empty array will be returned
// var r = response;
2018-01-08 22:48:45 +01:00
2018-06-15 00:33:10 +02:00
// resolve(r);
// });
// }
// catch(e){
// reject(e);
// }
// });
// }
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_sendMessage = async function(tab, message, options){
// if(BrowserDetect.usebrowser != "firefox"){
// var r = await _com_chrome_tabs_sendmsg_wrapper(tab, message, options);
// console.log("TESTING what is this owo? (should be a promise)", r);
// return r;
// }
// else{
// return browser.tabs.sendMessage(tab, message, options);
// }
// }
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_chrome_tabs_sendmsgrt_wrapper = async function(message){
// return new Promise(function (resolve, reject){
// try{
// browser.runtime.sendMessage(message, function(response){
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// // Chrome/js shittiness mitigation — remove this line and an empty array will be returned
// var r = response;
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// resolve(r);
// });
// }
// catch(e){
// reject(e);
// }
// });
// }
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// var _com_sendMessageRuntime = async function(message){
// if(BrowserDetect.usebrowser != "firefox"){
// return _com_chrome_tabs_sendmsgrt_wrapper(message);
// }
// else{
// return browser.runtime.sendMessage(message);
// }
// }
2018-01-06 22:58:31 +01:00
2018-06-15 00:33:10 +02:00
// // pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku. Vrne tisti odgovor od tistega okvira, ki prispe prvi.
// // sends a message to all frames in the currently opened tab. Returns the response of a frame that replied first
// var _com_sendToAllFrames = async function(message) {
// if(Debug.debug)
// console.log("[Comms::_com_sendToAllFrames] sending message to all frames of currenntly active tab");
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// if(Debug.debug)
// console.log("[Comms::_com_sendToAllFrames] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// var response = await browser.tabs.sendMessage(tabs[0].id, message);
// console.log("[Comms::_com_sendToAllFrames] response is this:",response);
// return response;
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// // if(BrowserDetect.firefox){
// // return
// // }
// }
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// // pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku in vrne _vse_ odgovore
// // sends a message to all frames in currently opened tab and returns all responses
// var _com_sendToEachFrame = async function(message, tabId) {
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] sending message to every frames of currenntly active tab");
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// if(tabId === undefined){
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
// tabId = tabs[0].id;
// }
// var frames = await browser.webNavigation.getAllFrames({tabId: tabId});
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] we have this many frames:", frames.length, "||| tabId:", tabId ,"frames:",frames);
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// // pošlji sporočilce vsakemu okvirju, potisni obljubo v tabelo
// // send message to every frame, push promise to array
// var promises = [];
// for(var frame of frames){
// if(Debug.debug)
// console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
// try{
// promises.push(browser.tabs.sendMessage(tabId, message, {frameId: frame.frameId}));
// }
// catch(e){
// if(Debug.debug)
// console.log("[Comms:_com_sendToEachFrame] we sending message to tab with id", tabId, ", frame with id", frame.frameId);
// }
// }
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// // počakajmo, da so obljube izpolnjene.
// // wait for all promises to be kept
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// var responses = [];
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// for(var promise of promises){
// var response = await promise;
// if(response !== undefined)
// responses.push(response);
// }
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// if(Debug.debug)
// console.log("[Comms::_com_sendToEveryFrame] we received responses from all frames", responses);
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// return responses;
// }
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// var _com_sendToMainFrame = async function(message, tabId){
// if(Debug.debug)
// console.log("[Comms::_com_sendToMainFrame] sending message to every frames of currenntly active tab");
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// if(tabId === undefined){
// var tabs = await browser.tabs.query({currentWindow: true, active: true});
// tabId = tabs[0].id;
// }
2018-02-01 00:26:16 +01:00
2018-06-15 00:33:10 +02:00
// // pošlji sporočilce glavnemu okvirju. Glavni okvir ima id=0
// // send message to the main frame. Main frame has id=0
// try{
// var response = await browser.tabs.sendMessage(tabId, message, {frameId: 0});
// console.log("[Comms::_com_sendToMainFrame] response is this:",response);
2018-01-24 23:15:54 +01:00
2018-06-15 00:33:10 +02:00
// }
// catch(e){
// console.log("[Comms:_com_sendToEachFrame] failed sending message to tab with id", tabId, ", frame with id", 0, "\nerror:",e);
// }
// return response;
// }
2018-01-24 23:15:54 +01:00
2018-05-26 23:08:49 +02:00
// var Comms = {
// getActiveTab: _com_getActiveTab,
// sendToBackgroundScript: _com_sendMessageRuntime,
// queryTabs: _com_queryTabs,
// sendMessage: _com_sendMessage,
// sendMessageRuntime: _com_sendMessageRuntime,
// sendToEach: _com_sendToEachFrame,
// sendToAll: _com_sendToAllFrames,
// sendToMain: _com_sendToMainFrame,
// }