# Communication

This guide explains how to establish seamless bidirectional communication between your React Native app and the LiSA Player running within a WebView. By leveraging native-to-JavaScript bridges and WebView event listeners, you can enable your Android app and the LiSA Player to exchange data, trigger events, and synchronize state in real time.

Whether you need to send commands from you app to the LiSA Player (e.g., changing app behavior or updating content) or pass data from the WebView back to your app (e.g., user actions or analytics), this guide will walk you through the necessary setup and best practices for efficient, secure, and reliable communication.

### Receiving Messages

React Native listens for messages using the `onMessage` prop of the WebView:

```tsx
<WebView
  source={{ uri: 'https://{clientId}.loveslisa.tech/s/{showId}' }}
  onMessage={(event) => {
    const message = JSON.parse(event.nativeEvent.data);
    console.log('Received message from React.js:', message);
  }}
/>
```

***

### Sending Messages

React Native allows sending messages to the embedded web app using the `injectJavaScript` or `evaluateJavaScript`props of the `WebView`.

```tsx
const webViewRef = useRef(null);

const sendMessageToWebApp = () => {
  const message = JSON.stringify({
    type: 'event',
    payload: { key: 'value' },
  });

  webViewRef.current?.injectJavaScript(`
    window.postMessage(${message}, '*');
  `);
};

return (
  <WebView
    ref={webViewRef}
    source={{ uri: 'https://{clientId}.loveslisa.tech/s/{showId}' }}
    javaScriptEnabled={true}
  />
);
```

* The `WebView` is wrapped in a `ref` (`webViewRef`), allowing programmatic control.
* When `sendMessageToWebApp` is called, it injects JavaScript into the LiSA Player using `injectJavaScript`.
* The message is sent as a JSON object via `window.postMessage`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hello-lisa.com/developers/guides/integration-guide/app-integration/react-native/communication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
