Bonjour is a little service for easy communication with bonjour protocol
supported devices.
- Swift
5.2
- iOS
11.0
- macOS
10.13
Install via Cocoapods
pod 'Bonjour'
-
Init session
let bonjour = BonjourSession(configuration: .init(configuration: .default))
-
Start / stop session:
// Start broadcasting bonjour.start() // Stop broadcasting bonjour.stop()
-
Implement optional handlers:
// On start receiving large package of data. bonjour.onStartRecieving = { resourceName, peer in ... } // Track large package of data receiving progress. bonjour.onReceiving = { resourceName, progress in ... } // On finish receiving large package of data. bonjour.onFinishRecieving = { resourceName, peer, localURL, error in ... } // On small package of data receive. bonjour.onReceive = { data, peer in ... } // On new peer discovery. bonjour.onPeerDiscovery = { peer in ... } // On loss of peer. bonjour.onPeerLoss = { peer in ... } // On connection to peer. bonjour.onPeerConnection = { peer in ... } // On disconnection from peer. bonjour.onPeerDisconnection = { peer in ... } // On update of list of available peers. bonjour.onAvailablePeersDidChange = { availablePeers in ... }
-
Send messages/data:
// Send small package of data to all connected peers. bonjour.broadcast(_ data: Data) // Send small package of data to certain amount of connected peers. bonjour.send(_ data: Data, to peers: [Peer]) // Send large package of data to a certain peer. bonjour.sendResource(at url: URL, resourceName: String, to peer: Peer, progressHandler: ((Double) -> Void)?, completionHandler: ((Error?) -> Void)?)
Eugene Bokhan Software Engineer |
---|
Project's license is MIT.