mirror of https://github.com/vector-im/riot-web
Split service worker post message handling out to function
parent
80dd41508b
commit
0395ee450e
|
@ -58,27 +58,29 @@ export default class WebPlatform extends VectorBasePlatform {
|
|||
return r;
|
||||
})
|
||||
.then((r) => {
|
||||
navigator.serviceWorker.addEventListener("message", (e) => {
|
||||
try {
|
||||
if (e.data?.["type"] === "userinfo" && e.data?.["responseKey"]) {
|
||||
const userId = localStorage.getItem("mx_user_id");
|
||||
const deviceId = localStorage.getItem("mx_device_id");
|
||||
r.active!.postMessage({
|
||||
responseKey: e.data["responseKey"],
|
||||
userId,
|
||||
deviceId,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error responding to service worker: ", e);
|
||||
}
|
||||
});
|
||||
navigator.serviceWorker.addEventListener("message", this.onServiceWorkerPostMessage.bind(this));
|
||||
})
|
||||
.catch((e) => console.error("Error registering/updating service worker:", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onServiceWorkerPostMessage(event: MessageEvent): void {
|
||||
try {
|
||||
if (event.data?.["type"] === "userinfo" && event.data?.["responseKey"]) {
|
||||
const userId = localStorage.getItem("mx_user_id");
|
||||
const deviceId = localStorage.getItem("mx_device_id");
|
||||
event.source!.postMessage({
|
||||
responseKey: event.data["responseKey"],
|
||||
userId,
|
||||
deviceId,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error responding to service worker: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
public getHumanReadableName(): string {
|
||||
return "Web Platform"; // no translation required: only used for analytics
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue