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

Different websocket addresses for different simultaneous platforms #54

Closed
frankiesardo opened this issue Jan 7, 2016 · 16 comments
Closed

Comments

@frankiesardo
Copy link

We are running a cordova application that targets browser, ios and android.

The default reload address ws:localhost:.. works wonder with the browser and the ios simulator, allowing us to push the changes to both simultaneously.

However the Android emulator remaps localhost to 10.0.2.2. I can change my build.boot to use (reload :ws-host "10.0.2.2") , but this way we cannot develop with a single reloaded workflow on all three platform simultaneously.

Our ultimate dream is: having the three platform screens side by side and see our changes propagate to all of them in realtime ⭐ I wonder if boot has a way to accomplish this with.

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

Not possible currently I think.

And I'm not sure what would be a solution to this. As far as I know the websocket client needs an address and port. Also, in client code it can be difficult to detect what is the current client.

One solution would be to the same hostname for websocket connection as is used to load the page, but that doesn't solve all cases so I don't think it's worth the complexity.

Maybe you could configure your network so that you have single IP which is accessible from all clients?

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

To setup loopback alias for browser and maybe ios simulator:

# linux?
ifconfig lo: 10.0.2.2 netmask 255.0.0.0 up
# os x?
ifconfig lo0 alias 10.0.2.2

@frankiesardo
Copy link
Author

Thanks @Deraen you comment made me realise that there is a very easy solution to this problem:

(task-options!
 reload {:ws-host (.getHostAddress (java.net.Inet4Address/getLocalHost))})

And voilà, the websocket connects to all three platforms without problems!

screen shot 2016-01-08 at 10 04 05

However, this story still has no happy ending. When I try to reload on android boot-reload does a call to GET file:///Users/frankie/Projects/my-app/www/js/app.out/web/core.js?zx=vs40u6q9r42l (my main namespace) that fails for the same localhost problem. My guess is it should be file://MY_HOST_IP/Users/frankie/Projects/my-app/www/js/app.out/web/core.js?zx=vs40u6q9r42l. Do you guys know how can I tweak that behaviour (or monkeypatch it?)

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

File urls never work with ips, they are always to local filesystem. Reload client is set to load files from same url as they were initially loaded.

This part of code is where JS files are reloaded: https://github.com/adzerk-oss/boot-reload/blob/master/src/adzerk/boot_reload/reload.cljs#L42-L44

Is there a possibility to get android load files from HTTP server instead?

@frankiesardo
Copy link
Author

Interesting. Figwheel does not have the same problem because it uses a static file server to serve those files over http:// rather than file://. Since boot-reload is already starting a server for the websocket connection it shouldn't be a massive change to serve the files from there?

I don't know if that's the direction boot-reload wants to go to, but if you think it's a useful addition I'm happy to help implementing this feature.

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

Usually one uses boot-http or project http server to serve the files.

@frankiesardo
Copy link
Author

Yeah but having it integrated in this plugin means boot-reload can call reload-js with a uri like http://host:port/js/out/app.js instead of file:///Documents/...js/out/app.js, thus allowing a user to pass a different host and port for emulators, or using something like ngrok with physical devices

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

No, it shouldn't need to be integrated into this plugin. Boot-reload should already reload files over http BUT you probably need to load the HTML over http.

@frankiesardo
Copy link
Author

BUT you probably need to load the HTML over http.

That's the point. When running on a device (cordova, React Native) the file is not loaded over http. Wouldn't it be nice to support those platforms too?

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

Boot-react-native seems to have some workarounds to make boot-reload work.

It would be nice to support those platforms too but I don't think integrating http server is needed for that. We could either require user to use boot-http or depend on boot-http and compose reload with boot-http to start server, but I would probably prefer the first option if the configuration doesn't get too complex.

Some kind of reload-url-fn or prefix option might be enough.

Do you have some example project I could take a look at?

@frankiesardo
Copy link
Author

Yes, I have a very sample example pushed at https://github.com/frankiesardo/cadabra.

You can run only the Android platform if you like, that's the one I'm having problems with.

@martinklepsch
Copy link
Contributor

maybe the asset-host option proposed in #52 would help with this as it allows to specify an alternative "root host" to load to-be-reloaded files from instead of deriving it from the intially loaded file?

@frankiesardo
Copy link
Author

Yes, it works beautifully! Thanks a bunch for the help guys, I've updated the cadabra project to reflect this change if anyone wants to try it out.

This change is so good that it makes it trivial to use ngrok and make boot-reload work on real devices remotely. Exciting times ahead.

@martinklepsch
Copy link
Contributor

Great to hear @frankiesardo! Took me a while to realize that the solution was already there haha.

Cheers! 🍻

@Deraen
Copy link
Contributor

Deraen commented Jan 8, 2016

I'll be doing release this weekend.

@Deraen
Copy link
Contributor

Deraen commented Jan 10, 2016

0.4.3 is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants