bsorrentino / cordova-broadcaster

Cordova Plugin to allow message exchange between javascript and native (and viceversa)
MIT License
115 stars 53 forks source link

How to stop broadcaster in ionic app?There is no API available?It consume more battery? #22

Closed Prabuganesan closed 3 years ago

bsorrentino commented 7 years ago

I'm not sure what do you mean for stop broadcaster.

However the plugin provide a removeEventListener to unsubscribe (and eventually remove) subscription

Prabuganesan commented 7 years ago

Thanks.. I'm using 'ionic-native/broadcaster' plugin in ionic 3. 'removeEventListener' method not available. Can u please help me....

bsorrentino commented 7 years ago

Keep in mind that ionic-native/broadcasterwraps original methods.

In particular, in the ionic-native/broadcaster, the addEventListener(eventName: string): Observable<any> return an Observable and the removeEventListener is implicit in Observable unsubscription than you can use that to stop broadcaster.

register subscription


let subscription = this.broadcaster.addEventListener('eventName')
                                       .subscribe((event) => console.log(event));

when you need to stop


subscription.unsubscribe();
Prabuganesan commented 7 years ago

Thanks for your clarification..