Skip to content

Commit

Permalink
#5 Support event based detection and updated to new cordova plugin cl…
Browse files Browse the repository at this point in the history
…obbers - tidied up a few little things
  • Loading branch information
EddyVerbruggen committed Jun 27, 2016
1 parent 90980c8 commit 76cef0c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,29 @@ The successCallback (first argument) is a boolean (true or false). Couldn't be e

### 3.1 Usage with event-based detection

If you need to respond to removal or added headset while your app i running, you can use the `HeadsetDetection.registerRemoteEvents` function and listen for either `headsetAdded` or `headsetRemove`:
If you need to respond to removal or added headset while your app i running, you can use the `HeadsetDetection.registerRemoteEvents` function and listen for either `headsetAdded` or `headsetRemoved`:

```js
window.HeadsetDetection.registerRemoteEvents(function(status) {
switch(status) {
case 'headsetAdded':
console.log('Headset was added');
break;
case 'headsetRemove':
console.log('Headset was removed');
break;
};
});
document.addEventListener('deviceready', function() {
window.HeadsetDetection.registerRemoteEvents(function(status) {
switch (status) {
case 'headsetAdded':
alert('Headset was added');
break;
case 'headsetRemoved':
alert('Headset was removed');
break;
};
});
}, false);
```

## 4. CREDITS ##

This plugin was created by and enhanced for Plugman / PhoneGap Build by [Eddy Verbruggen](http://www.x-services.nl).

The awesome `registerRemoteEvents` function was added by [Gerhard Sletten](https://github.com/gerhardsletten).

## 5. License

[The MIT License (MIT)](http://www.opensource.org/licenses/mit-license.html)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-headsetdetection",
"version": "2.0.0",
"version": "3.0.0",
"description": "Detect a wired or Bluetooth headset",
"cordova": {
"id": "cordova-plugin-headsetdetection",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-headsetdetection"
version="2.0.0">
version="3.0.0">

<name>Headset Detection</name>

Expand Down
1 change: 1 addition & 0 deletions src/ios/HeadsetDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
@interface HeadsetDetection :CDVPlugin

- (void) detect:(CDVInvokedUrlCommand*)command;
- (void) registerRemoteEvents:(CDVInvokedUrlCommand*)command;

@end
4 changes: 4 additions & 0 deletions src/ios/HeadsetDetection.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ - (void) detect:(CDVInvokedUrlCommand*)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void) registerRemoteEvents:(CDVInvokedUrlCommand*)command {
// no implementation needed
}

- (BOOL) isHeadsetEnabled {
AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute];
for (AVAudioSessionPortDescription* desc in [route outputs]) {
Expand Down
2 changes: 1 addition & 1 deletion www/HeadsetDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var HeadsetDetection = {
this.actionCallback = actionCallback;
},
remoteHeadsetRemoved: function() {
this.actionCallback && this.actionCallback('headsetRemove');
this.actionCallback && this.actionCallback('headsetRemoved');
},
remoteHeadsetAdded: function() {
this.actionCallback && this.actionCallback('headsetAdded');
Expand Down

0 comments on commit 76cef0c

Please sign in to comment.