Class: Bonjour

Network. Bonjour

new Bonjour(type, domain) → {boolean}

Create a new Bonjour service.

Parameters:
Name Type Argument Default Description
type String <optional>
_game._tcp

Type of the service.

domain String <optional>
local

Domain to make the service available to.

Source:
  • network.js, line 62
Returns:

true on success, false on failure.

Type
boolean

Members

domain :String

Type:
  • String
Source:
  • network.js, line 66

type :String

Type:
  • String
Source:
  • network.js, line 64

Methods

discover(callback)

Discover published peers in the domain.

Parameters:
Name Type Description
callback discoverCallback

Callback called when a peer is found.

Source:
  • network.js, line 85

publish(port, name, callback)

Publish a new service.

Parameters:
Name Type Argument Description
port Number

Port the service is available on.

name String

Name to publish the service on. Pass an empty String to use the local computer name.

callback publishCallback <optional>

Callback to retrieve status.

Source:
  • network.js, line 77

resolve(name, callback)

Resolve a name to a hostname and port.

You should not store the hostname and port in a persistent storage, as it might change over time. Store the name instead and call Bonjour.resolve().

Parameters:
Name Type Description
name String

Name of the peer service.

callback resolveCallback

Callback called when a hostname+port combination is found.

Source:
  • network.js, line 99

stop()

Stop publishing, discovering or resolving.

Call this when you found your peers and want to play the game. After this call, you can still call resolve() again to re-resolve a peer.

Source:
  • network.js, line 109

Type Definitions

discoverCallback(error, peer)

Callback used when a peer is discovered.

Parameters:
Name Type Description
error String

Error message or null.

peer Network.Bonjour.Peer

The new peer or null.

Source:
  • network.js, line 147

publishCallback(status)

Callback used when publishing is complete or it failed.

Parameters:
Name Type Description
status String

Result-status of publishing.

Source:
  • network.js, line 139

resolveCallback(error, host, port)

Callback used when a host+port combination is resolved.

Parameters:
Name Type Description
error String

Error message or null.

host String

Hostname of the peer.

port Number

Port of the peer.

Source:
  • network.js, line 156