WebView communication
publish(eventKey, data, targetWebviewId)
Section titled “publish(eventKey, data, targetWebviewId)”Send messages to other WebViews.
// Broadcast to all WebViewsSuperSDK.publish('user_login', { userId: '123' });
// Send to specified WebViewSuperSDK.publish('refresh_data', { type: 'order' }, 'a1b2c3d4');Parameter Description:
| Parameter | Type | Description |
|---|---|---|
| eventKey | string | Event Identifier |
| data | object | Message Data |
| targetWebviewId | string | Target WebView ID, omit or pass ’*’ to broadcast to all |
subscribe(eventKey, callback)
Section titled “subscribe(eventKey, callback)”Listen for broadcast messages from other WebViews or clients.
const unsubscribe = SuperSDK.subscribe('user_login', (data) => { console.log('Message received:', data);});
// Cancel listenerunsubscribe();Note:
subscribecan receivepublishmessages from other WebViews, as well as broadcasts sent by the client viasendBroadcast/broadcastToAll.
Client Broadcast (Native → Frontend)
Section titled “Client Broadcast (Native → Frontend)”The host app can send broadcast messages to WebView via SDK API, and the frontend uses subscribe to receive them.
Client-side invocation method:
// Android - Send broadcast to the current WebViewpageView.sendBroadcast("login_changed", "{\"isLogin\":true}");
// Android - Broadcast to all WebViewsSuperSDK.broadcastToAll("config_updated", "{\"key\":\"value\"}");// iOS - Send broadcast to the current WebViewpageView.sendBroadcast(eventKey: "login_changed", jsonData: "{\"isLogin\":true}")
// iOS - Broadcast to all WebViewsSuperSDK.broadcastToAll(eventKey: "config_updated", jsonData: "{\"key\":\"value\"}")Front-end reception method:
// Listen to client broadcasts (using subscribe, same as communication with WebView)SuperSDK.subscribe('login_changed', (data) => { console.log('Sign-in state changed:', data); // data = { isLogin: true }});
SuperSDK.subscribe('config_updated', (data) => { console.log('Configuration updated:', data);});Note: If a broadcast is sent before the JSBridge is ready, the message will be buffered and automatically delivered once the JSBridge is ready.