Ionic Bluetooth Serial Module / Unsubscribe & UnsubscribeRawData methods missing?

Hi All,

I’ve been developing an Ionic(V4)/Angular 8 app using the Bluetooth serial module and everything works fine, the app can use the Bluetooth Serial Library to scan and connect to devices. However, 2 methods are missing from the library that are included in the original Github:

This is a problem as when trying to disconnect from one device and connect with another the library stays subscribed to the data stream and consequently receives data from 2 devices. I added this to the Github repo as an issue and got this response from Don, the Github owner:

don commented 24 days ago

The functions are available in this plugin, they’re missing from the Ionic wrapper.

The best solution is to add them to the Ionic wrapper and send them a pull request. Alternately you can access the plugin directly from ionic and just call the functions.

Is it possible to get the Libary updated to include the methods in the Ionic Wrapper? Or am I missing something and is there a work-around to unsubscribe from previously subscribed data streams.

Any help or guidance on this matter is much appreciated


I don’t think I’d describe it as a “work-around”, because it looks to me to be the deliberately-intended way of doing things. When you call subscribe() (or subscribeRawData) on the plugin (not a name I would have chosen, because it’s going to make this conversation a lot harder, but nobody asked my opinion) you get an Observable. I assume you then call subscribe() on that Observable. Don’t throw away the return value of that call. You get back a Subscription at that point, and calling unsubscribe on that Subscription calls the underlying unsubscribe or unsubscribeRawData as appropriate within the plugin.

Great, Thanks @rapropos for the quick response!

Setting up the subscription and unsubscribing this way makes sense and works well! I guess I was a bit confused as to how this subscription was working (trying to call unsubscribe/unsubscribeRawData) without storing the return value as a subscription first.

Thanks again, great support!