Swiftpack.co - Package - eugenebokhan/Bonjour

Bonjour

Bonjour is a little service for easy communication with bonjour protocol supported devices.

Requirements

  • Swift 5.2
  • iOS 11.0
  • macOS 10.13

Install via Cocoapods

pod 'Bonjour'

How To Use

  • 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)?)
    

Author

| | Eugene Bokhan

Software Engineer
Twitter Github LinkedIn| | - | :- |

License

Project's license is MIT.

Github

link
Stars: 2

Dependencies

Used By

Total: 1

Releases

Release ver. 2.0.1 - 2020-09-14 11:35:23

Release ver. 2.0.1

Release ver. 2.0.0 - 2020-06-04 19:29:56