Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Update example to stop using the deprecated discovery method; prepare…
Browse files Browse the repository at this point in the history
… 0.4.0
  • Loading branch information
mannodermaus committed Jan 23, 2016
1 parent 2b614df commit bb10f39
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,63 @@
# RxBonjour
Say "Hi!" to RxBonjour, a wrapper around Android's network service discovery functionalities with a support implementation for devices below Jelly Bean, going down all the way to API level 9.

Disclaimer: This library is to be considered **very early** in terms of maturity. There will probably be issues, especially since NSD is a fragile topic on Android!

## Download

`RxBonjour` is available on `jcenter()`:

```groovy
compile 'com.github.aurae:rxbonjour:0.3.3'
compile "com.github.aurae:rxbonjour:0.4.0"
```

## Usage
## Discovery

Create a network service discovery request using `RxBonjour.startDiscovery(Context, String)` and subscribe to the returned `Observable` (this code is using Java 8 syntax for brevity):
Create a network service discovery request using `RxBonjour.newDiscovery(Context, String)` and subscribe to the returned `Observable`:

```java
RxBonjour.startDiscovery(this, "_http._tcp")
.subscribe(bonjourEvent -> {
BonjourService item = bonjourEvent.getService();
switch (bonjourEvent.getType()) {
case ADDED:
// Called when a service was discovered
break;

case REMOVED:
// Called when a service is no longer visible
break;
}
}, error -> {
// Service discovery failed, for instance
});
RxBonjour.newDiscovery(this, "_http._tcp")
.subscribe(bonjourEvent -> {
BonjourService item = bonjourEvent.getService();
switch (bonjourEvent.getType()) {
case ADDED:
// Called when a service was discovered
break;

case REMOVED:
// Called when a service is no longer visible
break;
}
}, error -> {
// Service discovery failed, for instance
});
```

RxBonjour pre-configures the returned Observables to run on an I/O thread, but return their callbacks on the main thread. The discovery will be stopped automatically upon unsubscribing from the Observable.

## Registration

Create a service to broadcast using `RxBonjour.newBroadcast(Context, String)` and subscribe to the returned `Observable` of the broadcast object:

```java
BonjourBroadcast<?> broadcast = RxBonjour.newBroadcast("_http._tcp")
.name("My Broadcast")
.port(65335)
.build();

broadcast.start(this)
.subscribe(bonjourEvent -> {
// Same as above
});
```

RxBonjour pre-configures the returned Observables to run on an I/O thread, but return their callbacks on the main thread. The broadcast will be stopped automatically upon unsubscribing from the Observable.

## Implementations

RxBonjour comes with two implementations for network service discovery. By default, the support implementation is used because of the unreliable state of the `NsdManager` APIs and known bugs with that. If you **really** want to use `NsdManager` on devices running Jelly Bean and up though, you can specify this when creating service discovery Observables:

```java
// If you're feeling real and ready to reboot your device once NsdManager breaks, pass in "true" to use it for supported devices
RxBonjour.startDiscovery(this, "_http._tcp", true)
RxBonjour.newDiscovery(this, "_http._tcp", true)
.subscribe(bonjourEvent -> {
// ...
}, error -> {
Expand Down
2 changes: 1 addition & 1 deletion example/src/main/java/rxbonjour/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void restartDiscovery() {

// Clear the adapter's items, then start a new discovery
adapter.clearItems();
nsdSubscription = RxBonjour.startDiscovery(this, input, useNsdManager)
nsdSubscription = RxBonjour.newDiscovery(this, input, useNsdManager)
.subscribe(new Action1<BonjourEvent>() {
@Override public void call(BonjourEvent bonjourEvent) {
// Depending on the type of event and the availability of the item, adjust the adapter
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TARGET_SDK_VERSION=23
# Library artifact & current version
GROUP_NAME=com.github.aurae
ARTIFACT_ID=rxbonjour
VERSION_NAME=0.3.3
VERSION_NAME=0.4.0

# Dependency versions (plugins)
GRADLE_PLUGIN_VERSION=1.5.0
Expand Down

0 comments on commit bb10f39

Please sign in to comment.