All Projects → kirankunigiri → Peertalk Simple

kirankunigiri / Peertalk Simple

Licence: mit
Communicate between iOS and Mac devices via USB

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Peertalk Simple

16soundsusb
16 Synchronized Inputs USB (UAC2) Sound Card Based on XMOS xCORE-200
Stars: ✭ 45 (-53.12%)
Mutual labels:  usb
Adafruit circuitpython hid
USB Human Interface Device drivers.
Stars: ✭ 65 (-32.29%)
Mutual labels:  usb
Ehal
Embedded Hardware Abstraction Library
Stars: ✭ 84 (-12.5%)
Mutual labels:  usb
Usb4java Javax
javax.usb extension for usb4java
Stars: ✭ 47 (-51.04%)
Mutual labels:  usb
Apple Family
A simple framework that brings Apple devices together - like a family
Stars: ✭ 59 (-38.54%)
Mutual labels:  usb
Autogadgetfs
USB testing made easy
Stars: ✭ 71 (-26.04%)
Mutual labels:  usb
X Cube Usb Pd
USB-C Power Delivery Firmware for STM32 microcontroller (ARM Cortex M0 & M4)
Stars: ✭ 41 (-57.29%)
Mutual labels:  usb
Kindd
A kindful dd, written in qt-quick.
Stars: ✭ 93 (-3.12%)
Mutual labels:  usb
Toboot
Bootloader for the EFM32HG Tomu Board
Stars: ✭ 65 (-32.29%)
Mutual labels:  usb
Micronucleus
ATTiny usb bootloader with a strong emphasis on bootloader compactness.
Stars: ✭ 1,240 (+1191.67%)
Mutual labels:  usb
Multibootusb
Create multiboot live Linux on a USB disk...
Stars: ✭ 1,042 (+985.42%)
Mutual labels:  usb
Awesome Connectivity Info
Awesome list of connectivity indexes and reports to help you better under who has access to communication infrastructure and on what terms.
Stars: ✭ 57 (-40.62%)
Mutual labels:  connectivity
Virtual Display
USB/Ethernet Display driver sample for Windows
Stars: ✭ 71 (-26.04%)
Mutual labels:  usb
Uhubctl
uhubctl - USB hub per-port power control
Stars: ✭ 1,036 (+979.17%)
Mutual labels:  usb
Canlabcore
Core tools required for running Canlab Matlab toolboxes. The heart of this toolbox is object-oriented tools that enable interactive analysis of neuroimaging data and simple scripts using high-level commands tailored to neuroimaging analysis.
Stars: ✭ 88 (-8.33%)
Mutual labels:  connectivity
Usb Keystroke Injector
☠️ An Arduino-based USB keyboard simulator which injects keystrokes via Bluetooth protocol or predefined payloads in a SD card.
Stars: ✭ 42 (-56.25%)
Mutual labels:  usb
Secure If
Android USB Control app
Stars: ✭ 68 (-29.17%)
Mutual labels:  usb
Ipod Gadget
iPod usb gadget for audio playback
Stars: ✭ 94 (-2.08%)
Mutual labels:  usb
Usbserial
Usb serial controller for Android
Stars: ✭ 1,301 (+1255.21%)
Mutual labels:  usb
Jsprintmanager
Advanced Client-side Printing & Scanning Solution for Javascript
Stars: ✭ 74 (-22.92%)
Mutual labels:  usb

peertalk-simple Platform

License MIT Build Passing

This library simplifies peertalk by Rasmus, and allows for simplified communication between iOS and Mac devices via USB. This project contains 2 things.

  • A detailed tutorial on how to use peertalk
    • Lengthy and complex
    • Allows for full customizability of data transfers
    • Read the commented ManualViewController classes for a tutorial
  • A facade class that simplifies peertalk
    • Setup is extremely quick and simple
    • Code is the exact same on iOS and macOS
    • Read the guide below for a tutorial

In the Xcode project, there are 2 targets (for iOS and macOS) with demos of peertalk as seen in the gif above. Each one has 2 View Controller files named Manual and Simple. As you can guess, navigate to the Manual classes for a detailed tutorial on how to implement peertalk yourself. It is filled with comments and clean swift code for you to read. On the other hand, the Simple classes contain a quick demo of using the facade class.

Demo

Demo

Installation

Just drag the PTManager.swift file to your project, and you'll be all set to go.

Guide

PTManager is a facade class that manages all the different peertalk components so that you can easily manage communication with just one object. The best part is, the code is the exact same on both iOS and macOS! While manual peertalk had a completely different setup for the two, you can literally copy and paste code from one to another with PTManager. Let's walk through how simple the process is!

Setup

To begin, let's setup the PTManager singleton instance by setting the delegate and starting the connection with a port number. The port number can be any 4 digit integer, and the Mac app must use the same one to connect.

PTManager.instance.delegate = self
PTManager.instance.connect(portNumber: 2345)

Next, we also need to run a method in the App Delegate when the app restarts because peertalk automatically disconnects when the iPhone is put to sleep.

func applicationDidBecomeActive(_ application: UIApplication) {
    PTManager.instance.connect(portNumber: 2345)
}

Send Data

You can add a tag to the data you send so that the receiver knows what the data is. You can create a UInt32 enum to manage them. Here's an example with 2 types: strings and images.

enum PTType: UInt32 {
    case string = 100
    case image = 101
}

Now, let's send a String! Family automatically converts objects to data using NSKeyedArchiver, so if you want to send your own data, use the sendData method instead.

ptManager.sendObject(object: "Hello World", type: PTType.string.rawValue)

Receive Data (Protocol)

Let's receive data now! We just need to conform to the PTManagerDelegate protocol.

The other methods give you other information about your devices and data, but the didReceiveDataOfType method is where you can actually receive and use data. Here, I check the type of the data and convert it to the corresponding object. The class has an extension to the Data class - the method convert() - that uses the NSKeyedArchiver class to convert data back into the object you need.

// You can reject data before receiving it if it is a certain type
// Because I always want to accept the data, I return true no matter what
func peertalk(shouldAcceptDataOfType type: UInt32) -> Bool {
    return true
}

// With the data, you can convert it based on it's type
func peertalk(didReceiveData data: Data, ofType type: UInt32) {
    if type == PTType.string.rawValue {
        let string = data.convert() as! String
    } else if type == PTType.image.rawValue {
        let image = UIImage(data: data)
    }
}

// You can perform any updates when the connection status changes
func peertalk(didChangeConnection connected: Bool) {}

And that's how simple it is to use! Remember, PTManager works the same across iOS and macOS, so you can resuse the same code.

Contribute

Feel free to to contribute to the project with a pull request or open up an issue for any new features or bug fixes.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].