Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundled Android application is not connecting to Web Socket server #5435

Closed
abduzar opened this issue Jan 31, 2019 · 12 comments
Closed

Bundled Android application is not connecting to Web Socket server #5435

abduzar opened this issue Jan 31, 2019 · 12 comments

Comments

@abduzar
Copy link

abduzar commented Jan 31, 2019

Describe the bug
The main actors are React Native android application and Storybook WebSocket server.
When the application is not containing JS bundle it successfully connects to local WebSocket server and shares stories to WebSocket server. In the case when the application is bundled with JS inside, it does not connect to the WebSocket server.

To Reproduce
Steps to reproduce the behavior:

  1. Build the Storybook Android application with embedded JS.
  2. Install the application on the emulator ( AVD )
  3. Launch Storybook WebSocket server
  4. Launch Android application
  5. Open WebSocket server web page (by default localhost:7007)
  6. Storybook is empty

Expected behavior
Storybook web page should contain all stories added to Android application.

System:

  • OS: MacOS Mojave 10.14.2
  • Device: Android Virtual Device ( Nexus 5 API 27 )
  • Framework: React Native
  • Version: 4.1.2
@Gongreg
Copy link
Member

Gongreg commented Jan 31, 2019

Hey, have you tried to explicitly pass host to the storybookUI?

The host order in prieview is:

const host = params.host || parse(NativeModules.SourceCode.scriptURL).hostname || 'localhost';

So maybe parse(NativeModules.SourceCode.scriptURL).hostname returns something that isn't correct.

@abduzar
Copy link
Author

abduzar commented Jan 31, 2019

@Gongregyes, for android putting "localhost" explicitly, does not help. As a workaround I've used 10.0.2.2 which helped.

PS. NativeModules.SourceCode.scriptURL this returns http://index.android.bundle:7007

@Gongreg
Copy link
Member

Gongreg commented Jan 31, 2019

Hey I never use android emulator, but that seems to be react native / android emulator issue. Have you tried to use host: localhost and then do "adb reverse tcp:7007 tcp:7007"?

@Gongreg
Copy link
Member

Gongreg commented Jan 31, 2019

Regarding: NativeModules.SourceCode.scriptURL this returns http://index.android.bundle:7007 We should probably do something about it.

@abduzar
Copy link
Author

abduzar commented Jan 31, 2019

Hey I never use android emulator, but that seems to be react native / android emulator issue. Have you tried to use host: localhost and then do "adb reverse tcp:7007 tcp:7007"?

Sure. It is just port redirection. If you try to open http://localhost:7007 from the emulator's browser it is not working. In a case when JS bundle is managed by Metro bundler, simulator proper responds on localhost:7007.

@abduzar abduzar closed this as completed Jan 31, 2019
@abduzar
Copy link
Author

abduzar commented Jan 31, 2019

Sorry accidentally closed

@abduzar abduzar reopened this Jan 31, 2019
@fjtrujy
Copy link

fjtrujy commented Jan 31, 2019

Hello,
I can confirm that I'm suffering the same error.
One question @Gongreg , why are we using parse(NativeModules.SourceCode.scriptURL).hostname at all?

I have been investigating it, and I have found this PR #1568 but as we can see is not working in all the scenarios.

Maybe we should check if the bundle is or isn't inside, and then have different approaches.

Thanks

@Gongreg
Copy link
Member

Gongreg commented Jan 31, 2019

Hey @fjtrujy, the reason for that was:

Most CRNA users will tend to run on the phone, not emulator, and the phone can't reach the PC on localhost, leading to storybook not working when following the hello world tutorial (btw this "host" should rather be in hello world readme)

I guess there are other solutions for this.

@fjtrujy
Copy link

fjtrujy commented Jan 31, 2019

Thanks for your reply @Gongreg, but maybe I didn't explain properly.

As you know, we can execute Storybook in a Physical Device, having the bundle either in the machine or included in the APK/IPA.
I think that the previous response that you said, would work when you DON'T have the bundle inside of the APK/IPA.

If I'm not wrong, when you are installing in the specific device you must provide the URL for the host where you are executing the server.

So, the current approach won't work either if you want to install the Storybook in a Physical device with the JS bundle inside of the APK/IPA, and then start the server in a different machine (obviously) to change the stories.
In order to make it work, you must specify the server URL anyway.

My initial suggestion was, that maybe we should check if the bundle is inside or outside, in order to use or not use parse(NativeModules.SourceCode.scriptURL).hostname

Thanks

@stale
Copy link

stale bot commented Feb 21, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale
Copy link

stale bot commented Mar 15, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Mar 15, 2019
@stale
Copy link

stale bot commented Apr 14, 2019

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Apr 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants