NativeScript Headset Detection plugin
Installation
tns plugin add nativescript-headset-detection
API
isConnected
To check for a headset at any given moment, use this method:
JavaScript
var headsetDetection = ; headsetDetection ;
TypeScript
; headsetDetection.isConnected .thenconsole.log`Connected? ` .catchconsole.log`Error: `;
onConnectionStateChanged
To listen to changes to the headset state, use this one (adding it to a high level component like `app.[ts|js] makes sense); you can pass in a callback function that gets invoked whenever a headset is (dis)connected:
JavaScript
var headsetDetection = ; headsetDetection;
TypeScript
; headsetDetection.onConnectionStateChangedconsole.log`Connection changed to: `;