Skip to content

Commit

Permalink
Generated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
insidegui committed Apr 26, 2020
1 parent bcfda0e commit 272f092
Show file tree
Hide file tree
Showing 9 changed files with 429 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Documentation/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Types

- [MultipeerConfiguration](MultipeerConfiguration)
- [MultipeerConfiguration.Invitation](MultipeerConfiguration_Invitation)
- [MultipeerConfiguration.Security](MultipeerConfiguration_Security)
- [MultipeerDataSource](MultipeerDataSource)
- [MultipeerTransceiver](MultipeerTransceiver)
- [Peer](Peer)
81 changes: 81 additions & 0 deletions Documentation/MultipeerConfiguration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# MultipeerConfiguration

Configures several aspects of the multipeer communication.

``` swift
public struct MultipeerConfiguration
```

## Initializers

### `init(serviceType:peerName:defaults:security:invitation:)`

Creates a new configuration.

``` swift
public init(serviceType: String, peerName: String, defaults: UserDefaults, security: Security, invitation: Invitation)
```

#### Parameters

- 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.
- peerName: A display name for this peer that will be shown to nearby peers.
- 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.
- security: The security configuration.
- 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.

## Properties

### `serviceType`

This must be the same accross your app running on multiple devices,
it must be a short string.

``` swift
var serviceType: String
```

Check Apple's docs on `MCNearbyServiceAdvertiser` for more info on the limitations for this field.

### `peerName`

A display name for this peer that will be shown to nearby peers.

``` swift
var peerName: String
```

### `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 extensions,
make sure to use a shared app group if you wish to maintain a stable identity.

``` swift
var defaults: UserDefaults
```

### `security`

The security configuration.

``` swift
var security: Security
```

### `invitation`

Defines how the multipeer connection handles newly discovered peers.

``` swift
var invitation: Invitation
```

### `` `default` ``

The default configuration, uses the service type `MKSVC`, the name of the device/computer as the
display name, `UserDefaults.standard`, the default security configuration and automatic invitation.

``` swift
let `default`
```
36 changes: 36 additions & 0 deletions Documentation/MultipeerConfiguration_Invitation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# MultipeerConfiguration.Invitation

Defines how the multipeer connection handles newly discovered peers.
New peers can be invited automatically, invited with a custom context and timeout,
or not invited at all, in which case you must invite them manually.

``` swift
public enum Invitation
```

## Enumeration Cases

### `automatic`

When `.automatic` is used, all found peers will be immediately invited to join the session.

``` swift
case automatic
```

### `custom`

Use `.custom` when you want to control the invitation of new peers to your session,
but still invite them at the time of discovery.

``` swift
case custom(: (Peer) throws -> (context: Data, timeout: TimeInterval)?)
```

### `none`

Use `.none` when you want to manually invite peers by calling `invite` in `MultipeerTransceiver`.

``` swift
case none
```
71 changes: 71 additions & 0 deletions Documentation/MultipeerConfiguration_Security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# MultipeerConfiguration.Security

Configures security-related aspects of the multipeer connection.

``` swift
public struct Security
```

## Nested Type Aliases

### `InvitationHandler`

``` swift
public typealias InvitationHandler = (Peer, Data?, @escaping (Bool) -> Void) -> Void
```

## Initializers

### `init(identity:encryptionPreference:invitationHandler:)`

``` swift
public init(identity: [Any]?, encryptionPreference: MCEncryptionPreference, invitationHandler: @escaping InvitationHandler)
```

## Properties

### `identity`

An array of information that can be used to identify the peer to other nearby peers.

``` swift
var identity: [Any]?
```

The first object in this array should be a `SecIdentity` object that provides the local peer’s identity.

The remainder of the array should contain zero or more additional SecCertificate objects that provide any
intermediate certificates that nearby peers might require when verifying the local peer’s identity.
These certificates should be sent in certificate chain order.

Check Apple's `MCSession` docs for more information.

### `encryptionPreference`

Configure the level of encryption to be used for communications.

``` swift
var encryptionPreference: MCEncryptionPreference
```

### `invitationHandler`

A custom closure to be used when handling invitations received by remote peers.

``` swift
var invitationHandler: InvitationHandler
```

It receives the `Peer` that sent the invitation, a custom `Data` value
that's a context that can be used to customize the invitation,
and a closure to be called with `true` to accept the invitation or `false` to reject it.

The default implementation accepts all invitations.

### `` `default` ``

The default security configuration, which has no identity, uses no encryption and accepts all invitations.

``` swift
let `default`
```
39 changes: 39 additions & 0 deletions Documentation/MultipeerDataSource.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# MultipeerDataSource

``` swift
@available(tvOS 13.0, *) @available(OSX 10.15, *) @available(iOS 13.0, *) public final class MultipeerDataSource: ObservableObject
```

## Inheritance

`ObservableObject`

## Initializers

### `init(transceiver:)`

Initializes a new data source.

``` swift
public init(transceiver: MultipeerTransceiver)
```

#### Parameters

- 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.

## Properties

### `transceiver`

``` swift
let transceiver: MultipeerTransceiver
```

### `availablePeers`

Peers currently available for invitation, connection and data transmission.

``` swift
var availablePeers: [Peer]
```
137 changes: 137 additions & 0 deletions Documentation/MultipeerTransceiver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# MultipeerTransceiver

Handles all aspects related to the multipeer communication.

``` swift
public final class MultipeerTransceiver
```

## Initializers

### `init(configuration:)`

Initializes a new transceiver.

``` swift
public init(configuration: MultipeerConfiguration = .default)
```

#### Parameters

- configuration: The configuration, uses the default configuration if none specified.

## Properties

### `availablePeersDidChange`

Called on the main queue when available peers have changed (new peers discovered or peers removed).

``` swift
var availablePeersDidChange: ([Peer]) -> Void
```

### `peerAdded`

Called on the main queue when a new peer discovered.

``` swift
var peerAdded: (Peer) -> Void
```

### `peerRemoved`

Called on the main queue when a peer removed.

``` swift
var peerRemoved: (Peer) -> Void
```

### `availablePeers`

All peers currently available for invitation, connection and data transmission.

``` swift
var availablePeers: [Peer]
```

## Methods

### `receive(_:using:)`

Configures a new handler for a specific `Codable` type.

``` swift
public func receive<T: Codable>(_ type: T.Type, using closure: @escaping (_ payload: T) -> Void)
```

MultipeerKit communicates data between peers as JSON-encoded payloads which originate with
`Codable` entities. You register a closure to handle each specific type of entity,
and this closure is automatically called by the framework when a remote peer sends
a message containing an entity that decodes to the specified type.

#### Parameters

- type: The `Codable` type to receive.
- closure: The closure that will be called whenever a payload of the specified type is received.
- payload: The payload decoded from the remote message.

### `resume()`

Resumes the transceiver, allowing this peer to be discovered and to discover remote peers.

``` swift
public func resume()
```

### `stop()`

Stops the transceiver, preventing this peer from discovering and being discovered.

``` swift
public func stop()
```

### `broadcast(_:)`

Sends a message to all connected peers.

``` swift
public func broadcast<T: Encodable>(_ payload: T)
```

#### Parameters

- payload: The payload to be sent.

### `send(_:to:)`

Sends a message to a specific peer.

``` swift
public func send<T: Encodable>(_ payload: T, to peers: [Peer])
```

#### Parameters

- payload: The payload to be sent.
- peers: An array of peers to send the message to.

### `invite(_:with:timeout:completion:)`

Manually invite a peer for communicating.

``` swift
public func invite(_ peer: Peer, with context: Data?, timeout: TimeInterval, completion: InvitationCompletionHandler?)
```

You can call this method to manually invite a peer for communicating if you set the
`invitation` parameter to `.none` in the transceiver's `configuration`.

> Warning: If the invitation parameter is not set to `.none`, you shouldn't call this method, since the transceiver does the inviting automatically.

#### Parameters

- peer: The peer to be invited.
- context: Custom data to be sent alongside the invitation.
- timeout: How long to wait for the remote peer to accept the invitation.
- completion: Called when the invitation succeeds or fails.
Loading

0 comments on commit 272f092

Please sign in to comment.