Skip to content

Retry request when online (Android OAuth Monitor) #26

Description

@jperl

Thoughts?

/**
 * Plugin messages are not processed on Android until the next message.
 * This is a workaround to manually check messages.
 * http://stackoverflow.com/q/23352940/230462 and http://stackoverflow.com/a/24319063/230462
 * @param enabled
 */
manuallyCheckMessages: function (enabled) {
    if (!!this._checkMessageInterval === !!enabled) return;

    if (enabled) {
        this._checkMessageInterval = setInterval(function () {
            cordova.exec(null, null, '', '', [])
        }, 200);
    } else {
        clearInterval(this._checkMessageInterval);
        this._checkMessageInterval = null;
    }
},
/**
 * If the response failed, retry the MeteorRider request when online.
 */
retryWhenOnline: function () {
    var self = this;

    // If there is a problem loading, retry loading when online.
    document.addEventListener('MeteorRiderResponseError', function () {
        // Retry init of MeteorRider when the app goes online
        self._retryLoading = true;
        self.manuallyCheckMessages(true);
    });

    document.addEventListener('online', function () {
        if (!self._retryLoading) return;

        self.manuallyCheckMessages(false);
        self._retryLoading = false;

        MeteorRider.request();
    }, false);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions