Giter VIP home page Giter VIP logo

peertalk's Introduction

peertalk

PeerTalk is an iOS and Mac Cocoa library for communicating over USB.

                         ┌──────────────────────────────┐
                         │ ┌──────────────────────────┐ │
                         │ │                          │ │
  ┌─────────┐            │ │                          │ │
  │┌───────┐│            │ │          Hello           │ │
  ││       ││            │ │                          │ │
  ││ Hello ││            │ │                          │ │
  ││       ││            │ │                          │ │
  │└───────┘│            │ └──────────────────────────┘ │
  │    ◯    │            \  ─────────────────────────── \
  └────╦────┘             \  \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
       ║         ╔══════════■ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
       ╚═════════╝          \  ─────────────────────────── \
      - meep -               └─────────────────────────────┘
         - beep -

Highlights

  1. Provides you with USB device attach/detach events and attached device's info

  2. Can connect to TCP services on supported attached devices (e.g. an iPhone), bridging the communication over USB transport

  3. Offers a higher-level API (PTChannel and PTProtocol) for convenient implementations.

  4. Tested and designed for libdispatch (aka Grand Central Dispatch).

Grab the goods from https://github.com/rsms/peertalk

Usage in Apple App Store

PeerTalk has successfully been released on both the iOS and OS X app store.

A great example is Duet Display which is a fantastic piece of software allowing you to use your iDevice as an extra display for your Mac using the Lightning or 30-pin cable.

Facebook's Origami uses PeerTalk for it's Origami Live iOS app (in fact, this is where PeerTalk was first used, back in 2012)

This probably means that you can use PeerTalk for apps aiming at the App Store.

Getting started

Suck down the code and open peertalk.xcodeproj in Xcode 4.3 or later on OS X 10.7 or later.

  1. Select the "peertalk" target and hit Cmd+U (Product → Test) and verify that the unit tests passed.

  2. Select the "Peertalk Example" target and hit Cmd+R (Product → Run). You should se a less than-pretty, standard window with some text saying it's ready. That's the OS X example app you're looking at.

  3. In Xcode, select the "Peertalk iOS Example" target for the iPhone Simulator, and hit Cmd+R (Product → Run). There should be some action going on now. Try sending some messages between the OS X app and the app running in the iPhone simulator.

  4. Connect your iOS device (iPhone, iPod or iPad) and kill the iPhone simulator and go back to Xcode. Select the "Peertalk iOS Example" target for your connected iOS device. Hit Cmd+R (Product → Run) to build and run the sample app on your device.

It should work.

Demo video: http://www.youtube.com/watch?v=kQPWy8N0mBg

<iframe width="880" height="530" src="http://www.youtube.com/embed/kQPWy8N0mBg?hd=1&rel=0" frameborder="0" allowfullscreen></iframe>

macOS sandboxed mode

In #36 (comment) @Lessica suggests the following entitlement snippet made macOS give access to peertalk:

<key>com.apple.security.temporary-exception.sbpl</key>
<array>
    <string>(allow network-outbound (literal "/private/var/run/usbmuxd"))</string>
</array>

peertalk's People

Contributors

davidobfuscator avatar jonathandann avatar nickdowell avatar philikon avatar rsms avatar silent0321 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peertalk's Issues

visit website provided by http-server

I setup a http-server on Macbook, then perform "iproxy 8080 8080", finally I need to visit the website on an iPhone, can I directly enter 127.0.0.1:8080 safari it? or write an APP, which wrapped peertalk.

best wish for you ,i am not good at english.:-D

Peertalk Examples does not run on Xcode 6.4 and Yosemite 10.10.5

Per step 2 of your getting started steps, running Peertalk example target caused 6 Semantic issue error, e.g,
peertalk/peertalk/PTUSBHub.m:485:5: Objc_precise_lifetime only applies to retainable types; type here is 'dispatch_data_t' (aka 'struct dispatch_data_s *')
peertalk/peertalk/PTUSBHub.m:515:7: Objc_precise_lifetime only applies to retainable types; type here is 'dispatch_data_t' (aka 'struct dispatch_data_s *')
peertalk/peertalk/PTProtocol.m:216:7: Objc_precise_lifetime only applies to retainable types; type here is 'dispatch_data_t' (aka 'struct dispatch_data_s *')

Actually step 1 running unit tests for peertalk target also failed
peertalk/peertalk/PTProtocol.m:216:7: Objc_precise_lifetime only applies to retainable types; type here is 'dispatch_data_t' (aka 'struct dispatch_data_s *')

Detect Android Device

Hi,

First of all very nice solution, thank you.
But I have one question.
Is it possible to detect connected Android device?

Error after lock device

Case:

  1. lock device
    2 )Invoke callback - (void)ioFrameChannel:(PTChannel_)channel didEndWithError:(NSError_)error
    And error is nil(

My decision:
I change code in PTChannel.m from
" NSError *err = error == 0 ? _endError : [[NSError alloc] initWithDomain:NSPOSIXErrorDomain code:error userInfo:nil];
"
to
"
NSError *err = error == 0 ? channel->_endError : [[NSError alloc] initWithDomain:NSPOSIXErrorDomain code:error userInfo:nil];
"

And in callback i have correct error

Opening streams

Is there a way to open a NSStream over the connection? This would be much apriechieted

Crash in usbmux_packet_alloc assert

We're getting crash dumps from our OS X app pointing to an assertion being triggered in PTUSBHub.m line 66:

#0. Crashed: com.apple.libdispatch-io.opq
0  libsystem_kernel.dylib         0x7fff8d4b5286 __pthread_kill + 10
1  libsystem_pthread.dylib        0x7fff8c6379f9 pthread_kill + 90
2  libsystem_c.dylib              0x7fff93a8f9ab abort + 129
3  libsystem_c.dylib              0x7fff93a57a91 __assert_rtn + 319
4  Application                    0x109abf3c8 usbmux_packet_alloc (PTUSBHub.m:66)
5  libdispatch.dylib              0x7fff947f8e2b ___dispatch_operation_deliver_data_block_invoke + 118
6  libdispatch.dylib              0x7fff947e0700 _dispatch_call_block_and_release + 12
7  libdispatch.dylib              0x7fff947dce73 _dispatch_client_callout + 8
8  libdispatch.dylib              0x7fff947e05cd _dispatch_queue_drain + 1100
9  libdispatch.dylib              0x7fff947e0030 _dispatch_queue_invoke + 202
10 libdispatch.dylib              0x7fff947ed5aa _dispatch_main_queue_callback_4CF + 416
11 CoreFoundation                 0x7fff8a5fd3f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
12 CoreFoundation                 0x7fff8a5b868f __CFRunLoopRun + 2159
13 CoreFoundation                 0x7fff8a5b7bd8 CFRunLoopRunSpecific + 296
14 HIToolbox                      0x7fff8968356f RunCurrentEventLoopInMode + 235
15 HIToolbox                      0x7fff896832ea ReceiveNextEventCommon + 431
16 HIToolbox                      0x7fff8968312b _BlockUntilNextEventMatchingListInModeWithFilter + 71
17 AppKit                         0x7fff872698ab _DPSNextEvent + 978
18 AppKit                         0x7fff87268e58 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 346
19 AppKit                         0x7fff8725eaf3 -[NSApplication run] + 594
20 AppKit                         0x7fff871db244 NSApplicationMain + 1832
21 Application                    0x109a935d4 start + 52

We poll the USB port repeatedly waiting for a device with our client app to connect. The crazy thing about that is the assert being triggered should be:

static usbmux_packet_t *usbmux_packet_alloc(CFIndex payloadSize) {
  assert(payloadSize <= UINT32_MAX); // protocol limitation
  uint32_t payloadLength = (uint32_t)payloadSize;

but the stack shows this coming from the dispatch_io_read in scheduleReadPacketWithCallback (PTUSBHub.m:494), which uses a uint32_t parameter, thus making it (theoretically) impossible to overflow UINT32_MAX:

    // Allocate a new usbmux_packet_t for the expected size
    uint32_t payloadLength = upacket_len - sizeof(usbmux_packet_t);
    usbmux_packet_t *upacket = usbmux_packet_alloc(payloadLength);

Any ideas? Maybe stack corruption in the previous memcpy (should be protected by the assertion, so...)?

Connecting with more than one device

I want to send some msgs on all connected usb devices. Here this code works for only single connected device. is there any way to connect to more than one device at a time. Thanks for the help in advance.

Connect more than one ios device to OSX

Hi,
great work.
Is there way to connect two ios devices to OSX and recognize where is first and where is second, I need to make app bundle source synchronization between two ios devices through USB connected to OSX.
I need to sync, video and images not loaded in memory, as a files.
is there possible?
thank you very much.

Error while testing Simulator and mac app

I got error when i was running both app and my display was stuck with some time and the both app did got error after my display blinking.After that the sample project crash with the below method

  • (void)readAndDiscardDataOfSize:(size_t)size overChannel:(dispatch_io_t)channel callback:(void(^)(NSError*, BOOL))callback .

Actually what you did with my systems.

Send/Receive in background

Will it ever be able to send and receive in the iOS background? I've tried setting on some background modes and even a background identifier, but that does not seem to work.

Thanks in advance

Documentation

Hello, first of all, thank you for an awesome library. But I can't find even "Getting Started" guide or simple code examples(without complete demo app). Could you please add at least that? Thank you!

Issues with AppleTV

Hi, I'm a software engineer at AT&T.
I used the peertalk library from my UITest (based on XCTest) on AppleTV.
This UITest was developed using Swift with a bridge header to the peertalk library.
I developed the UITest according to the iOS example.
On the Mac I simply run the example GUI.
I successfully sent messages from AppleTV to Mac, but the messages from the Mac to the AppleTV
don't arrive.
Details: The delegate's method ioFrameChannel-didReceiveFramOfType is not called when I send
a message from the Mac GUI.
I wonder if it is possible to work with peertalk on AppleTV too.

Thanks,
Eli
[EMAIL REDACTED]

QUE: Example app, why is connecting to LocalIPv4Port

Why is the example app trying to enqueueConnectToLocalIPv4Port ?

as everything is working without it

// Start trying to connect to local IPv4 port (defined in PTExampleProtocol.h)
[self enqueueConnectToLocalIPv4Port];

and iam also wondering a bit why it works, as the client iOS app listnes on IPV4 port
[channel listenOnPort:PTExampleProtocolIPv4PortNumber IPv4Address:INADDR_LOOPBACK callback:^

Possible memory leak

When an iPhone/iPad is plugged in, but the iOS app that communicates with the Mac app is not running, the enqueueConnectToUSBDevice method is triggered every PTAppReconnectDelay seconds until the connection is made. This delayed call seems to add ~100kb to used memory on every call, and is never released. This adds up over time, and slows down the Mac app.

I could reproduce this in the Peertalk Example app, in my own app, and also noticed it happening in Quartz Composer with Origami installed.

Console output:

10/30/15 12:46:51.705 PM com.apple.usbmuxd[49965]: HandleUSBMuxDictionary client 0x7fce19420800-Quartz Composer/NULL using library 151.1, running usbmuxd-364

10/30/15 12:46:51.706 PM com.apple.usbmuxd[49965]: MuxTCPInputSCE received RST for 0x1e-ef766571a2af13fc4d603d460e1943592582f130@0x41123000:2345->0x7fce19420130-Quartz Composer/NULL:40149: handleConnectResult: failure - 61

The line of code for reference : https://github.com/rsms/peertalk/blob/master/Peertalk%20Example/PTAppDelegate.m#L330

I tried using __block to pass weak references of self and other variables to the callback, but that did not help. If I remove this line it stops using memory, but, obviously, it also doesn't detect the app being launched if the device was already plugged in before launch.

Any ideas on how to avoid the memory usage?

Cannot initialize a variable of type 'PTExampleTextFrame *' (aka '_PTExampleTextFrame *') with an rvalue of type 'void *'

Example for iOS works ok, but when I'm trying to use libs in my own project (swift version with objective-c++ .mm classes bridges) I get next error:

Cannot initialize a variable of type 'PTExampleTextFrame *' (aka '_PTExampleTextFrame *') with an rvalue of type 'void *'

in this function (Peertalk Example) PTExampleProtocol.h

also this header file for Mac target/project, so does why iOS target/project reference to it?

static dispatch_data_t PTExampleTextDispatchDataWithString(NSString *message) {
  // Use a custom struct
  const char *utf8text = [message cStringUsingEncoding:NSUTF8StringEncoding];
  size_t length = strlen(utf8text);
  //CFAllocatorAllocate(nil, 1 + length, 0);
  PTExampleTextFrame *textFrame = CFAllocatorAllocate(nil, sizeof(PTExampleTextFrame) + length, 0);
  memcpy(textFrame->utf8text, utf8text, length); // Copy bytes to utf8text array
  textFrame->length = htonl(length); // Convert integer to network byte order
  
  // Wrap the textFrame in a dispatch data object
  return dispatch_data_create((const void*)textFrame, sizeof(PTExampleTextFrame)+length, nil, ^{
    CFAllocatorDeallocate(nil, textFrame);
  });

screenshot at apr 13 16-18-13

Cross plattform support

This is rather a RFC than an actual issue.

I would be happy to connect an iPad as a additional screen to my Linux system via a wired connection. One application that does it for Mac OS is the awesome Duett Display app you mention in the readme and which lead me here [1].

Would it be possible to use this library from a Linux system now that at least parts of libcentraldispatch are getting ported [2]?

Or would I be better off reimplementing the functionality utilizing usbmuxd [3] to achieve the same goals?

Thank you for your time! 👍

using peertalk with with python binding

Hi, I'm just wondering if it's is possible to send data via peertalk to macos but instead of using objective-c on the macos side to use python. I'm doing some realtime signal processing and it's easier for me to prototype algorithm using python and opencv. I bet there is currently no python binding but would like to know if it's teoretically possible to intercept peertalk usb data via e.g. pyserial. Any tips and ideas how to best approach this?

Porting from OSX

Hi

Does peertalk OSX app rely on some Apple's core framework or it can be implemented in something else? I'd need to make a nodejs (or anything cross-platform) implementation so it'd work on windows but I'm not really sure what makes all of this work without a jailbroken phone.

Best regards,
PB

Using PeerTalk without the protocol and channel component?

My app suite connects Windows/Mac with iOS and I'm trying to use unified communication protocol. Apparently I cannot use PeerTalk directly on Windows. So I'd love to strip off everything but the usbmuxb service features of PeerTalk codebase, just to ensure that a TCP socket server running on iOS can receive data through USB.

Now the question is: Can I achieve my goal by simply using the PTUsbHub class alone?

Figure out use in macOS 10.12 under sandboxed mode (for app store)

When I try to submit a Mac app that uses peertalk, it sends me an error and says that I have to enable the sandbox. However, I get the Operation Not Permitted error because peertalk is no longer able to write to the device.

I tried making an exception according to another user on this stack overflow post, but it does not work.

How can I either disable sandbox and still use peertalk, or enable an exception in sandbox for peertalk? Thanks!

run with usbmuxd

I try to find way to launch peertalk ios with linux server backend.

I try to understand, is there any way to replace peertalk mac os with usbmuxd ( libimobiledevice )

Can I ask for some hint?

Status of the library

It's a very interesting piece of software, but the fact that the last commit was made in December 2020 worries me a bit. Is this actively maintained? :)

How to connect multi devices?

When i try to use PTChannel connect the second device to a new port, get the error like this:

Error Domain=PTUSBHubError Code=3 "connection refused" UserInfo={NSLocalizedDescription=connection refused

PeerTalk with Arduino

Hi @everyone,
someone know if it there's a way to adapt PeerTalk protocol communication (that is based on usbmuxd) in order to create a path for a communication between an iOS device and an Arduino UNO?

Thank's in advance.

PTUSBHub connectToDevice in main queue

why PTUSBHub hard code api that connectToDevice in main queue?

- (void)connectToDevice:(NSNumber*)deviceID port:(int)port onStart:(void(^)(NSError*, dispatch_io_t))onStart onEnd:(void(^)(NSError*))onEnd {
      PTUSBChannel *channel = [PTUSBChannel new];
      NSError *error = nil;
      //open main queue ?
     if (![channel openOnQueue:dispatch_get_main_queue() error:&error onEnd:onEnd]) {
           onStart(error, nil);
           return;
       }
     // ....
}

peer talk memory leaked ~

i found peertalk memory leaks happen when receive message and answers, and may crash.

Maybe at "- (void)readFrameOverChannel:(dispatch_io_t)channel callback:(void(^)(NSError *error, uint32_t frameType, uint32_t frameTag, uint32_t payloadSize))callback" , but i can not ensure it ~

please help me to check and solve it ~

english is not good, so sorry。

Tag master with a new version

When pulling PeerTalk through CocoaPods it is not pulling the latest codebase. Its actually pulling an old commit since version 0.0.1 points to an old commit.

Would it be possible to push a new podspec to cocoapods master repo for version 0.0.2 and tag the master branch with tag 0.0.2?

I can do a PR for the podspec if you will

Cocoapods Not Updated

After installing peertalk via Cocoapods (and not changing anything else about my project), I get the following linking error:
4 duplicate symbols for architecture x86_64

I've tried every solution I can find online, so I was hoping it was an issue with the project. Can anyone reproduce my error / offer a solution?

I was using Swift, but I ended up recreating my project as Objective-C and that didn't fix it.

The Cocoapods version available right now is 0.0.1. I noticed in #32 that version 0.0.1 is throwing linking errors. Seeing as there is a Podfile in the repository, it looks like this is meant to be officially on Cocoapods, however the version available is not what is in the Podfile here.

How to speed up data transferring?

By using your library I faced up with slow transferring issue. My setup is using serial port for grabbing incoming data and translate them via usb to iOS. My serial is usually has 115200 baud rate (it's about ~ 230kbits/s) and I see the big differences with displaying big data in uitextview which were received from serial port and from usb (using peertalk). The data from serial port is displaying almost immediately.

Does this app require two-way communication? Can I only listen to data input?

I am trying to make an HDMI -> iPad application.

Ideally, the configuration would go as follows:

HDMI -> converter -> USB-C -> iPad -> decode HDMI data into video

Preferably, I'd only need to use one-way communication - I don't care for the iPad to respond to the HDMI provider (unless that's necessary). Is it possible to instead of PeerTalk... just, PeerListen?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.