如何连接signalR以响应本机

问题描述

我试图与SignalR连接。请求后,不返回响应。 库: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,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,});

日志:

[13:21:14 GMT + 0300(EEST)] SignalR:客户端订阅了中心“通知”。 DEBUG [13:21:14 GMT + 0300(EEST)] SignalR:与 'https://test.get-bagel.com:8000 / signalr / negotiate?clientProtocol = 1.5&bearer = eyJ0e ...'

DEBUG [13:21:15 GMT + 0300(EEST)] SignalR:webSockets传输 开始。

调试[13:21:15 GMT + 0300(EEST)] SignalR:连接到websocket 终点 'wss://test.get-bagel.com:8000 / signalr / connect?transport = webSockets&clientProtocol = 1.5&bearer = eyJ0eXAiOi ...'。

调试[GMT + 0300(EEST)13:21:18] SignalR:Websocket已打开。

DEBUG [13:21:18 GMT + 0300(EEST)] SignalR:webSockets传输 连接的。发起启动请求。

DEBUG [13:21:18 GMT + 0300(EEST)] SignalR:开始请求 成功了。过渡到连接状态。

DEBUG [13:21:18 GMT + 0300(EEST)] SignalR:现在监视保持活动 警告超时为13333.333333333332,请保持活动超时 20000,断开超时30000

LOG现在已连接,连接ID = ca21c32a-cfc4-4479-9cce-********

DEBUG [13:21:18 GMT + 0300(EEST)] SignalR:正在调用 notifications.endUpdateContact

DEBUG [13:21:18 GMT + 0300(EEST)] SignalR: notifications.endUpdateContact无法执行。错误: 无法解决“ endUpdateContact”方法。找不到方法 这个名字。

WARN调用服务器时出了点问题,可能没有启动 并运行?

//现在我可以发送请求了,但是我没有收到回复

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)