olofd / react-native-signalr

Use SignalR with React Native
150 stars 61 forks source link

Failed - Error: Error during negotiation request. #59

Open gilshaan opened 4 years ago

gilshaan commented 4 years ago

Error

Failed - Error: Error during negotiation request.
    at Object.error (jquery.signalR.js:179)
    at onFailed (jquery.signalR.js:652)
    at Object.error (jquery.signalR.js:672)
    at EventTarget.request.onreadystatechange (ajax.js:23)
    at EventTarget.dispatchEvent (event-target-shim.js:818)
    at EventTarget.setReadyState (XMLHttpRequest.js:592)
    at EventTarget.__didCompleteResponse (XMLHttpRequest.js:395)
    at XMLHttpRequest.js:508
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:416)
jquery.signalR.js:82 [13:01:40 GMT+0530 (India Standard Time)] SignalR: Stopping connection.

My Code

componentDidMount() {
    //This is the server under /example/server published on azure.
    const connection = signalr.hubConnection('https://react-native-signalr.olofdahlbom.se');
    connection.logging = true;

    const proxy = connection.createHubProxy('chatHub');
    //receives broadcast messages from a hub function, called "helloApp"
    proxy.on('helloApp', (argOne, argTwo, argThree, argFour) => {
      console.log('message-from-server', argOne, argTwo, argThree, argFour);
      //Here I could response by calling something else on the server...
    });

    // atempt connection, and handle errors
    connection.start().done(() => {
      console.log('Now connected, connection ID=' + connection.id);

      proxy.invoke('helloServer', 'Hello Server, how are you?')
        .done((directResponse) => {
          console.log('direct-response-from-server', directResponse);
        }).fail(() => {
          console.warn('Something went wrong when calling server, it might not be up and running?')
        });

    }).fail(() => {
      console.log('Failed');
    });

    //connection-handling
    connection.connectionSlow(() => {
      console.log('We are currently experiencing difficulties with the connection.')
    });

    connection.error((error) => {
      const errorMessage = error.message;
      let detailedError = '';
      if (error.source && error.source._response) {
        detailedError = error.source._response;
      }
      if (detailedError === 'An SSL error has occurred and a secure connection to the server cannot be made.') {
        console.log('When using react-native-signalr on ios with http remember to enable http in App Transport Security https://github.com/olofd/react-native-signalr/issues/14')
      }
      console.debug('SignalR error: ' + errorMessage, detailedError)
    });
  }
GhayoorUlHaq commented 4 years ago

Same issue

GhayoorUlHaq commented 4 years ago

I think https://react-native-signalr.olofdahlbom.se is not working that's why getting this.

amir-gorji commented 4 years ago

This package is outdated and it's not working out with the latest signalR functionalities. You can use @aspnet/signalr. It's an official package working also on the React Native.