Skip to content

Commit

Permalink
Merge pull request #15 from insidegui/connection-callbacks
Browse files Browse the repository at this point in the history
Added callbacks for peer connection and disconnection
  • Loading branch information
insidegui authored Jul 7, 2021
2 parents 951b29d + 512b8ff commit ee013fd
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Sources/MultipeerKit/Public API/MultipeerTransceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public final class MultipeerTransceiver {
/// Called on the main queue when a peer removed.
public var peerRemoved: (Peer) -> Void = { _ in }

/// Called on the main queue when a connection is established with a peer.
public var peerConnected: (Peer) -> Void = { _ in }

/// Called on the main queue when the connection with a peer is interrupted.
public var peerDisconnected: (Peer) -> Void = { _ in }

/// The current device's peer id
public var localPeerId: String? {
return connection.getLocalPeerId()
Expand Down Expand Up @@ -174,10 +180,14 @@ public final class MultipeerTransceiver {

private func handlePeerConnected(_ peer: Peer) {
setConnected(true, on: peer)

peerConnected(peer)
}

private func handlePeerDisconnected(_ peer: Peer) {
setConnected(false, on: peer)

peerDisconnected(peer)
}

private func setConnected(_ connected: Bool, on peer: Peer) {
Expand Down

0 comments on commit ee013fd

Please sign in to comment.