react-native-webview-messaging icon indicating copy to clipboard operation
react-native-webview-messaging copied to clipboard

await connectToRemote() not returning a connection or error

Open reggie3 opened this issue 7 years ago • 4 comments

The following code doesn't return a connection, nor does connectToRemote() return an error to be caught

 makeRemoteConnection = async () => {
    this.printElement('connecting to remote');
    try {
      let remote = await connectToRemote();
      this.remote = remote;
      this.printElement('remote connected');
      this.printElement(this.remote);
      this.bindListeners();

      // let the webview know we are listening
      this.printElement('emitting webview ready');
      this.remote.emit('WEBVIEW_READY', {
        payload: 'hello'
      });
      this.printElement('WEBVIEW_READY emitted');
    } catch (error) {
      console.log(`Error: ${error}`);
      this.printElement(`remote connect error ${error}`);
    }
  };

I receive the "connecting to remote" message, but I never receive the expected "remote connected" message. Additionally, no error is thrown for catching.

reggie3 avatar Jan 22 '18 17:01 reggie3

Hey @reggie3, thanks for opening this up. I have 2 quick questions:

what version are you using? is it webview side code or react-native? (if rn – you forgot to pass webview instance as a parameter to connectToRemote) if this is webview side code – please drop me a sample of code being evaluated on react-native side

thanks

lesnitsky avatar Jan 22 '18 18:01 lesnitsky

I just downloaded the @next version about an hour ago. It is on the webview side, not the React-Native side

On Jan 22, 2018 8:15 AM, "Andrei Volchenko" [email protected] wrote:

Hey @reggie3 https://github.com/reggie3, thanks for opening this up. I have 2 quick questions:

what version are you using? is it webview side code or react-native? (if rn – you forgot to pass webview instance as a parameter to connectToRemote) if this is webview side code – please drop me a sample of code being evaluated on react-native side

thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/R1ZZU/react-native-webview-messaging/issues/18#issuecomment-359515199, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAb-FViNF0b14dNp4fOXqRZsQnFDQlRks5tNNBUgaJpZM4RoXhp .

reggie3 avatar Jan 22 '18 18:01 reggie3

Could you please provide react-native side code as well?

lesnitsky avatar Jan 22 '18 18:01 lesnitsky

Here it goes:

  componentDidMount() {
    console.log(`WebViewLeaflet INFO: connecting to remote`);

    connectToRemote(this.webview)
      .then(remote => {
        this.remote = remote;
        console.log(`WebViewLeaflet INFO: remote connected`);
        this.bindListeners();

        // attempt to send the map center coords in case the remote is 
        // connected after the webview is ready
        this.sendUpdatedMapCenterCoordsToHTML(this.props.mapCenterCoords);
      })
      .catch((error)=>{
        console.log(`WebViewLeaflet ERROR: ${error}`);
      });
    console.log('WebViewLeaflet INFO: wbvw braintree mounted');
  }

reggie3 avatar Jan 23 '18 03:01 reggie3