wampy.js: Wampy not connecting in react-native env

Describe the bug Wampy is not connecting properly in react-native environment.

The onConnect callback is not called.

Killing the crossbar service will trigger the onClose and onError callbacks. As mentioned also here: https://github.com/KSDaemon/wampy.js/issues/82#issuecomment-405012228

I also checked https://github.com/KSDaemon/wampy.js/issues/82 but could not find a working solution. Also the examples use w3cws as ws client.

I made a stripped down version of crossbar.io without authentication and bundled it into a repo to reproduce.

To Reproduce Clone https://github.com/zaytsevfuu/wampytest yarn install node node_modules/react-native/local-cli/cli.js run-android yarn run start cd crossbar && ./start_wamp.sh

Expected behavior onConnect callback is called

Screenshots Screenshot 2019-04-25 10 48 35

Screenshot 2019-04-25 10 52 38

Environment (please complete the following information):

  • Mac
  • see package.json
  • crossbar official docker image

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

@cabelitos Thats great! Looking forward for next release with ur MR included 😃

@KSDaemon I did some more digging and I think the problem is just with react-native and android because of the OkHttp code. I don’t have mac handy to test on IOS right now, however this test should only check for the undefined protocol in RN envs, while not affecting other ones. The code below would replace 582 from the post above.

            if (serverProtocol === 'json'
                ||  (typeof navigator != 'undefined'
                    && navigator.product == 'ReactNative'
                    && typeof this._ws.protocol === 'undefined')) {

Apologies for the multi-line here, but I wanted to to fit in the post more easily.