aa
Some checks failed
test / Run tests (push) Failing after 11s
build / Build (push) Failing after 16s
Some checks failed
test / Run tests (push) Failing after 11s
build / Build (push) Failing after 16s
This commit is contained in:
parent
3a41bf0f21
commit
fcf9f6fd63
@ -14,7 +14,6 @@ export class Broker {
|
||||
LoggerCore.getInstance().logger({ service: "messageQueue" }).debug("subscribe", { topic });
|
||||
const con = await this.msg.connect({ action: "messageQueue", data: { action: "subscribe", topic } });
|
||||
con.onMessage((msg: { action: string; topic: string; message: any }) => {
|
||||
console.log(msg);
|
||||
if (msg.action === "message") {
|
||||
handler(msg.message);
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ export class WindowMessage implements Message {
|
||||
) {
|
||||
// 监听消息
|
||||
this.source.addEventListener("message", (e) => {
|
||||
console.log(e);
|
||||
if (e.source === this.target || e.source === this.source) {
|
||||
this.messageHandle(e.data, new WindowPostMessage(this.target));
|
||||
}
|
||||
@ -169,11 +168,10 @@ export class ServiceWorkerMessageSend implements MessageSend {
|
||||
constructor() {}
|
||||
|
||||
async init() {
|
||||
const list = await clients.matchAll();
|
||||
const list = await self.clients.matchAll({ includeUncontrolled: true, type: "window" });
|
||||
this.target = list[0];
|
||||
console.log(this.target);
|
||||
addEventListener("message", (e) => {
|
||||
console.log(e);
|
||||
self.addEventListener("message", (e) => {
|
||||
console.log("serviceWorker", e);
|
||||
this.messageHandle(e.data);
|
||||
});
|
||||
}
|
||||
|
@ -87,12 +87,11 @@ export default class GMApi {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function sendMessageToOffscreen(action: string, data?: any) {
|
||||
// service_worker和offscreen同时监听消息,会导致消息被两边同时接收,但是返回结果时会产生问题,导致报错
|
||||
// 不进行监听的话又无法从service_worker主动发送消息
|
||||
// 所以这里通过clients.matchAll()获取到所有的client,然后通过postMessage发送消息
|
||||
const list = await clients.matchAll();
|
||||
const list = await clients.matchAll({ includeUncontrolled: true, type: "window" });
|
||||
list[0].postMessage({
|
||||
type: "sendMessage",
|
||||
data: { action, data },
|
||||
|
Loading…
x
Reference in New Issue
Block a user