This commit is contained in:
IndieKKY
2024-10-06 13:38:08 +08:00
parent b690a7ef08
commit 3140b91f72
14 changed files with 35 additions and 35 deletions

View File

@@ -0,0 +1,31 @@
import { setCurFetched, setCurInfo, setData, setInfos, setTitle, setUrl } from '@/redux/envReducer'
import { useMemo } from 'react'
import { useAppDispatch } from './redux'
import { MESSAGE_TO_APP_SET_INFOS, MESSAGE_TO_APP_SET_VIDEO_INFO } from '@/consts/const'
import useMessagingService from '@/messaging/layer2/useMessagingService'
const useMessageService = () => {
const dispatch = useAppDispatch()
//methods
const methods: {
[key: string]: (params: any, context: MethodContext) => Promise<any>
} = useMemo(() => ({
[MESSAGE_TO_APP_SET_INFOS]: async (params: any, context: MethodContext) => {
dispatch(setInfos(params.infos))
dispatch(setCurInfo(undefined))
dispatch(setCurFetched(false))
dispatch(setData(undefined))
},
[MESSAGE_TO_APP_SET_VIDEO_INFO]: async (params: any, context: MethodContext) => {
dispatch(setInfos(params.infos))
dispatch(setUrl(params.url))
dispatch(setTitle(params.title))
console.debug('video title: ', params.title)
},
}), [dispatch])
useMessagingService(methods)
}
export default useMessageService