olofd / react-native-signalr

Use SignalR with React Native
150 stars 61 forks source link

Not running at all. SignalR error: Undefained #14

Closed dabor238 closed 7 years ago

dabor238 commented 7 years ago

I try to use this package, but the following error appears. Any help would be really appreciated.

My server info is: var connection = signalr.hubConnection('https://www.multidoctores.com'); var proxy = connection.createHubProxy('chatHub');

This info is already tasted in Web, Android and Ios native apps.

screen shot 2017-01-10 at 3 33 26 pm screen shot 2017-01-10 at 3 34 26 pm
olofd commented 7 years ago

Anything related to #12?

dabor238 commented 7 years ago

I don't think that is the same issue, because: 1) the server is HTTPS 2) the hub has no security, you can access it here: https://www.multidoctores.com/signalr/hubs

dabor238 commented 7 years ago

Do I have to configure the hub in any specific way to test the library. Do you have an example of a server side hub that actually works with this library?

dabor238 commented 7 years ago

It tries to negotiate with

[16:41:33 GMT-0500 (ECT)] SignalR: Negotiating with 'https://www.multidoctores.com/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D'.

that brings a valid token. but then it gives us the SignalR error: undefined.

olofd commented 7 years ago

Testing now. Hold on.

olofd commented 7 years ago

@dabor238 I get: "An SSL error has occurred and a secure connection to the server cannot be made." Sry. There is a bug in the lib that hides the actual error.

olofd commented 7 years ago

But do this: Start react-native with chrome dev tools. Go to sources tab and press cmd + O (mac) ctrl + O (windows) and search for the file ajax.js and open it. should look like this:


export default function(options, data) {
  var request = new XMLHttpRequest();
  request.onreadystatechange = (e) => {
    if (request.readyState !== 4) {
      return;
    }

    if (request.status === 200 && !request._hasError) {
      options.success && options.success(JSON.parse(request.responseText));
    } else {
      options.error && options.error(request);
    }
  };

  request.open(options.type, options.url);
  request.setRequestHeader('content-type', options.contentType);

  request.send(options.data.data && `data=${options.data.data}`);

  return {
    abort: function(reason) {
      return request.abort(reason);
    }
  };
}

Place a breakpoint at options.error and then inspect your error.

olofd commented 7 years ago

Now for the error itself I do not know what's wrong exactly. You have any idea?

olofd commented 7 years ago

I now connected successfully to your server by disabling NSAppTransportSecurity..Hmm don't really know why it won't connect without it.

added

  <key>NSAppTransportSecurity</key>
   <dict>

      <key>NSAllowsArbitraryLoads</key>
      <true/>

   </dict>

to Info.plist.

dabor238 commented 7 years ago
screen shot 2017-01-10 at 5 24 42 pm

_response: An SSL error has occurred and a secure connection to the server cannot be made.

No idea why this happened, we are using this hub on WEB, Native Android and Native Ios, and it works fine.

dabor238 commented 7 years ago

I added at the end and still doesnt work.

screen shot 2017-01-10 at 5 30 49 pm screen shot 2017-01-10 at 5 32 56 pm
olofd commented 7 years ago

Hmm.. might be incorrectly formated.

This i my entire Info.plist in XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
      <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationLandscapeLeft</string>
      <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string/>
    <key>NSAppTransportSecurity</key>
   <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true/>
   </dict>
  </dict>
</plist>

Try opening yours in xcode and see if it can open it.

dabor238 commented 7 years ago

olofd: the boy wonder, the kid, the miracle man. the phenomenon, the unstoppable. It Works.

screen shot 2017-01-10 at 5 43 36 pm
olofd commented 7 years ago

Haha 👍 Happy to help out. But I will take a look at two things:

  1. Why you need that Info.plist edit (will also make a mention about these issues in the readme)
  2. That undefined error-value needs fixing.

Will do that in the next couple of days when I have time.

But let me know if there is anything else and good luck with your project!

dabor238 commented 7 years ago

My dear friend.

look at this http://stackoverflow.com/questions/32495059/ios9-will-nsallowsarbitraryloads-true-be-allowed-for-a-release-in-the-app-store

It appears that this fix will couse some problems for a release in the app store.

olofd commented 7 years ago

@dabor238 I found the root issue. Your server uses TLS 1.0. Insecure. So it was refused. You should look at upgrading.

However. You can do this, and set an exception for your domain only to accept TLS1.0. This should have no problem in App Store. (Even though the other version with allowing all is no prob. either, have released multiple apps with it.)

Here is the Info.plist with the exception:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string></string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
            <key>www.multidoctores.com</key>
            <dict>
                <key>NSTemporaryExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
            </dict>
        </dict>
    </dict>
</dict>
</plist>
dabor238 commented 7 years ago

Thank so much for the information

olofd commented 7 years ago

@dabor238 FYI: I've just released 0.0.11 on npm. I should contain a fix for the undefined error-problem you faced earlier. Please update and let me know if something is not working. Have you had any other issues?