Recall browserID from backend if it suddenly disappears

This commit is contained in:
2022-07-25 19:28:39 +00:00
parent 5ecf24d501
commit ae916a3900
5 changed files with 67 additions and 1 deletions

View File

@@ -20,10 +20,23 @@ export const BrowserIDMixin = (SuperClass) => {
}
}
async recall_id() {
// If the connection is still open, but the BrowserID has disappeared - recall it from the backend
// This happens e.g. when the frontend cache is reset in the Compainon app
if (!this.connection) return;
const recalledID = await this.connection.sendMessagePromise({
type: "browser_mod/recall_id",
});
if (recalledID) {
localStorage[ID_STORAGE_KEY] = recalledID;
}
}
get browserID() {
if (document.querySelector("hc-main")) return "CAST";
if (localStorage[ID_STORAGE_KEY]) return localStorage[ID_STORAGE_KEY];
this.browserID = "";
this.recall_id();
return this.browserID;
}
set browserID(id) {

View File

@@ -16,6 +16,11 @@ export const ConnectionMixin = (SuperClass) => {
return;
const dt = new Date();
console.log(`${dt.toLocaleTimeString()}`, ...args);
this.connection.sendMessage({
type: "browser_mod/log",
message: args[0],
});
}
private fireEvent(event, detail = undefined) {