Skip to content

Commit 272f092

Browse files
committed
Generated documentation
1 parent bcfda0e commit 272f092

9 files changed

Lines changed: 429 additions & 0 deletions

Documentation/Home.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Types
2+
3+
- [MultipeerConfiguration](MultipeerConfiguration)
4+
- [MultipeerConfiguration.Invitation](MultipeerConfiguration_Invitation)
5+
- [MultipeerConfiguration.Security](MultipeerConfiguration_Security)
6+
- [MultipeerDataSource](MultipeerDataSource)
7+
- [MultipeerTransceiver](MultipeerTransceiver)
8+
- [Peer](Peer)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# MultipeerConfiguration
2+
3+
Configures several aspects of the multipeer communication.
4+
5+
``` swift
6+
public struct MultipeerConfiguration
7+
```
8+
9+
## Initializers
10+
11+
### `init(serviceType:peerName:defaults:security:invitation:)`
12+
13+
Creates a new configuration.
14+
15+
``` swift
16+
public init(serviceType: String, peerName: String, defaults: UserDefaults, security: Security, invitation: Invitation)
17+
```
18+
19+
#### Parameters
20+
21+
- serviceType: This must be the same accross your app running on multiple devices, it must be a short string. Check Apple's docs on `MCNearbyServiceAdvertiser` for more info on the limitations for this field.
22+
- peerName: A display name for this peer that will be shown to nearby peers.
23+
- defaults: An instance of `UserDefaults` that's used to store this peer's identity so that it remains stable between different sessions. If you use MultipeerKit in app extension make sure to use a shared app group if you wish to maintain a stable identity.
24+
- security: The security configuration.
25+
- invitation: Defines how the multipeer connection handles newly discovered peers. New peers can be invited automatically, invited with a custom context or not invited at all, in which case you must invite them manually.
26+
27+
## Properties
28+
29+
### `serviceType`
30+
31+
This must be the same accross your app running on multiple devices,
32+
it must be a short string.
33+
34+
``` swift
35+
var serviceType: String
36+
```
37+
38+
Check Apple's docs on `MCNearbyServiceAdvertiser` for more info on the limitations for this field.
39+
40+
### `peerName`
41+
42+
A display name for this peer that will be shown to nearby peers.
43+
44+
``` swift
45+
var peerName: String
46+
```
47+
48+
### `defaults`
49+
50+
An instance of `UserDefaults` that's used to store this peer's identity so that it
51+
remains stable between different sessions. If you use MultipeerKit in app extensions,
52+
make sure to use a shared app group if you wish to maintain a stable identity.
53+
54+
``` swift
55+
var defaults: UserDefaults
56+
```
57+
58+
### `security`
59+
60+
The security configuration.
61+
62+
``` swift
63+
var security: Security
64+
```
65+
66+
### `invitation`
67+
68+
Defines how the multipeer connection handles newly discovered peers.
69+
70+
``` swift
71+
var invitation: Invitation
72+
```
73+
74+
### `` `default` ``
75+
76+
The default configuration, uses the service type `MKSVC`, the name of the device/computer as the
77+
display name, `UserDefaults.standard`, the default security configuration and automatic invitation.
78+
79+
``` swift
80+
let `default`
81+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# MultipeerConfiguration.Invitation
2+
3+
Defines how the multipeer connection handles newly discovered peers.
4+
New peers can be invited automatically, invited with a custom context and timeout,
5+
or not invited at all, in which case you must invite them manually.
6+
7+
``` swift
8+
public enum Invitation
9+
```
10+
11+
## Enumeration Cases
12+
13+
### `automatic`
14+
15+
When `.automatic` is used, all found peers will be immediately invited to join the session.
16+
17+
``` swift
18+
case automatic
19+
```
20+
21+
### `custom`
22+
23+
Use `.custom` when you want to control the invitation of new peers to your session,
24+
but still invite them at the time of discovery.
25+
26+
``` swift
27+
case custom(: (Peer) throws -> (context: Data, timeout: TimeInterval)?)
28+
```
29+
30+
### `none`
31+
32+
Use `.none` when you want to manually invite peers by calling `invite` in `MultipeerTransceiver`.
33+
34+
``` swift
35+
case none
36+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# MultipeerConfiguration.Security
2+
3+
Configures security-related aspects of the multipeer connection.
4+
5+
``` swift
6+
public struct Security
7+
```
8+
9+
## Nested Type Aliases
10+
11+
### `InvitationHandler`
12+
13+
``` swift
14+
public typealias InvitationHandler = (Peer, Data?, @escaping (Bool) -> Void) -> Void
15+
```
16+
17+
## Initializers
18+
19+
### `init(identity:encryptionPreference:invitationHandler:)`
20+
21+
``` swift
22+
public init(identity: [Any]?, encryptionPreference: MCEncryptionPreference, invitationHandler: @escaping InvitationHandler)
23+
```
24+
25+
## Properties
26+
27+
### `identity`
28+
29+
An array of information that can be used to identify the peer to other nearby peers.
30+
31+
``` swift
32+
var identity: [Any]?
33+
```
34+
35+
The first object in this array should be a `SecIdentity` object that provides the local peer’s identity.
36+
37+
The remainder of the array should contain zero or more additional SecCertificate objects that provide any
38+
intermediate certificates that nearby peers might require when verifying the local peer’s identity.
39+
These certificates should be sent in certificate chain order.
40+
41+
Check Apple's `MCSession` docs for more information.
42+
43+
### `encryptionPreference`
44+
45+
Configure the level of encryption to be used for communications.
46+
47+
``` swift
48+
var encryptionPreference: MCEncryptionPreference
49+
```
50+
51+
### `invitationHandler`
52+
53+
A custom closure to be used when handling invitations received by remote peers.
54+
55+
``` swift
56+
var invitationHandler: InvitationHandler
57+
```
58+
59+
It receives the `Peer` that sent the invitation, a custom `Data` value
60+
that's a context that can be used to customize the invitation,
61+
and a closure to be called with `true` to accept the invitation or `false` to reject it.
62+
63+
The default implementation accepts all invitations.
64+
65+
### `` `default` ``
66+
67+
The default security configuration, which has no identity, uses no encryption and accepts all invitations.
68+
69+
``` swift
70+
let `default`
71+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# MultipeerDataSource
2+
3+
``` swift
4+
@available(tvOS 13.0, *) @available(OSX 10.15, *) @available(iOS 13.0, *) public final class MultipeerDataSource: ObservableObject
5+
```
6+
7+
## Inheritance
8+
9+
`ObservableObject`
10+
11+
## Initializers
12+
13+
### `init(transceiver:)`
14+
15+
Initializes a new data source.
16+
17+
``` swift
18+
public init(transceiver: MultipeerTransceiver)
19+
```
20+
21+
#### Parameters
22+
23+
- transceiver: The transceiver to be used by this data source. Note that the data source will set `availablePeersDidChange` on the transceiver, so if you wish to use that closure yourself, you won't be able to use the data source.
24+
25+
## Properties
26+
27+
### `transceiver`
28+
29+
``` swift
30+
let transceiver: MultipeerTransceiver
31+
```
32+
33+
### `availablePeers`
34+
35+
Peers currently available for invitation, connection and data transmission.
36+
37+
``` swift
38+
var availablePeers: [Peer]
39+
```
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# MultipeerTransceiver
2+
3+
Handles all aspects related to the multipeer communication.
4+
5+
``` swift
6+
public final class MultipeerTransceiver
7+
```
8+
9+
## Initializers
10+
11+
### `init(configuration:)`
12+
13+
Initializes a new transceiver.
14+
15+
``` swift
16+
public init(configuration: MultipeerConfiguration = .default)
17+
```
18+
19+
#### Parameters
20+
21+
- configuration: The configuration, uses the default configuration if none specified.
22+
23+
## Properties
24+
25+
### `availablePeersDidChange`
26+
27+
Called on the main queue when available peers have changed (new peers discovered or peers removed).
28+
29+
``` swift
30+
var availablePeersDidChange: ([Peer]) -> Void
31+
```
32+
33+
### `peerAdded`
34+
35+
Called on the main queue when a new peer discovered.
36+
37+
``` swift
38+
var peerAdded: (Peer) -> Void
39+
```
40+
41+
### `peerRemoved`
42+
43+
Called on the main queue when a peer removed.
44+
45+
``` swift
46+
var peerRemoved: (Peer) -> Void
47+
```
48+
49+
### `availablePeers`
50+
51+
All peers currently available for invitation, connection and data transmission.
52+
53+
``` swift
54+
var availablePeers: [Peer]
55+
```
56+
57+
## Methods
58+
59+
### `receive(_:using:)`
60+
61+
Configures a new handler for a specific `Codable` type.
62+
63+
``` swift
64+
public func receive<T: Codable>(_ type: T.Type, using closure: @escaping (_ payload: T) -> Void)
65+
```
66+
67+
MultipeerKit communicates data between peers as JSON-encoded payloads which originate with
68+
`Codable` entities. You register a closure to handle each specific type of entity,
69+
and this closure is automatically called by the framework when a remote peer sends
70+
a message containing an entity that decodes to the specified type.
71+
72+
#### Parameters
73+
74+
- type: The `Codable` type to receive.
75+
- closure: The closure that will be called whenever a payload of the specified type is received.
76+
- payload: The payload decoded from the remote message.
77+
78+
### `resume()`
79+
80+
Resumes the transceiver, allowing this peer to be discovered and to discover remote peers.
81+
82+
``` swift
83+
public func resume()
84+
```
85+
86+
### `stop()`
87+
88+
Stops the transceiver, preventing this peer from discovering and being discovered.
89+
90+
``` swift
91+
public func stop()
92+
```
93+
94+
### `broadcast(_:)`
95+
96+
Sends a message to all connected peers.
97+
98+
``` swift
99+
public func broadcast<T: Encodable>(_ payload: T)
100+
```
101+
102+
#### Parameters
103+
104+
- payload: The payload to be sent.
105+
106+
### `send(_:to:)`
107+
108+
Sends a message to a specific peer.
109+
110+
``` swift
111+
public func send<T: Encodable>(_ payload: T, to peers: [Peer])
112+
```
113+
114+
#### Parameters
115+
116+
- payload: The payload to be sent.
117+
- peers: An array of peers to send the message to.
118+
119+
### `invite(_:with:timeout:completion:)`
120+
121+
Manually invite a peer for communicating.
122+
123+
``` swift
124+
public func invite(_ peer: Peer, with context: Data?, timeout: TimeInterval, completion: InvitationCompletionHandler?)
125+
```
126+
127+
You can call this method to manually invite a peer for communicating if you set the
128+
`invitation` parameter to `.none` in the transceiver's `configuration`.
129+
130+
> Warning: If the invitation parameter is not set to `.none`, you shouldn't call this method, since the transceiver does the inviting automatically.
131+
132+
#### Parameters
133+
134+
- peer: The peer to be invited.
135+
- context: Custom data to be sent alongside the invitation.
136+
- timeout: How long to wait for the remote peer to accept the invitation.
137+
- completion: Called when the invitation succeeds or fails.

0 commit comments

Comments
 (0)