diff --git a/package.json b/package.json index 72a936b..b5ba070 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ }, "dependencies": { "@servie/events": "^1.0.0", - "async-call-rpc": "^1.0.4", + "async-call-rpc": "^4.0.0", "concurrent-lock": "^1.0.7", "jsx-jsonml-devtools-renderer": "^1.4.1", "lodash-es": "^4.17.15", diff --git a/src/Extension/AutomatedTabTask.ts b/src/Extension/AutomatedTabTask.ts index 2217616..ce0ed3e 100644 --- a/src/Extension/AutomatedTabTask.ts +++ b/src/Extension/AutomatedTabTask.ts @@ -133,7 +133,10 @@ export function AutomatedTabTask Pr } const AsyncCallKey = AsyncCallOptions.key const REGISTER = AsyncCallKey + ':ping' - const finalAsyncCallOptions = { messageChannel: new MessageCenter(false), ...AsyncCallOptions } + const finalAsyncCallOptions: AsyncCallOptions = { + channel: new MessageCenter(false, AsyncCallKey).eventBasedChannel, + ...AsyncCallOptions, + } if (GetContext() === 'content') { // If run in content script // Register this tab diff --git a/src/Extension/MessageCenter.ts b/src/Extension/MessageCenter.ts index f65b987..871b256 100644 --- a/src/Extension/MessageCenter.ts +++ b/src/Extension/MessageCenter.ts @@ -1,5 +1,5 @@ import { Emitter } from '@servie/events' -import { NoSerialization } from 'async-call-rpc' +import { NoSerialization, EventBasedChannel } from 'async-call-rpc' /** * Define how to do serialization and deserialization of remote procedure call */ @@ -8,12 +8,12 @@ export interface Serialization { * Do serialization * @param from - original data */ - serialization(from: any): PromiseLike + serialization(from: any): unknown | PromiseLike /** * Do deserialization * @param serialized - Serialized data */ - deserialization(serialized: unknown): PromiseLike + deserialization(serialized: unknown): unknown | PromiseLike } type InternalMessageType = { key: string @@ -102,7 +102,7 @@ export class MessageCenter { if (typeof browser !== 'undefined') { browser.runtime?.sendMessage?.(serialized).catch(noop) // Send message to Content Script - browser.tabs?.query({ discarded: false }).then(tabs => { + browser.tabs?.query({ discarded: false }).then((tabs) => { for (const tab of tabs) { if (tab.id !== undefined) browser.tabs.sendMessage(tab.id, serialized).catch(noop) } @@ -120,4 +120,8 @@ export class MessageCenter { this.log = on return this } + eventBasedChannel: EventBasedChannel = { + on: (e) => this.on('__async-call' as any, e), + send: (e) => this.emit('__async-call' as any, e as any), + } } diff --git a/yarn.lock b/yarn.lock index 6866277..03f1e68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -887,10 +887,10 @@ astral-regex@^1.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== -async-call-rpc@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/async-call-rpc/-/async-call-rpc-1.0.4.tgz#ded3ef0fac75d0ae90e0ac574adda1ffae4a5cc9" - integrity sha512-dsLSfuF+n1GmgsL5Y+uGCkd+/wYZtHObKPxUncEoJ05bb1Lk3wUlU4ppTXL5sBsRuIXPEUxEdb6w86d0u59udg== +async-call-rpc@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/async-call-rpc/-/async-call-rpc-4.0.0.tgz#825aecfd54bed4873b70ae027ca5a4d0655949e4" + integrity sha512-sDNNa5BIgUYknloEAacx4ool/CKU+IZF8tzbvVGPO8s0ivTcKse7YLsG1U9aBcrXtkdAdqR1nEFNmTdZO6CycA== asynckit@^0.4.0: version "0.4.0"