Skip to content

Commit

Permalink
Merge pull request #8 from JordanOsterberg/master
Browse files Browse the repository at this point in the history
Added localPeerId variable to MultipeerTranseiver
  • Loading branch information
insidegui authored May 14, 2020
2 parents a32759c + 86b66ec commit a135dbd
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Documentation/MultipeerConfiguration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ <h3>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:16-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/MultipeerConfiguration_Invitation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ <h3>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:16-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/MultipeerConfiguration_Security/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ <h3>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:16-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
11 changes: 5 additions & 6 deletions Documentation/MultipeerDataSource/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1215,28 +1215,27 @@ <h2 hidden>Relationships</h2>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.42.3 (20191010.1750)
<!-- Generated by graphviz version 2.44.0 (20200408.0750)
-->
<!-- Title: %3 Pages: 1 -->
<!-- Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- MultipeerDataSource -->
<g id="node1" class="node class current">
<title>MultipeerDataSource</title>
<g id="a_node1"><a xlink:href="/MultipeerDataSource" xlink:title="MultipeerDataSource">
<path fill="none" stroke="black" stroke-width="3" d="M528,-108C528,-108 336,-108 336,-108 330,-108 324,-102 324,-96 324,-96 324,-84 324,-84 324,-78 330,-72 336,-72 336,-72 528,-72 528,-72 534,-72 540,-78 540,-84 540,-84 540,-96 540,-96 540,-102 534,-108 528,-108"/>
<text text-anchor="middle" x="432" y="-86.95" font-family="Menlo" font-size="14.00">MultipeerDataSource</text>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00">MultipeerDataSource</text>
</a>
</g>
</g>
<!-- ObservableObject -->
<g id="node2" class="node unknown">
<title>ObservableObject</title>
<path fill="none" stroke="black" d="M528,-36C528,-36 336,-36 336,-36 330,-36 324,-30 324,-24 324,-24 324,-12 324,-12 324,-6 330,0 336,0 336,0 528,0 528,0 534,0 540,-6 540,-12 540,-12 540,-24 540,-24 540,-30 534,-36 528,-36"/>
<text text-anchor="middle" x="432" y="-14.95" font-family="Menlo" font-size="14.00">ObservableObject</text>
<text text-anchor="middle" x="432" y="-14.3" font-family="Menlo" font-size="14.00">ObservableObject</text>
</g>
<!-- MultipeerDataSource&#45;&gt;ObservableObject -->
<g id="edge1" class="edge conformsTo">
Expand Down Expand Up @@ -1316,7 +1315,7 @@ <h3>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:17-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
14 changes: 12 additions & 2 deletions Documentation/MultipeerTransceiver/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@
<nav>
<div class="wrapper">
<h2>On This Page</h2>
<ol><li><a href="#initializers">Initializers</a><ul><li class="initializer"><a href="#multipeertransceiver.init(configuration:)">init(configuration:​)</a></li></ul></li><li><a href="#properties">Properties</a><ul><li class="property"><a href="#multipeertransceiver.availablepeersdidchange">available​Peers​Did​Change</a></li><li class="property"><a href="#multipeertransceiver.peeradded">peer​Added</a></li><li class="property"><a href="#multipeertransceiver.peerremoved">peer​Removed</a></li><li class="property"><a href="#multipeertransceiver.availablepeers">available​Peers</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="method"><a href="#multipeertransceiver.receive(_:using:)">receive(_:​using:​)</a></li><li class="method"><a href="#multipeertransceiver.resume()">resume()</a></li><li class="method"><a href="#multipeertransceiver.stop()">stop()</a></li><li class="method"><a href="#multipeertransceiver.broadcast(_:)">broadcast(_:​)</a></li><li class="method"><a href="#multipeertransceiver.send(_:to:)">send(_:​to:​)</a></li><li class="method"><a href="#multipeertransceiver.invite(_:with:timeout:completion:)">invite(_:​with:​timeout:​completion:​)</a></li></ul></li></ol>
<ol><li><a href="#initializers">Initializers</a><ul><li class="initializer"><a href="#multipeertransceiver.init(configuration:)">init(configuration:​)</a></li></ul></li><li><a href="#properties">Properties</a><ul><li class="property"><a href="#multipeertransceiver.availablepeersdidchange">available​Peers​Did​Change</a></li><li class="property"><a href="#multipeertransceiver.peeradded">peer​Added</a></li><li class="property"><a href="#multipeertransceiver.peerremoved">peer​Removed</a></li><li class="property"><a href="#multipeertransceiver.localpeerid">local​Peer​Id</a></li><li class="property"><a href="#multipeertransceiver.availablepeers">available​Peers</a></li></ul></li><li><a href="#methods">Methods</a><ul><li class="method"><a href="#multipeertransceiver.receive(_:using:)">receive(_:​using:​)</a></li><li class="method"><a href="#multipeertransceiver.resume()">resume()</a></li><li class="method"><a href="#multipeertransceiver.stop()">stop()</a></li><li class="method"><a href="#multipeertransceiver.broadcast(_:)">broadcast(_:​)</a></li><li class="method"><a href="#multipeertransceiver.send(_:to:)">send(_:​to:​)</a></li><li class="method"><a href="#multipeertransceiver.invite(_:with:timeout:completion:)">invite(_:​with:​timeout:​completion:​)</a></li></ul></li></ol>
</div>
</nav>

Expand Down Expand Up @@ -1278,6 +1278,16 @@ <h3>
<div class="summary" role="doc-abstract">
<p>Called on the main queue when a peer removed.</p>

</div>
</div>
<div role="article" class="class" id="multipeertransceiver.localpeerid">
<h3>
<code>local​Peer​Id</code>
</h3>
<html><body><pre class="highlight"><code><span class="keyword">var</span> <span class="variable">localPeerId</span>: <span class="type">String</span>?</code></pre></body></html>
<div class="summary" role="doc-abstract">
<p>The current device's peer id</p>

</div>
</div>
<div role="article" class="class" id="multipeertransceiver.availablepeers">
Expand Down Expand Up @@ -1491,7 +1501,7 @@ <h4>Parameters</h4>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:16-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
33 changes: 16 additions & 17 deletions Documentation/Peer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1219,44 +1219,43 @@ <h2 hidden>Relationships</h2>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.42.3 (20191010.1750)
<!-- Generated by graphviz version 2.44.0 (20200408.0750)
-->
<!-- Title: %3 Pages: 1 -->
<!-- Pages: 1 -->
<svg width="872pt" height="116pt"
viewBox="0.00 0.00 872.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 868,-112 868,4 -4,4"/>
<!-- Peer -->
<g id="node1" class="node structure current">
<title>Peer</title>
<g id="a_node1"><a xlink:href="/Peer" xlink:title="Peer">
<path fill="none" stroke="black" stroke-width="3" d="M528,-108C528,-108 336,-108 336,-108 330,-108 324,-102 324,-96 324,-96 324,-84 324,-84 324,-78 330,-72 336,-72 336,-72 528,-72 528,-72 534,-72 540,-78 540,-84 540,-84 540,-96 540,-96 540,-102 534,-108 528,-108"/>
<text text-anchor="middle" x="432" y="-86.95" font-family="Menlo" font-size="14.00">Peer</text>
<text text-anchor="middle" x="432" y="-86.3" font-family="Menlo" font-size="14.00">Peer</text>
</a>
</g>
</g>
<!-- Hashable -->
<!-- Identifiable -->
<g id="node2" class="node unknown">
<title>Hashable</title>
<title>Identifiable</title>
<path fill="none" stroke="black" d="M303,-36C303,-36 111,-36 111,-36 105,-36 99,-30 99,-24 99,-24 99,-12 99,-12 99,-6 105,0 111,0 111,0 303,0 303,0 309,0 315,-6 315,-12 315,-12 315,-24 315,-24 315,-30 309,-36 303,-36"/>
<text text-anchor="middle" x="207" y="-14.95" font-family="Menlo" font-size="14.00">Hashable</text>
<text text-anchor="middle" x="207" y="-14.3" font-family="Menlo" font-size="14.00">Identifiable</text>
</g>
<!-- Peer&#45;&gt;Hashable -->
<g id="edge1" class="edge conformsTo">
<title>Peer&#45;&gt;Hashable</title>
<!-- Peer&#45;&gt;Identifiable -->
<g id="edge2" class="edge conformsTo">
<title>Peer&#45;&gt;Identifiable</title>
<path fill="none" stroke="black" d="M377.25,-71.97C345.4,-62.06 305.08,-49.51 271.67,-39.12"/>
<polygon fill="black" stroke="black" points="272.59,-35.74 262,-36.11 270.51,-42.42 272.59,-35.74"/>
</g>
<!-- Identifiable -->
<!-- Hashable -->
<g id="node3" class="node unknown">
<title>Identifiable</title>
<title>Hashable</title>
<path fill="none" stroke="black" d="M753,-36C753,-36 561,-36 561,-36 555,-36 549,-30 549,-24 549,-24 549,-12 549,-12 549,-6 555,0 561,0 561,0 753,0 753,0 759,0 765,-6 765,-12 765,-12 765,-24 765,-24 765,-30 759,-36 753,-36"/>
<text text-anchor="middle" x="657" y="-14.95" font-family="Menlo" font-size="14.00">Identifiable</text>
<text text-anchor="middle" x="657" y="-14.3" font-family="Menlo" font-size="14.00">Hashable</text>
</g>
<!-- Peer&#45;&gt;Identifiable -->
<g id="edge2" class="edge conformsTo">
<title>Peer&#45;&gt;Identifiable</title>
<!-- Peer&#45;&gt;Hashable -->
<g id="edge1" class="edge conformsTo">
<title>Peer&#45;&gt;Hashable</title>
<path fill="none" stroke="black" d="M486.75,-71.97C518.6,-62.06 558.92,-49.51 592.33,-39.12"/>
<polygon fill="black" stroke="black" points="593.49,-42.42 602,-36.11 591.41,-35.74 593.49,-42.42"/>
</g>
Expand Down Expand Up @@ -1324,7 +1323,7 @@ <h3>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:17-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
2 changes: 1 addition & 1 deletion Documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ <h2>Enumerations</h2>

<footer>
<p>
Generated on <time datetime="2020-04-26T10:31:16-0300">26 April 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
Generated on <time datetime="2020-05-13T15:25:40-0700">May 13, 2020</time> using <a href="https://github.com/SwiftDocOrg/swift-doc">swift-doc</a>.
</p>
</footer>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ final class MockMultipeerConnection: MultipeerProtocol {
func invite(_ peer: Peer, with context: Data?, timeout: TimeInterval, completion: InvitationCompletionHandler?) {

}

func getLocalPeerId() -> String? {
return "MockId"
}

}
4 changes: 4 additions & 0 deletions Sources/MultipeerKit/Internal API/MultipeerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ final class MultipeerConnection: NSObject, MultipeerProtocol {

browser.invitePeer(peer.underlyingPeer, to: session, withContext: context, timeout: timeout)
}

func getLocalPeerId() -> String? {
return try? Peer(peer: me, discoveryInfo: nil).id
}

}

Expand Down
2 changes: 2 additions & 0 deletions Sources/MultipeerKit/Internal API/MultipeerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ protocol MultipeerProtocol: AnyObject {
func invite(_ peer: Peer, with context: Data?, timeout: TimeInterval, completion: InvitationCompletionHandler?)
func broadcast(_ data: Data) throws
func send(_ data: Data, to peers: [Peer]) throws

func getLocalPeerId() -> String?

}
5 changes: 5 additions & 0 deletions Sources/MultipeerKit/Public API/MultipeerTransceiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public final class MultipeerTransceiver {
/// Called on the main queue when a peer removed.
public var peerRemoved: (Peer) -> Void = { _ in }

/// The current device's peer id
public var localPeerId: String? {
return connection.getLocalPeerId()
}

/// All peers currently available for invitation, connection and data transmission.
public private(set) var availablePeers: [Peer] = [] {
didSet {
Expand Down

0 comments on commit a135dbd

Please sign in to comment.