I trying to connect with SignalR. After request, does not return response. LIBRARY: react-native-signalr
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import signalr from 'react-native-signalr';
import store from '../../../../init/store';
export class SignalR extends Component {
componentDidMount() {
//This is the server under /example/server published on azure.
const connection = signalr.hubConnection('https://test.get-bagel.com:8000', {
qs: { bearer: store.getState().auth.token.split(' ')[1] }
});
connection.logging = true;
const proxy = connection.createHubProxy('notifications');
//receives broadcast messages from a hub function, called "helloApp"
proxy.on('endUpdateContact', (argOne, argTwo, argThree, argFour) => {
console.log('message-from-server', argOne, argTwo, argThree, argFour);
//Here I could response by calling something else on the server...
});
connection.start({
pingInterval: null,
transport: ['webSockets', 'serverSentEvents']
}).done(() => {
console.log('Now connected, connection ID=' + connection.id);
proxy.invoke("endUpdateContact", 'endUpdateContact')
.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)
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Logs:
[13:21:14 GMT+0300 (EEST)] SignalR: Client subscribed to hub 'notifications'. DEBUG [13:21:14 GMT+0300 (EEST)] SignalR: Negotiating with 'https://test.get-bagel.com:8000/signalr/negotiate?clientProtocol=1.5&bearer=eyJ0e...'
DEBUG [13:21:15 GMT+0300 (EEST)] SignalR: webSockets transport starting.
DEBUG [13:21:15 GMT+0300 (EEST)] SignalR: Connecting to websocket endpoint 'wss://test.get-bagel.com:8000/signalr/connect?transport=webSockets&clientProtocol=1.5&bearer=eyJ0eXAiOi...'.
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: Websocket opened.
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: webSockets transport connected. Initiating start request.
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: The start request succeeded. Transitioning to the connected state.
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
LOG Now connected, connection ID=ca21c32a-cfc4-4479-9cce-********
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: Invoking notifications.endUpdateContact
DEBUG [13:21:18 GMT+0300 (EEST)] SignalR: notifications.endUpdateContact failed to execute. Error: 'endUpdateContact' method could not be resolved. No method found with that name.
WARN Something went wrong when calling server, it might not be up and running?
//Now I can send request, but i doesn't get response