Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: expose a reInit() action #50

Merged
merged 9 commits into from
Nov 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.2.9] - 2017-11-23

- Added `reInit()` method to allow for runtime plugin reset

## [1.2.8] - 2017-10-13

- [Android] fixing NPE when calling close right after unwatch and stop right after unregister
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ Closes the service browser and stops watching.
zeroconf.close()
```

#### `reInit(success, failure)`
Re-initializes the entire plugin, which resets the browsers and services. Use this if the WiFi network has changed while the app is running.

```javascript
zeroconf.reInit()
```

## Credits

#### Android
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-zeroconf",
"version": "1.2.8",
"version": "1.2.9",
"description": "Cordova ZeroConf plugin",
"cordova": {
"id": "cordova-plugin-zeroconf",
Expand Down Expand Up @@ -30,6 +30,10 @@
"name": "Sylvain Bréjeon",
"url": "https://github.com/becvert"
},
"contributors": {
"name": "Eric McNiece",
"url": "https://github.com/emcniece"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/becvert/cordova-plugin-zeroconf/issues"
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-zeroconf"
version="1.2.8">
version="1.2.9">

<name>ZeroConf</name>
<description>ZeroConf plugin for Cordova/Phonegap</description>
Expand Down
18 changes: 18 additions & 0 deletions src/android/net/becvert/cordova/ZeroConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class ZeroConf extends CordovaPlugin {
public static final String ACTION_WATCH = "watch";
public static final String ACTION_UNWATCH = "unwatch";
public static final String ACTION_CLOSE = "close";
// Re-initialize
public static final String ACTION_REINIT = "reInit";

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
Expand Down Expand Up @@ -135,6 +137,8 @@ public void onDestroy() {
lock.release();
lock = null;
}

Log.v(TAG, "Destroyed");
}

@Override
Expand Down Expand Up @@ -330,6 +334,20 @@ public void run() {
callbackContext.success();
}

} else if (ACTION_REINIT.equals(action)) {
Log.e(TAG, "Re-Initializing");

cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
onDestroy();
initialize(cordova, webView);
callbackContext.success();

Log.e(TAG, "Re-Initialization complete");
}
});

} else {
Log.e(TAG, "Invalid action: " + action);
callbackContext.error("Invalid action: " + action);
Expand Down
Loading