rmartin94 opened a new issue #99: Network status not reliable
URL: https://github.com/apache/cordova-plugin-network-information/issues/99
 
 
   # Bug Report
   
   ## Problem
   
   ### What is expected to happen?
   
   I would expect this plugin always to reflect the true network status of a 
mobile device, being notified when the status changes with its proper value
   
   ### What does actually happen?
   
   In general it works fine, but at some point I get stuck with a notification 
indicating that there's no network connection while the mobile device actual 
does have a connection. It's hard to reproduce, most time it works fine but on 
some occasions it doesn't. I subscribe to both onConnect and onDisconnect 
events.
   
   This provides a really bad user experience since there are many web services 
that are not being called depending on the network status (some others are 
cached locally since I try to provide offline support and then sync to the 
server when connection is back online), like the login web service. 
   
   I'm not sure if I should rely entirely on this plugin anymore or if I'm 
doing something wrong. Does anyone had this behavior? I've seen it mostly on 
Android devices. 
   
   ## Information
   <!-- Include all relevant information that might help understand and 
reproduce the problem -->
   
   I subscribe to the provided events by the plugin on a service I use across 
the application, and when they are fired I check the network type just in 
case.... but to double check I set a timeout of 2 seconds and then re-check the 
current network type. Only then I change the status based on the type. If by 
some reason a subsequent event is fired I clear the timeout to prevent this 
with messing with the current network status from the last fired event
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   
   ```
    public online: boolean;
    private notify;
   
    constructor(private _pf: Platform, private _nw: Network) {
       this.initNetwork();
    }
    
    public initNetwork(){
        this._pf.ready().then(() => {
           if (this._pf.is('cordova')) {
        this._nw.onDisconnect().subscribe(() => {
                console.log('now type... ', this._nw.type);
                this.clearNetworkNotification();
                this.notify = setTimeout(() => {
                        console.log('just to be sure.. ', this._nw.type);
                        if (this._nw.type.toLowerCase() === 'none') {
                        console.log('we are offline!');
                        this.online = false;
                        }
                }, 2000);
        });
        this._nw.onConnect().subscribe(() => {
                console.log('now type... ', this._nw.type);
                this.clearNetworkNotification();
                this.notify = setTimeout(() => {
                        console.log('just to be sure.. ', this._nw.type);
                        if (this._nw.type.toLowerCase() !== 'none') {
                                console.log('we are online!');
                                this.online = true;
                        }
                }, 2000);
        });
           }
       });
    }
    
    private clearNetworkNotification() {
       if (this.notify) {
           clearTimeout(this.notify);
           this.notify = undefined;
       }
    }
    
    public getNetworkStatus(){
        return this.online;
    }
   ```
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you 
experiencing the issue? -->
   
   I'm building an Ionic 4 application in Angular 7 with cordova
   
   ### Version information
   <!-- 
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins 
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   
   ```
   Ionic:
   
      Ionic CLI                     : 5.2.2 
(C:\Users\rodrigomartinezjr\AppData\Roaming\npm\node_modules\ionic)
      Ionic Framework               : @ionic/angular 4.8.1
      @angular-devkit/build-angular : 0.12.4
      @angular-devkit/schematics    : 7.2.1
      @angular/cli                  : 7.3.0
      @ionic/angular-toolkit        : 1.3.0
   
   Cordova:
   
      Cordova CLI       : 8.1.2 ([email protected])
      Cordova Platforms : not available
      Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, 
cordova-plugin-ionic-webview 4.1.3, (and 16 other plugins)
   
   Utility:
   
      cordova-res : 0.6.0 
      native-run  : 0.2.7 
   
   System:
   
      NodeJS : v10.14.1 (C:\Program Files\nodejs\node.exe)
      npm    : 6.4.1
      OS     : Windows 10
   ```
   
   ```
   code-push 2.0.6 "CodePushAcquisition"
   cordova-android-support-gradle-release 3.0.0 
"cordova-android-support-gradle-release"
   cordova-plugin-code-push 1.11.17 "CodePush"
   cordova-plugin-compat 1.2.0 "Compat"
   cordova-plugin-device 2.0.2 "Device"
   cordova-plugin-dialogs 2.0.1 "Notification"
   cordova-plugin-file 4.3.3 "File"
   cordova-plugin-file-transfer 1.6.3 "File Transfer"
   cordova-plugin-geolocation 4.0.1 "Geolocation"
   cordova-plugin-globalization 1.11.0 "Globalization"
   cordova-plugin-googlemaps 2.5.3 "cordova-plugin-googlemaps"
   cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
   cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
   cordova-plugin-network-information 2.0.1 "Network Information"
   cordova-plugin-request-location-accuracy 2.2.3 "Request Location Accuracy"
   cordova-plugin-splashscreen 5.0.2 "Splashscreen"
   cordova-plugin-statusbar 2.4.2 "StatusBar"
   cordova-plugin-whitelist 1.3.3 "Whitelist"
   cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
   cordova-sqlite-storage 3.2.0 "Cordova sqlite storage plugin - 
cordova-sqlite-storage plugin version"
   cordova.plugins.diagnostic 5.0.1 "Diagnostic"
   im.ltdev.cordova.UserAgent 1.0.1 "User-Agent"
   ```
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [ ] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to