Functional wrapper for Apple's MultipeerConnectivity framework.

Overview

PeerConnectivity

Platform: iOS 8+ Language: Swift 3 Carthage compatible Cocoapods compatible Docs License: MIT

A functional wrapper for the MultipeerConnectivity framework.

PeerConnectivity is meant to have a lightweight easy to use syntax, be extensible and flexible, and handle the heavy lifting and edge cases of the MultipeerConnectivity framework quietly in the background.

Please open an issue or submit a pull request if you have any suggestions!

🔌 Blog post https://goo.gl/HJcMbE

Installation

Cocoapods

The easiest way to get started is to use CocoaPods. Just add the following line to your Podfile:

pod 'PeerConnectivity', '~> 0.5.4'

Carthage

github "rchatham/PeerConnectivity"

Creating/Stopping/Starting

var pcm = PeerConnectionManager(serviceType: "local")

// Start
pcm.start()

// Stop
//  - You should always stop the connection manager 
//    before attempting to create a new one
pcm.stop()

// Can join chatrooms using PeerConnectionType.Automatic, .InviteOnly, and .Custom
//  - .Automatic : automatically searches and joins other devices with the same service type
//  - .InviteOnly : provides a browserViewController and invite alert controllers
//  - .Custom : no default behavior is implemented

// The manager can be initialized with a contructed peer representing the local user
// with a custom displayName

pcm = PeerConnectionManager(serviceType: "local", connectionType: .Automatic, displayName: "I_AM_KING")

// Start again at any time
pcm.start() {
    // Do something when finished starting the session
}

Sending Events to Peers

let event: [String: Any] = [
    "EventKey" : Date()
]

// Sends to all connected peers
pcm.sendEvent(event)


// Use this to access the connectedPeers
let connectedPeers: [Peer] = pcm.connectedPeers

// Events can be sent to specific peers
if let somePeerThatIAmConnectedTo = connectedPeers.first {
   pcm.sendEvent(event, toPeers: [somePeerThatIAmConnectedTo])
}

Listening for Events

// Listen to an event
pcm.observeEventListenerForKey("someEvent") { (eventInfo, peer) in
    
    print("Received some event \(eventInfo) from \(peer.displayName)")
    guard let date = eventInfo["eventKey"] as? Date else { return }
    print(date)
    
}

// Stop listening to an event
pcm.removeListenerForKey("SomeEvent")

Acknowledgments

Icon from the Noun Project.

Helpful links

Comments
  • Can't connect (ICE + FAILED BINDING)

    Can't connect (ICE + FAILED BINDING)

    Hi there! Spent a lot of time on trying to resolve the problem, the code is actually here: https://gist.github.com/Luccifer/5e588502992124a1b0ec184361bfcd4c

    Log: https://gist.github.com/Luccifer/60e55e17507012793c8b6d412bf5e9f4

    Help please, I googled it and people usually turning off the encryption, but this didn't help, I have already tried to change it in sources of Pod..

    opened by Luccifer 3
  • intermittent crashing

    intermittent crashing

    Been using this library and it works fine. However, I am getting intermittent errors that cause it to crash. Below is a sample of the crash report

    6 PeerConnectivity 0x00000001013449d8 0x101338000 + 51672 7 PeerConnectivity 0x000000010134ab1c 0x101338000 + 76572 8 PeerConnectivity 0x000000010134b4b4 0x101338000 + 79028 9 PeerConnectivity 0x0000000101356e48 0x101338000 + 126536 10 PeerConnectivity 0x000000010134b2c4 0x101338000 + 78532 11 PeerConnectivity 0x0000000101343164 0x101338000 + 45412 12 PeerConnectivity 0x000000010134ab1c 0x101338000 + 76572 13 PeerConnectivity 0x000000010134b4b4 0x101338000 + 79028 14 PeerConnectivity 0x0000000101353a2c 0x101338000 + 113196 15 PeerConnectivity 0x0000000101353010 0x101338000 + 110608 16 MultipeerConnectivity 0x00000001a1bdf02c __58-[MCSession syncHandleNetworkEvent:pid:freeEventWhenDone:]_block_invoke.630 + 144

    i can't isolate where in the code it's happening. i've seen similar postings like this. seemed to be around the MCSession synchandleNetworkEvent call

    any insight would really help.

    opened by Nathan187 3
  • invite only does not seem to work?

    invite only does not seem to work?

    How do you call the viewcontroller for searching advertisers with the inviteOnly option? it's kind of unclear to me. Just setting the connection type to inviteOnly and then writing pcm.start does not seem to change anything :(

    opened by lucletruc 2
  • Swift 3.0 support by Pod install

    Swift 3.0 support by Pod install

    Hi @rchatham Just want to make sure if Pod install v0.5.3 supports Swift 3.0 already?

    By looking at Github repo, it seems yes, but I still got warning messages after installation. I've followed the instruction to install PeerConnectivity by Pod pod 'PeerConnectivity', '~> 0.5.3'

    Thanks for helping out!

    opened by harryhow 2
  • Feature - (2.0.0-beta)  'node' connection mode

    Feature - (2.0.0-beta) 'node' connection mode

    Description

    status: last testing stage

    This might looks like a lots of change but the pull-request include differents things:

    • new files and update to projects / settings (.gitignore, pod spec, example project, playground)
    • some reoganisation of extensions into new files or re-order of properties of functions
    • update multiple types with news attributes for feature like 'security', 'discoveryInfo' & 'connectionMode'
    • update of the EventProducers for Sessions, Advertiser & Browser

    Sessions - MCSession delegate & event producer

    PeerSession can represent either a advertiser session (local-service) or a connection to a 'distant-service' invited through PeerBrowser

    thus we now have access to the following attributes:

    • sessionPeer - indicate this is a distance-service-session and represent the peer advertising that servicer
    • isLocalServiceSession - computed property that check peer against peerSession
    • isDistantServiceSession - computed property too

    PeerSession can now take security parameter at init allowing to configurer the kind of security to use on the MCSession

    Advertisers - MCNearbyServiceAdvertiser delegate & event producer

    Advertiser didn't change too much, we can now use discoverInfo at init which couple with Peer.context allow better introspection of services and peer.

    Before we used poorly named service to differentiate environment or restaurants, now we can name our services simply and use discoveryInfo to filter matching services.

    Browser - MCNearbyServiceBrowser delegate & event producer

    Main change to browser is the new sessionFactory logic introduced. The browser will use the sessions attribute when uses as a single slave connection, but will create new session through the factory if configured as node browser.

    This will allow to create new session for each services we're connecting to.

    opened by lifely 1
  • Hotfix - OO-844 - PeerConnectivity MultiThreading Issue

    Hotfix - OO-844 - PeerConnectivity MultiThreading Issue

    Description

    Added additional safety on 'foundPeer' modification for on sessionObserver event. This re-use the already available mutex from PeerConnectionManager preventing multiple thread from updating internal data at once.

    Should fix the following firebase crash:

    Firebase #5cdc6448f8b88c296302a7e7

    opened by lifely 0
  • Feature - Adds Invitation.Status, better identification of invitation state

    Feature - Adds Invitation.Status, better identification of invitation state

    Description

    Adds new Invitation.Status type which help identify in which state in the invitation (and thus peer) is.

    Possible cases are unknown, pending, failed and inconsistent in order.

    Best case scenario a invitation would see the following status:

    unknown -> pending -> invitation removed

    In case the invitation fail the following status would happen:

    unknown -> pending -> failed -> pending -> failed -> pending -> invitation removed

    in worst case scenario the invitation would fail quickly:

    unknown -> inconsistent -> inconsistent -> still failing = ignoring peer

    opened by lifely 0
  • Feature - Connection Retry/Attempt with 'Invitation'

    Feature - Connection Retry/Attempt with 'Invitation'

    Description

    Adds 'Invitation' type directly managed by PeerBrowser, once a user called Invite through PeerManager the PeerBrowser will check it's invitation array.

    This allow multiple fixes and security in the connections business logics:

    • It prevent a user to invite the same peer multiple times.
    • it allow PeerManager to retry invitation when the connection failed
    • It also allow to reconnect to peers/advertiser reused by MultipeerConnectivity when a distant PeerAdvertiser has been stop and restart in a small amount of time.
    opened by lifely 0
  • Library Validation

    Library Validation

    Hello,

    There is a problem with the new Xcode. Looks like the library is not signed. Can you please check?

    Regards

    /private/var/containers/Bundle/Application/22001A3E-3E0A-4863-8356-676F91E560D9/thenotebookdigital.app/Frameworks/PeerConnectivity.framework/PeerConnectivity: code signature in (/private/var/containers/Bundle/Application/22001A3E-3E0A-4863-8356-676F91E560D9/thenotebookdigital.app/Frameworks/PeerConnectivity.framework/PeerConnectivity) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.

    opened by leonardoopitz 0
Owner
Reid Chatham
Reid Chatham
AZPeerToPeerConnectivity is a wrapper on top of Apple iOS Multipeer Connectivity framework. It provides an easier way to create and manage sessions. Easy to integrate

AZPeerToPeerConnection Controller Features Multipeer Connectivity Connection via Bluetooth or Wifi No need write all session, browser, services delega

Afroz Zaheer 66 Dec 19, 2022
CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework, making it possible to subscribe to perform bluetooth operations while subscribing to a publisher of the results of those operations, instead of relying on implementing delegates and manually filtering for the results you need.

Starry 74 Dec 29, 2022
iOS Bluetooth LE framework

Features A futures interface replacing protocol implementations. Timeout for Peripheral connection, Service scan, Service + Characteristic discovery a

Troy Stribling 696 Dec 25, 2022
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.

Bluejay is a simple Swift framework for building reliable Bluetooth LE apps. Bluejay's primary goals are: Simplify talking to a single Bluetooth LE pe

Steamclock Software 1k Dec 13, 2022
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Secure Mobile Networking Lab 5.8k Jan 9, 2023
An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps

PeerKit An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps Usage // Automatically detect and attach to

JP Simard 861 Dec 23, 2022
A simple framework that brings Apple devices together - like a family

Apple Family A simple framework that brings Apple devices together - like a family. It will automatically use bluetooth, wifi, or USB to connect and c

Kiran 62 Aug 21, 2022
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.

ExtendaBLE Introduction ExtendaBLE provides a very flexible syntax for defining centrals and peripherals with ease. Following a blocks based builder a

Anton 94 Nov 29, 2022
🐵Fooling around with Apples private framework AvatarKit

Fooling around with Apples private framework AvatarKit, the framework used in Messages.app for recording Animoji videos. If you are looking to create your own Animoji, take a look at SBSCustomAnimoji.

Simon Støvring 968 Dec 25, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity

RxSwift Community 69 Jul 5, 2022
A testable RxSwift wrapper around MultipeerConnectivity

A testable RxSwift wrapper around MultipeerConnectivity RxMultipeer is a RxSwift wrapper for MultipeerConnectivity. Using the adapter pattern, we can

RxSwift Community 69 Jul 5, 2022
A peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework

This repository is a peer to peer framework for OS X, iOS and watchOS 2 that presents a similar interface to the MultipeerConnectivity framework (which is iOS only) that lets you connect any 2 devices from any platform. This framework works with peer to peer networks like bluetooth and ad hoc wifi networks when available it also falls back onto using a wifi router when necessary. It is built on top of CFNetwork and NSNetService. It uses the newest Swift 2's features like error handling and protocol extensions.

Manav Gabhawala 93 Aug 2, 2022
Keep It Functional - An iOS Functional Testing Framework

IMPORTANT! Even though KIF is used to test your UI, you need to add it to your Unit Test target, not your UI Test target. The magic of KIF is that it

KIF Framework 6.2k Dec 29, 2022
a playground app using `MultipeerConnectivity` to transfor data wirelessly between iOS / iPadOS

README An example app using MultipeerConnectivity to transfor data wirelessly between iOS / iPadOS. Both using Data and Stream to transfer data are su

null 3 Aug 6, 2022
A simple, declarative, functional drawing framework, in Swift!

DePict - A simple, declarative, functional drawing framework. To produce a drawing, call the Draw function (just type Draw and let autocomplete do the

David Cairns 35 Sep 16, 2021
A simple, declarative, functional drawing framework, in Swift!

DePict - A simple, declarative, functional drawing framework. To produce a drawing, call the Draw function (just type Draw and let autocomplete do the

David Cairns 35 Sep 16, 2021
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Koussaïla BEN MAMAR 2 Dec 31, 2021
Functional DSP / Audio Framework for Swift

Lullaby Lullaby is an audio synthesis framework for Swift that supports both macOS and Linux! It was inspired by other audio environments like FAUST,

Jae 16 Nov 5, 2022