Giter Club home page Giter Club logo

bonjour's Introduction

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 SwiftPM

.package(url: "https://github.com/eugenebokhan/Bonjour.git",
         .upToNextMinor(from: "2.1.0"))

How To Use

  • Init session

    let bonjour = BonjourSession(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)?)

Info.plist configuration

In order for BonjourSession to work when running on iOS 14, you will have to include two keys in your app's Info.plist file.

The keys are Privacy - Local Network Usage Description (NSLocalNetworkUsageDescription) and Bonjour services (NSBonjourServices).

For the privacy key, include a human-readable description of what benefit the user gets by allowing your app to access devices on the local network.

The Bonjour services key is an array of service types that your app will browse for. For BonjourSession, the entry should be in the format _servicename._tcp, where servicename is the serviceType you've set in your MultipeerConfiguration. If you're using the default configuration, the value of this key should be _Bonjour._tcp.

If you do not configure the above keys properly, then BonjourSession won't work.

License

Project's license is MIT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.