This is the interface to be implemented by the native layer for handling local discovery and peer to peer communication. The ThaliEmmitter
class is for use by developers which communicates with the Thali Peer Communication API.
StartBroadcasting
StopBroadcasting
Connect
Disconnect
KillConnection
peerAvailabilityChanged
networkChanged
METHODS:
This method instructs the native layer to broadcast the availability of the device under the specified deviceName and to direct any incoming connections to the specified port number available on localhost over TCP/IP. Calling this method twice without a StopBroadcasting
call in between will result in an error.
deviceName
:String
– the device name.portNumber
:Number
– a port number to direct any incoming TCP/IP connectionscallback
:Function
– must be in the form of the following,function (err)
where:
err
:String
– a string value containing the error if one occurred, elsenull
This method stops broadcasting of its availability. If this method is called before StartBroadcasting
, this will result in an error.
callback
:Function
– must be in the form of the following, function (err) where:err
:String
– a string value containing the error if one occurred, elsenull
This method instructs the native layer to establish a TCP/IP connection to the peer identified by the peerIdentifier, which is obtained via a peerAvailabilityChanged
event. If this is called twice with the same peer identifier without a Disconnect
call will result in an error.
peerIdentifier
:String
– peer identifier found during thepeerAvailabilityChanged
event.callback
:Function
– must be in the form of the following,function (err, port)
where:err
:String
– a string value containing the error if one occurred, else nullport
:Number
– the port number to connect to the remote peer over TCP/IP
This method disconnects from the peer by the given peer identifier. If the peer is already disconnected and Disconnect
is called again will result in an error in the callback.
peerIdentifier
:String
– peer identifier found during the peerAvailabilityChanged event.callback
:Function
– must be in the form of the following,function (err)
where:err
:String
– a string value containing the error if one occurred, elsenull
This method kills the connection for the given peer identifier to simulate crashes. There is no cleanup done on the connection during the kill connection. This is not intended for use in production code and is solely used for testing.
peerIdentifier
:String
– peer identifier found during the peerAvailabilityChanged event.callback
:Function
– must be in the form of the following,function (err)
where:err
:String
– a string value containing the error if one occurred, elsenull
EVENTS:
This event is called when a peer’s availability has changed.
peers
:Array<PeerAvailability>
wherePeerAvailability
has the following properties:peerIdentifier
:String
– the peer identifierpeerName
:String
– the name of the peerpeerAvailable
:Boolean
– whether the peer is available or not
This event is called when the network has changed.
networkChanged
:NetworkChanged
where it has the following properties:isAvailable
:Boolean
– whether the network is availableisWifi
:Boolean
– whether or not the network is WiFi