code cleanup
This commit is contained in:
parent
f1330570d6
commit
b69a03d42f
@ -19,26 +19,17 @@ class CommsServer {
|
|||||||
}[] = [];
|
}[] = [];
|
||||||
popupPort: any;
|
popupPort: any;
|
||||||
|
|
||||||
commands: {[x: string]: ((a: any, b: any) => void | Promise<void>)[]}
|
/**
|
||||||
|
* commands — functions that handle incoming messages
|
||||||
constructor(server) {
|
* functions can have the following arguments, which are,
|
||||||
this.server = server;
|
* in this order:
|
||||||
this.logger = server.logger;
|
* message — the message we received
|
||||||
this.settings = server.settings;
|
* port|sender — on persistent channels, second argument is port on which the server
|
||||||
this.popupPort = null;
|
* listens. If the message was sent in non-persistent way, this is the
|
||||||
|
* sender script/frame/whatever of the message
|
||||||
browser.runtime.onConnect.addListener(p => this.onConnect(p));
|
* sendResponse — callback function on messages received via non-persistent channel
|
||||||
browser.runtime.onMessage.addListener((m, sender) => this.processReceivedMessage_nonpersistent(m, sender));
|
*/
|
||||||
|
commands: {[x: string]: ((a: any, b: any) => void | Promise<void>)[]} = {
|
||||||
// commands — functions that handle incoming messages
|
|
||||||
// functions can have the following arguments, which are,
|
|
||||||
// in this order:
|
|
||||||
// message — the message we received
|
|
||||||
// port|sender — on persistent channels, second argument is port on which the server
|
|
||||||
// listens. If the message was sent in non-persistent way, this is the
|
|
||||||
// sender script/frame/whatever of the message
|
|
||||||
// sendResponse — callback function on messages received via non-persistent channel
|
|
||||||
this.commands = {
|
|
||||||
'announce-zoom': [
|
'announce-zoom': [
|
||||||
(message) => {
|
(message) => {
|
||||||
try {
|
try {
|
||||||
@ -54,6 +45,11 @@ class CommsServer {
|
|||||||
],
|
],
|
||||||
'get-current-site': [
|
'get-current-site': [
|
||||||
async (message, port) => {
|
async (message, port) => {
|
||||||
|
console.info("WILL GET CURRENT SITE AND RETURN:", {
|
||||||
|
cmd: 'set-current-site',
|
||||||
|
site: await this.server.getVideoTab(),
|
||||||
|
tabHostname: await this.getCurrentTabHostname()
|
||||||
|
})
|
||||||
port.postMessage({
|
port.postMessage({
|
||||||
cmd: 'set-current-site',
|
cmd: 'set-current-site',
|
||||||
site: await this.server.getVideoTab(),
|
site: await this.server.getVideoTab(),
|
||||||
@ -137,6 +133,21 @@ class CommsServer {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//#region getters
|
||||||
|
get activeTab() {
|
||||||
|
return browser.tabs.query({currentWindow: true, active: true});
|
||||||
|
}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
constructor(server) {
|
||||||
|
this.server = server;
|
||||||
|
this.logger = server.logger;
|
||||||
|
this.settings = server.settings;
|
||||||
|
|
||||||
|
browser.runtime.onConnect.addListener(p => this.onConnect(p));
|
||||||
|
browser.runtime.onMessage.addListener((m, sender) => this.processReceivedMessage_nonpersistent(m, sender));
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribe(command, callback) {
|
subscribe(command, callback) {
|
||||||
@ -181,9 +192,6 @@ class CommsServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeTab() {
|
|
||||||
return browser.tabs.query({currentWindow: true, active: true});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to addon content scripts.
|
* Sends a message to addon content scripts.
|
||||||
@ -306,7 +314,7 @@ class CommsServer {
|
|||||||
await this.execCmd(message, portOrSender);
|
await this.execCmd(message, portOrSender);
|
||||||
|
|
||||||
if (message.forwardToSameFramePort) {
|
if (message.forwardToSameFramePort) {
|
||||||
this.sendToFrameContentScripts(message, portOrSender.tab.id, portOrSender.frameId, message.port)
|
this.sendToFrameContentScripts(message, portOrSender.tab.id, portOrSender.frameId, message.port);
|
||||||
}
|
}
|
||||||
if (message.forwardToContentScript) {
|
if (message.forwardToContentScript) {
|
||||||
this.logger.log('info', 'comms', "[CommsServer.js::processReceivedMessage] Message has 'forward to content script' flag set. Forwarding message as is. Message:", message);
|
this.logger.log('info', 'comms', "[CommsServer.js::processReceivedMessage] Message has 'forward to content script' flag set. Forwarding message as is. Message:", message);
|
||||||
|
Loading…
Reference in New Issue
Block a user