Minor fixes for comms and mutation detectìon
This commit is contained in:
parent
e269ff3d79
commit
78395e3ea0
@ -106,7 +106,7 @@ export default class EventBus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
send(command: string, commandData: any, context: EventBusContext = {}) {
|
send(command: string, commandData: any, context: EventBusContext = {}) {
|
||||||
context = this.cloneContext(context); // Firefox throws an error if we don't clone the context.
|
// context = this.cloneContext(context); // Firefox throws an error if we don't clone the context.
|
||||||
|
|
||||||
if (context.visitedBusses?.includes(this.uuid)) {
|
if (context.visitedBusses?.includes(this.uuid)) {
|
||||||
console.warn('this bus was already visited before. Doing nothing.');
|
console.warn('this bus was already visited before. Doing nothing.');
|
||||||
@ -116,7 +116,10 @@ export default class EventBus {
|
|||||||
console.warn('this command was already sent');
|
console.warn('this command was already sent');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
context.visitedBusses = [...context.visitedBusses ?? [], this.uuid];
|
|
||||||
|
// we want to avoid re-assigning context.visitedBusses if possible
|
||||||
|
// in order to reduce the amount of garbage that needs to be collected.
|
||||||
|
context.visitedBusses ? context.visitedBusses.push(this.uuid) : context.visitedBusses = [this.uuid];
|
||||||
|
|
||||||
// execute commands we have subscriptions for
|
// execute commands we have subscriptions for
|
||||||
if (this.commands?.[command]) {
|
if (this.commands?.[command]) {
|
||||||
|
|||||||
@ -149,7 +149,11 @@ class CommsClient {
|
|||||||
|
|
||||||
// send to server
|
// send to server
|
||||||
if (!context?.borderCrossings?.commsServer) {
|
if (!context?.borderCrossings?.commsServer) {
|
||||||
|
try {
|
||||||
return chrome?.runtime?.sendMessage(null, message, null);
|
return chrome?.runtime?.sendMessage(null, message, null);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`Failed to send message to background script. Error:`, e, 'data:', {message, context});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,7 @@ class VideoData {
|
|||||||
videoLoaded: boolean = false;
|
videoLoaded: boolean = false;
|
||||||
videoDimensionsLoaded: boolean = false;
|
videoDimensionsLoaded: boolean = false;
|
||||||
active: boolean = false;
|
active: boolean = false;
|
||||||
|
private preventVideoOffsetValidation: boolean = false;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region misc stuff
|
//#region misc stuff
|
||||||
@ -511,6 +512,10 @@ class VideoData {
|
|||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!mutationList) {
|
||||||
|
this.logger.warn('onVideoMutation', 'mutation was triggered, but mutationList is missing. Something is fishy. Mutation will be ignored. Observer:', observer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// verify that mutation didn't remove our class. Some pages like to do that.
|
// verify that mutation didn't remove our class. Some pages like to do that.
|
||||||
let confirmAspectRatioRestore = false;
|
let confirmAspectRatioRestore = false;
|
||||||
@ -590,7 +595,9 @@ class VideoData {
|
|||||||
|
|
||||||
// sometimes something fucky wucky happens and mutations aren't detected correctly, so we
|
// sometimes something fucky wucky happens and mutations aren't detected correctly, so we
|
||||||
// try to get around that
|
// try to get around that
|
||||||
|
this.preventVideoOffsetValidation = true;
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
|
this.preventVideoOffsetValidation = false;
|
||||||
this.validateVideoOffsets();
|
this.validateVideoOffsets();
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
@ -611,6 +618,9 @@ class VideoData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
validateVideoOffsets() {
|
validateVideoOffsets() {
|
||||||
|
if (this.preventVideoOffsetValidation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// validate if current video still exists. If not, we destroy current object
|
// validate if current video still exists. If not, we destroy current object
|
||||||
try {
|
try {
|
||||||
if (! document.body.contains(this.video)) {
|
if (! document.body.contains(this.video)) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user