SignalR and mobile devices

3

Good morning

I was using signalr to update an application in which vehicles are shown moving on a map, the locations are notified from the server to the page by signalr, while the page is active, in the browser of the device (it is not a Hybrid application), all right, but if I send the browser to the background, regardless of whether it is Android or iOS, or if the PC is suspended, the browser to reactivate stops receiving notifications from the server. deal with the connectionSlow event or in error, and reconnect the client but this did not work. Any suggestions?

//esta es la inicializacion de signalr
//Bus
    transit = $.connection.transit;
    transit.client.updateBus = updateBus;
    transit.client.initBuses = initBuses;
    $.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame'] }).done(function () {
            transit.server.init();
        });
        $.connection.hub.connectionSlow(function () {
            try {
                $.connection.hub.stop();
            }
            catch (err) {
                console.log(err);
            }
            finally {
                $.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame'] }).done(function () { });
            }
        });
        $.connection.hub.error(function (error) {
            try {
                console.log(error);
                $.connection.hub.stop();
            }
            catch (err) {
                console.log(err);
            }
            finally {
                $.connection.hub.start({ transport: ['serverSentEvents', 'foreverFrame'] }).done(function () { });
            }

        });
    
asked by Byron 28.09.2016 в 00:03
source

1 answer

5

Remember that when you are on a device there is no background concept, applications are suspended and reactivated, there are usually events that you can use to control this.

Imagine you are using Apache Cordova

Apache Cordova Device Events

As you will see when you put the application in the background, the event pause should be executed and when you put it in the foreground the resume

It is in these events where you should update the signalr connection

You could also evaluate reconect events

Understanding and Handling Connection Lifetime Events in SignalR

Analyze the title " How to continuously reconnect "

    
answered by 29.09.2016 / 19:18
source