Giter Club home page Giter Club logo

Comments (6)

kevinNgws avatar kevinNgws commented on May 30, 2024 1

Yes, it works!

But you did not connect to your Hub. You only do this if you set up listener for that hub before calling connection.start. And lifecycle-events are only handled on the hub itself.

Strange indeed!
Nonetheless, thank you so much for the support!

FYI, when I did a npm install for signalr, the package.json still indicates 0.0.10.

from react-native-signalr.

olofd avatar olofd commented on May 30, 2024

Post some sample js-code here please. (I have used OnConnected with this library before and it should work).

And please update to react-native-signalr : 1.0.0

from react-native-signalr.

kevinNgws avatar kevinNgws commented on May 30, 2024

The code as below:
`connection = signalr.hubConnection(socketUrl); connection.logging = true;

proxy = connection.createHubProxy(Constant.PROXY_HUB);

return (dispatch) => {
    connection.start().done(() => {
        Reactotron.log('Now connected, connection ID=' + connection.id);

        dispatch({
            type: ActionTypes.ESTABLISH_CONNECTION_SUCCESS,
            payload: {
                Activity: ActionTypes.ESTABLISH_CONNECTION_SUCCESS,
                ConnectionId: connection.id
            }
        });

        // Connection-handling
        connection.connectionSlow(function () {
            Reactotron.log('Connection slow');
            dispatch({
                type: ActionTypes.CONNECTION_SLOW,
                payload: {
                    Activity: ActionTypes.CONNECTION_SLOW
                }
            });
        });

        connection.reconnecting(function () {
            Reactotron.log('Connection reconnecting');
        });

        connection.reconnected(function () {
            Reactotron.log('Connection reconnected');
        });

        connection.disconnected(function () {
            Reactotron.log('Connection disconnected');
        });

        connection.error(function (error) {
            Reactotron.log('Connection error');
            dispatch({
                type: ActionTypes.CONNECTION_HAS_ERROR,
                payload: {
                    Activity: ActionTypes.CONNECTION_HAS_ERROR,
                    Error: error
                }
            });
        });


    }).fail((error) => {
        Reactotron.log('Connection failed');
        Reactotron.log(error);
        dispatch({
            type: ActionTypes.ESTABLISH_CONNECTION_FAIL,
            payload: {
                Activity: ActionTypes.ESTABLISH_CONNECTION_FAIL,
            }
        });
    });

    dispatch({
        type: ActionTypes.ESTABLISH_CONNECTION_REQUEST,
        payload: {
            Activity: ActionTypes.ESTABLISH_CONNECTION_REQUEST
        }
    });
};`

I gotten the connection id so I doubt there is problem with the code.
Let me try updating the version to 1.0.0 and get back to you.

Thanks for the fast response!

from react-native-signalr.

kevinNgws avatar kevinNgws commented on May 30, 2024

Hi,
There is still issue with the server method not being called, even though i had upgraded to 1.0.0

from react-native-signalr.

olofd avatar olofd commented on May 30, 2024

It works here if I add a listener to the hub.
Tested on example project and it works.
I think you need to do this in signalr.

proxy = connection.createHubProxy(Constant.PROXY_HUB);

proxy.on('someMethodTheHubMightCallYouOn', (argOne) => {
    //I think you have to listen to a hub-method for lifecycle-events to fire on that hub.
    //Please read signalr-docs.
});

return (dispatch) => {
    connection.start().done(() => {
        Reactotron.log('Now connected, connection ID=' + connection.id);

        dispatch({
            type: ActionTypes.ESTABLISH_CONNECTION_SUCCESS,
            payload: {
                Activity: ActionTypes.ESTABLISH_CONNECTION_SUCCESS,
                ConnectionId: connection.id
            }
        });

        // Connection-handling
        connection.connectionSlow(function () {
            Reactotron.log('Connection slow');
            dispatch({
                type: ActionTypes.CONNECTION_SLOW,
                payload: {
                    Activity: ActionTypes.CONNECTION_SLOW
                }
            });
        });

        connection.reconnecting(function () {
            Reactotron.log('Connection reconnecting');
        });

        connection.reconnected(function () {
            Reactotron.log('Connection reconnected');
        });

        connection.disconnected(function () {
            Reactotron.log('Connection disconnected');
        });

        connection.error(function (error) {
            Reactotron.log('Connection error');
            dispatch({
                type: ActionTypes.CONNECTION_HAS_ERROR,
                payload: {
                    Activity: ActionTypes.CONNECTION_HAS_ERROR,
                    Error: error
                }
            });
        });


    }).fail((error) => {
        Reactotron.log('Connection failed');
        Reactotron.log(error);
        dispatch({
            type: ActionTypes.ESTABLISH_CONNECTION_FAIL,
            payload: {
                Activity: ActionTypes.ESTABLISH_CONNECTION_FAIL,
            }
        });
    });

    dispatch({
        type: ActionTypes.ESTABLISH_CONNECTION_REQUEST,
        payload: {
            Activity: ActionTypes.ESTABLISH_CONNECTION_REQUEST
        }
    });
};

from react-native-signalr.

olofd avatar olofd commented on May 30, 2024

My explanation for this: SignalR is a bit strange here. You established a successful connection to the server by calling connection.start().
But you did not connect to your Hub. You only do this if you set up a listener for that hub before calling connection.start. And lifecycle-events are only handled on the hub itself.

from react-native-signalr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.