olofd / react-native-signalr

Use SignalR with React Native
150 stars 61 forks source link

not connection SignalR error: undefined #11

Closed EmreMengukan closed 8 years ago

EmreMengukan commented 8 years ago

signals system => html page connection to signalr no problem alone react-native-signalr plugin there is an error

Back end code

[assembly: OwinStartup(typeof(Statistics.Startup))]
namespace Statistics
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {

            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();
        }
    }
}

namespace Statistics
{
    [HubName("dataHub")]
    public class DataHub : Hub
    {
        public void Send(object obj)
        {
            Clients.All.broadcastMessage(obj);
        }
    }
}

html code


$(function() {
        var chat = $.connection.dataHub;
         chat.client.broadcastMessage = function ( message) {
            console.dir(message)
        };

        $.connection.hub.url = "http://myserverurl/signalr/hubs";
        $.connection.hub.start().done(function() {
                 chat.server.send('test sample');
        });
    });

html connection no problem

react-native code

import signalr  from "react-native-signalr";

componentDidMount(){

        var connection = signalr.hubConnection('http://myserverurl/signalr/hubs');

        connection.logging = true;

        var proxy = connection.createHubProxy('dataHub');

        proxy.on('broadcastMessage', (message) => {
            console.log(message);

        });

            connection.start().done(() => {
                console.log('Now connected, connection ID=' + connection.id);
            }).fail(() => {
                console.log('Failed');
            });

        console.log(connection.connectionState)

            connection.connectionSlow(function () {
                console.log('We are currently experiencing difficulties with the connection.')
            });

            connection.error(function (error) {
                console.log('SignalR error: ' + error)
            });

    }

react native chrome debuger console error log ;

ekran resmi 2016-11-25 10 50 17

Example project can you share Help Me :)

olofd commented 8 years ago

@EmreMengukan You need to enable support for http (non-encrypted connection) in xcode. xcode has this disabled by default

olofd commented 8 years ago

http://iosdevtips.co/post/121756573323/ios-9-xcode-7-http-connect-server-error

olofd commented 8 years ago

Locate your Info.plist (resides in the ios folder) and add this:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

Let me know if this does not work.

EmreMengukan commented 8 years ago

@olofd You are the best 👍 :))))