 //
-//  Sploosh.swift
+//  CoulombNetwork.swift
 //  NetworkLib
 //
 //  Created by Ian Ngiaw on 3/14/16.

            return
        }
        
        DLog("%@", "invitePeer: \(peerID)")
        foundHosts.append(peerID)
        delegate?.foundHostsChanged(foundHosts)
    }

        session.delegate = self
        return session
    }()
    private let myPeerId: MCPeerID
    private var host: MCPeerID?
    private let serviceType: String
    
    public init(serviceType: String, myPeerId: MCPeerID) {
        self.serviceType = serviceType
        self.myPeerId = myPeerId
    }
    
    deinit {
        print("Coulomb deinit")
        stopAdvertisingHost()
        stopSearchingForHosts()
        session.disconnect()
    }
    
    func setUpSession() {
        session.delegate = self
    }
    // MARK: Methods for host
    public func startAdvertisingHost() {
        stopSearchingForHosts()
        self.host = myPeerId

        serviceAdvertiser = MCNearbyServiceAdvertiser(peer: myPeerId,
                                                      discoveryInfo: ["peerType": "host"], serviceType: serviceType)
        self.serviceAdvertiser?.delegate = self
        
        self.serviceAdvertiser?.startAdvertisingPeer()
    }
    
    public func stopAdvertisingHost() {
        self.host = nil
        serviceAdvertiser?.stopAdvertisingPeer()
        serviceAdvertiser?.delegate = nil
    }
    
    // MARK: Methods for guest
    public func startSearchingForHosts() {
        self.host = nil

        serviceBrowser = MCNearbyServiceBrowser(peer: myPeerId, serviceType: serviceType)
        serviceBrowser?.delegate = self

        foundHosts = []
        serviceBrowser?.startBrowsingForPeers()
    }
