Custom "bridge" protocol
jsBridge The built-in interface provided basically meets most of the requirements of js two-way communications between the environment and the client.Of course, for certain special customization needs that are not covered by built-in interfaces, two-way communications with clients can be implemented through the following two atomic methods.
callAndBackfeed
callAndBackfeed: <T>(scheme: string) => Promise<JSBridgeReturnType<T | false>>
const success = await jsBridge.callAndBackfeed<boolean>(
"/PlayVoiceMsg?msg={待播放语音文本}"
); // Return successful
Send
schemeinformation to the client, who will return to the frontend as soon as they receive it.
callAndListen
callAndListen: <T>(scheme: string, callback: (data: T) => void) => Promise<JSBridgeReturnType<false | (() => void)>>
Send
schemeinformation to client, client listens to changes in the status and feeds back to the frontend as soon as the status changes occur.The difference withcallBackfeedis:callBackfeed()is a one-time behavior,callAndListen()is listening.
For more information, refer to iOS Custom Protocol or Android Custom Protocol Documents description.