You've already forked bilibili-subtitle
优化
This commit is contained in:
@@ -17,7 +17,7 @@ type L2MethodHandlers<L2ReqMsg, L2ResMsg> = {
|
||||
[key: string]: L2MethodHandler<L2ReqMsg, L2ResMsg>
|
||||
}
|
||||
|
||||
class ExtensionMessage {
|
||||
class ExtensionMessaging {
|
||||
portIdToPort: Map<string, PortContext<L2ReqMsg, L2ResMsg>> = new Map()
|
||||
methods?: L2MethodHandlers<L2ReqMsg, L2ResMsg>
|
||||
|
||||
@@ -130,4 +130,4 @@ class ExtensionMessage {
|
||||
}
|
||||
}
|
||||
|
||||
export default ExtensionMessage
|
||||
export default ExtensionMessaging
|
@@ -1,7 +1,7 @@
|
||||
import Layer1Protocol from '../layer1/Layer1Protocol'
|
||||
import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_HANDSHAKE, MESSAGE_TO_EXTENSION_ROUTE, TAG_TARGET_APP, TAG_TARGET_INJECT } from '../const'
|
||||
|
||||
class InjectMessage {
|
||||
class InjectMessaging {
|
||||
port?: chrome.runtime.Port
|
||||
portMessageHandler?: Layer1Protocol<L2ReqMsg, L2ResMsg>
|
||||
//类实例
|
||||
@@ -103,4 +103,4 @@ class InjectMessage {
|
||||
|
||||
}
|
||||
|
||||
export default InjectMessage
|
||||
export default InjectMessaging
|
@@ -1,9 +1,9 @@
|
||||
import { msgWaiter } from './useMessageService'
|
||||
import { msgWaiter } from './useMessagingService'
|
||||
import { useCallback } from 'react'
|
||||
import Layer1Protocol from '../layer1/Layer1Protocol'
|
||||
import { L2ReqMsg, L2ResMsg, MESSAGE_TO_EXTENSION_ROUTE, TAG_TARGET_INJECT } from '../const'
|
||||
|
||||
const useMessage = () => {
|
||||
const useMessaging = () => {
|
||||
const sendExtension = useCallback(async <T = any>(method: string, params?: any) => {
|
||||
// wait
|
||||
const pmh = await msgWaiter.wait() as Layer1Protocol<L2ReqMsg, L2ResMsg>
|
||||
@@ -34,4 +34,4 @@ const useMessage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
export default useMessage
|
||||
export default useMessaging
|
@@ -16,7 +16,7 @@ export const msgWaiter = new Waiter<Layer1Protocol<L2ReqMsg, L2ResMsg>>(() => ({
|
||||
data: portMessageHandler!,
|
||||
}), 100, 15000)
|
||||
|
||||
const useMessageService = (methods?: {
|
||||
const useMessagingService = (methods?: {
|
||||
[key: string]: (params: any, context: MethodContext) => Promise<any>
|
||||
}) => {
|
||||
const messageHandler = useCallback(async (req: L2ReqMsg): Promise<L2ResMsg> => {
|
||||
@@ -90,4 +90,4 @@ const useMessageService = (methods?: {
|
||||
}, [messageHandler, port])
|
||||
}
|
||||
|
||||
export default useMessageService
|
||||
export default useMessagingService
|
Reference in New Issue
Block a user