No experience with this, but I see 2 Cordova plugins which can do it apparently:
No I don’t have experience with that yet …
I want to add realtime communication (chat function) to my app, but for now I’m planning to use Firebase for that.
When at some point it doesn’t perform well enough or it’s getting to expensive then I’ll look at setting up my own server with socket.io or a solution like that.
Sorry no, but you can look at how ngCordova does that, for instance the battery status plugin (arbitrary example):
ngCordova is just an Angular wrapper around Cordova plugins, the code isn’t difficult to read.
As you see the code for this plugin is just 47 lines.
Bluetooth plugin (a bit longer but still jut 218 lines):