danielsogl / awesome-cordova-plugins

Native features for mobile apps built with Cordova/PhoneGap and open web technologies. Complete with TypeScript support.
https://danielsogl.gitbook.io/awesome-cordova-plugins/
Other
2.41k stars 2.43k forks source link

Network plugin onConnect/onDisconnect not triggered #4837

Open willyboy opened 2 months ago

willyboy commented 2 months ago

This is a clone of #4086 as it was closed "inactive" but the issue still exists. I think the API for the underlying plugin has changed to just one event "networkStatusChange". I was hoping this plugin would give me the "onDisconnect/Connect" methods for readability.

I'm submitting a ... (check one with "x") [ x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior: The onConnect/Disconnect subscriptions are never getting invoked when the network status changes.

Expected behavior: The onConnect/Disconnect subscriptions should be invoked when the network status changes.

Steps to reproduce: Simple cordova 6 app with network plugin installed can be used to reproduce the issue.

Related code:

import { Network }  from '@awesome-cordova-plugins/network/ngx';

constructor(private platform: Platform, private network: Network {
  platform.ready().then(() => {
     this.network.onDisconnect().subscribe(() => {
        console.log('>network was disconnected :-(');
     });
     this.network.onConnect().subscribe(() => {
       console.log('>network was connected :-)');
     });      
});

} Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Ionic:

Ionic CLI : 6.18.2 (/home/elega9t/.nvm/versions/node/v14.16.0/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 5.9.3 @angular-devkit/build-angular : 12.2.16 @angular-devkit/schematics : 12.2.16 @angular/cli : 12.2.16 @ionic/angular-toolkit : 5.0.3

Capacitor:

Capacitor CLI : 3.4.3 @capacitor/android : not installed @capacitor/core : 3.4.3 @capacitor/ios : not installed

Cordova:

Cordova CLI : 11.0.0 Cordova Platforms : none Cordova Plugins : no whitelisted plugins (0 plugins total)

Utility:

cordova-res : 0.15.4 native-run : 1.5.0

System:

Android SDK Tools : 26.1.1 (/home/self/Android/Sdk) NodeJS : v14.16.0 (/home/self/.nvm/versions/node/v14.16.0/bin/node) npm : 8.5.2 OS : Linux 5.8

MaximBelov commented 1 month ago

Hi @willyboy Awesome Cordova Plugins wraps plugin callbacks in a Promise or Observable. The error is not related to this repository.

Maybe your issue is related to plugin itself https://github.com/apache/cordova-plugin-network-information

Try to create a demo application without ionic or capacitor Just Cordova + plugin

cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add ios
cordova platform add android
cordova plugin add cordova-plugin-network-information
cordova build

Good luck