# Titanium.Network.BonjourBrowser

A browser for the discovery and retrieval of Bonjour services available on the network.

Availability
1.2.0
9.2.0

# Overview

Use the Titanium.Network.createBonjourBrowser method to create a BonjourBrowser instance.

If your application publishes Bonjour services itself, that service will be discovered by the browser if necessary; be prepared to perform a check if you do not want to list local services as available. Bonjour service browsing is an asynchronous operation, meaning that you should be extremely careful when caching values from the services property returned by the updatedservices event. In particular, if you maintain a local copy of available services and a user tries to connect to one, you should be prepared to handle failures gracefully; the next updatedservices event should provide the new services list, but you should not rely on it being delivered before user input. When a window which uses Bonjour browsing is closed, if you do not want to continue searching, you must call the stop() method.

In iOS 14.0+, to browse services add key NSLocalNetworkUsageDescription and NSBonjourServices to the ios plist section of the tiapp.xml file.

Example:

<ti:app>
  <!-- ... -->
  <ios>
    <plist>
      <dict>
        <!-- Reason to access local network-->
        <key>NSLocalNetworkUsageDescription</key>
        <string>
            Specify the reason for accessing the local network.
            This appears in the alert dialog when asking the user 
            for permission to access local network.
        </string>
        <!-- List of bonjour service type-->
        <key>NSBonjourServices</key>
        <array>
          <string>_test._tcp</string>
        <array/>
      </dict>
    </plist>
  </ios>
  <!-- ... -->
</ti:app>

# Properties

# domain

Availability
1.2.0
9.2.0
domain :String

The domain the browser is searching in

Default: local.


# isSearching

Availability
1.2.0
9.2.0
isSearching :Boolean

Whether or not the browser is currently searching

Default: false


# serviceType

Availability
1.2.0
9.2.0
serviceType :String

The type of the service the browser searches for

Default: null

# Methods

Availability
1.2.0
9.2.0
search() void

Conduct a search for Bonjour services matching the type and domain specified during creation

Returns

Type
void

# stopSearch

Availability
1.2.0
9.2.0
stopSearch() void

Halt an ongoing search

Returns

Type
void

# Events

# updatedservices

Availability
3.0.0
9.2.0

Fired when the discovered services list is updated

Properties

Name Type Description
services Array<Titanium.Network.BonjourService>

An array of BonjourService objects corresponding to currently available services. If you cache this value, including using it as table data, be aware that it could become out of date at any time due to the asynchronous nature of Bonjour service discovery.

source Object

Source object that fired the event.

type String

Name of the event fired.

bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.