buildMessageHandler
Creates a message handler for processing window messages from wallet service frames or popups. This handler manages the communication protocol between FCL and wallet services, including ready states, responses, and cleanup operations.
Import
You can import the entire package and access the function:
_10import * as fcl from "@onflow/fcl-core"_10_10fcl.buildMessageHandler(buildMessageHandlerParams)
Or import directly the specific function:
_10import { buildMessageHandler } from "@onflow/fcl-core"_10_10buildMessageHandler(buildMessageHandlerParams)
Usage
_10// Create a message handler for wallet communication_10const handler = buildMessageHandler({_10 close: () => cleanup(),_10 send: (msg) => postMessage(msg),_10 onReady: (e, utils) => initializeWallet(utils),_10 onResponse: (e, utils) => handleResponse(e.data),_10 onMessage: (e, utils) => processMessage(e),_10 onCustomRpc: (payload, utils) => handleRpc(payload)_10})_10window.addEventListener("message", handler)
Parameters
buildMessageHandlerParams
- Type:
_21export interface BuildMessageHandlerParams {_21 close: () => void_21 send: (msg: any) => void_21 onReady: (_21 e: MessageEvent,_21 utils: {send: (msg: any) => void; close: () => void}_21 ) => void_21 onResponse: (_21 e: MessageEvent,_21 utils: {send: (msg: any) => void; close: () => void}_21 ) => void_21 onMessage: (_21 e: MessageEvent,_21 utils: {send: (msg: any) => void; close: () => void}_21 ) => void_21 onCustomRpc: (_21 payload: any,_21 utils: {send: (msg: any) => void; close: () => void}_21 ) => void_21 getSource?: () => Window | null_21}
Returns
_10(e: MessageEvent<any>) => void
Message event handler function that can be attached to window message listeners