registering tab — working with youtube only
This commit is contained in:
parent
06cfb9a04e
commit
0f996f3067
@ -128,6 +128,10 @@ class CommsClient {
|
|||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerTab() {
|
||||||
|
this.port.postMessage({cmd: "register-tab", url: location.hostname});
|
||||||
|
}
|
||||||
|
|
||||||
registerVideo(){
|
registerVideo(){
|
||||||
this.port.postMessage({cmd: "has-video"});
|
this.port.postMessage({cmd: "has-video"});
|
||||||
}
|
}
|
||||||
@ -155,8 +159,24 @@ class CommsServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCurrentTabUrl() {
|
async getCurrentTabHostname() {
|
||||||
|
const activeTab = await this._getActiveTab();
|
||||||
|
|
||||||
|
const url = activeTab[0].url;
|
||||||
|
|
||||||
|
var hostname;
|
||||||
|
|
||||||
|
if (url.indexOf("://") > -1) { //find & remove protocol (http, ftp, etc.) and get hostname
|
||||||
|
hostname = url.split('/')[2];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hostname = url.split('/')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
hostname = hostname.split(':')[0]; //find & remove port number
|
||||||
|
hostname = hostname.split('?')[0]; //find & remove "?"
|
||||||
|
|
||||||
|
return hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendToAll(message){
|
sendToAll(message){
|
||||||
@ -224,7 +244,7 @@ class CommsServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processReceivedMessage(message, port){
|
async processReceivedMessage(message, port){
|
||||||
if (Debug.debug && Debug.comms) {
|
if (Debug.debug && Debug.comms) {
|
||||||
console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port, "\nsettings and server:", this.settings,this.server);
|
console.log("[CommsServer.js::processMessage] Received message from background script!", message, "port", port, "\nsettings and server:", this.settings,this.server);
|
||||||
}
|
}
|
||||||
@ -233,6 +253,25 @@ class CommsServer {
|
|||||||
port.postMessage({cmd: 'set-current-site', site: this.server.currentSite});
|
port.postMessage({cmd: 'set-current-site', site: this.server.currentSite});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(message.cmd === 'register-tab') {
|
||||||
|
if(Debug.debug) { // we want to get these messages always when debugging
|
||||||
|
console.log("[Comms::processReceivedMessage] registering tab with hostname", message.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentUrl = await this.getCurrentTabHostname();
|
||||||
|
if (message.url === currentUrl) {
|
||||||
|
this.server.url = message.url;
|
||||||
|
|
||||||
|
if(Debug.debug) { // we want to get these messages always when debugging
|
||||||
|
console.log("[Comms::processReceivedMessage] hostname matches currently active tab. active:", currentUrl, "message:", message.url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(Debug.debug) { // we want to get these messages always when debugging
|
||||||
|
console.log("[Comms::processReceivedMessage] hostnames don't match. active:", currentUrl, "message:", message.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (message.cmd === 'get-config') {
|
if (message.cmd === 'get-config') {
|
||||||
if(Debug.debug) {
|
if(Debug.debug) {
|
||||||
console.log("CommsServer: received get-config. Active settings?", this.settings.active, "\n(settings:", this.settings, ")")
|
console.log("CommsServer: received get-config. Active settings?", this.settings.active, "\n(settings:", this.settings, ")")
|
||||||
|
@ -18,8 +18,11 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(this.videos.length > 0){
|
if(this.videos.length > 0){
|
||||||
|
console.log("registering video")
|
||||||
comms.registerVideo();
|
comms.registerVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
comms.registerTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
@ -118,7 +121,6 @@ class PageInfo {
|
|||||||
this.videos = this.videos.filter( vid => vid.destroyed === false);
|
this.videos = this.videos.filter( vid => vid.destroyed === false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
scheduleRescan(rescanReason){
|
scheduleRescan(rescanReason){
|
||||||
if(rescanReason != RescanReason.PERIODIC){
|
if(rescanReason != RescanReason.PERIODIC){
|
||||||
this.rescan(rescanReason);
|
this.rescan(rescanReason);
|
||||||
|
Loading…
Reference in New Issue
Block a user