From 272f0929d0be0a23587aba50b6692b8b32438cb3 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Sun, 26 Apr 2020 10:28:51 -0300 Subject: [PATCH] Generated documentation --- Documentation/Home.md | 8 + Documentation/MultipeerConfiguration.md | 81 +++++++++++ .../MultipeerConfiguration_Invitation.md | 36 +++++ .../MultipeerConfiguration_Security.md | 71 +++++++++ Documentation/MultipeerDataSource.md | 39 +++++ Documentation/MultipeerTransceiver.md | 137 ++++++++++++++++++ Documentation/Peer.md | 45 ++++++ Documentation/_Footer.md | 1 + Documentation/_Sidebar.md | 11 ++ 9 files changed, 429 insertions(+) create mode 100755 Documentation/Home.md create mode 100755 Documentation/MultipeerConfiguration.md create mode 100755 Documentation/MultipeerConfiguration_Invitation.md create mode 100755 Documentation/MultipeerConfiguration_Security.md create mode 100755 Documentation/MultipeerDataSource.md create mode 100755 Documentation/MultipeerTransceiver.md create mode 100755 Documentation/Peer.md create mode 100755 Documentation/_Footer.md create mode 100755 Documentation/_Sidebar.md diff --git a/Documentation/Home.md b/Documentation/Home.md new file mode 100755 index 0000000..18c40f0 --- /dev/null +++ b/Documentation/Home.md @@ -0,0 +1,8 @@ +# Types + + - [MultipeerConfiguration](MultipeerConfiguration) + - [MultipeerConfiguration.Invitation](MultipeerConfiguration_Invitation) + - [MultipeerConfiguration.Security](MultipeerConfiguration_Security) + - [MultipeerDataSource](MultipeerDataSource) + - [MultipeerTransceiver](MultipeerTransceiver) + - [Peer](Peer) diff --git a/Documentation/MultipeerConfiguration.md b/Documentation/MultipeerConfiguration.md new file mode 100755 index 0000000..a76f954 --- /dev/null +++ b/Documentation/MultipeerConfiguration.md @@ -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` +``` diff --git a/Documentation/MultipeerConfiguration_Invitation.md b/Documentation/MultipeerConfiguration_Invitation.md new file mode 100755 index 0000000..a32bdab --- /dev/null +++ b/Documentation/MultipeerConfiguration_Invitation.md @@ -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 +``` diff --git a/Documentation/MultipeerConfiguration_Security.md b/Documentation/MultipeerConfiguration_Security.md new file mode 100755 index 0000000..f34d2f5 --- /dev/null +++ b/Documentation/MultipeerConfiguration_Security.md @@ -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` +``` diff --git a/Documentation/MultipeerDataSource.md b/Documentation/MultipeerDataSource.md new file mode 100755 index 0000000..f359435 --- /dev/null +++ b/Documentation/MultipeerDataSource.md @@ -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] +``` diff --git a/Documentation/MultipeerTransceiver.md b/Documentation/MultipeerTransceiver.md new file mode 100755 index 0000000..42e0d73 --- /dev/null +++ b/Documentation/MultipeerTransceiver.md @@ -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(_ 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(_ payload: T) +``` + +#### Parameters + + - payload: The payload to be sent. + +### `send(_:to:)` + +Sends a message to a specific peer. + +``` swift +public func send(_ 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. diff --git a/Documentation/Peer.md b/Documentation/Peer.md new file mode 100755 index 0000000..163a06f --- /dev/null +++ b/Documentation/Peer.md @@ -0,0 +1,45 @@ +# Peer + +Represents a remote peer. + +``` swift +public struct Peer: Hashable, Identifiable +``` + +## Inheritance + +`Hashable`, `Identifiable` + +## Properties + +### `id` + +The unique identifier for the peer. + +``` swift +let id: String +``` + +### `name` + +The peer's display name. + +``` swift +let name: String +``` + +### `discoveryInfo` + +Discovery info provided by the peer. + +``` swift +let discoveryInfo: [String: String]? +``` + +### `isConnected` + +`true` if we are currently connected to this peer. + +``` swift +var isConnected: Bool +``` diff --git a/Documentation/_Footer.md b/Documentation/_Footer.md new file mode 100755 index 0000000..d868372 --- /dev/null +++ b/Documentation/_Footer.md @@ -0,0 +1 @@ +Generated at 2020-04-26T10:28:31-0300 using [swift-doc](https://github.com/SwiftDocOrg/swift-doc). diff --git a/Documentation/_Sidebar.md b/Documentation/_Sidebar.md new file mode 100755 index 0000000..1d14c96 --- /dev/null +++ b/Documentation/_Sidebar.md @@ -0,0 +1,11 @@ +
+Types + + - [MultipeerConfiguration](/MultipeerConfiguration) + - [MultipeerConfiguration.Invitation](/MultipeerConfiguration_Invitation) + - [MultipeerConfiguration.Security](/MultipeerConfiguration_Security) + - [MultipeerDataSource](/MultipeerDataSource) + - [MultipeerTransceiver](/MultipeerTransceiver) + - [Peer](/Peer) + +