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 callbackdiscoverCallback 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 portNumber Port the service is available on.
nameString Name to publish the service on. Pass an empty String to use the local computer name.
callbackpublishCallback <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 nameString Name of the peer service.
callbackresolveCallback 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 errorString Error message or null.
peerNetwork.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 statusString 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 errorString Error message or null.
hostString Hostname of the peer.
portNumber Port of the peer.
- Source:
- network.js, line 156