Giter Site home page Giter Site logo

airshare's Introduction

A library designed to ease P2P communication between iOS and Android devices. Use AirShare to build software that doesn't require the Internet to discover and interact with peers, or to create unique networks based on the geographical connections of their users.

Also see the Android library.

Under Development : APIs subject to change

Motivation

To abstract away the particulars of connection negotiation with clients over radio technologies like BLE and WiFi. P2P networking should be as simple as:

  1. Express an identity for your local device's user and to the service this user belongs to
  2. Express an intent to discover peers on remote devices, or make your local user discoverable
  3. (Optional) When a remote peer is discovered, query available transports and upgrade transport if desired.
  4. Exchange arbitrary data with discovered peers over a plain serial interface

Requirements

  • iOS 5 SDK or greater.
  • Compatible devices: iPhone 4s or newer, iPad 3rd gen or newer, iPad mini, iPad Pro, iPod touch 5th gen or newer.

Example Apps

  • The example module of this repository illustrates simple synchronous sharing of structured data.
  • BLEMeshChat is a more advanced example featuring background operation and store-and-forward messaging.

Installation

This library is currently under developmemt. CocoaPods is probably the simplist way to bundle it as a framework for inclusion in a project and install it's dependancies. Simply clone the project, add a local reference to it in your Podfile:

pod 'AirShare/UIKit', :path => "./AirShare"
[...]
use_frameworks!

Run pod install, and you should be ready to go.

import AirShare
[...]

Usage

Basic Usage -- BLESessionManager

BLESessionManager manages peer scanning and advertising, and provides delegatable methods to respond to peers being connected and receiving data. It also exposes the set of discoveredPeers ([BLERemotePeer]) and a method to send a BLESessionMessage to a peer.

class MyAirShareManager : NSObject, BLESessionManagerDelegate  {

  private var sessionManager : BLESessionManager?;

  override init(){

    super.init()

    let keyPair = BLEKeyPair(type: .Ed25519)
    let me = BLELocalPeer(publicKey: keyPair.publicKey, privateKey: keyPair.privateKey)

    me.alias = "Alice"

    sessionManager = BLESessionManager(localPeer: me, delegate: self)

    sessionManager!.advertiseLocalPeer()
    sessionManager!.scanForPeers()

  }


  @objc func sessionManager(sessionManager: BLESessionManager!, peer: BLERemotePeer!, statusUpdated status: BLEConnectionStatus, peerIsHost: Bool) {

        switch status {
        case .Connected:  print("\(peer.alias) connected."); break
        case .Connecting: print("\(peer.alias) is connecting."); break
        case .Disconnected:  print("\(peer.alias) disconnected."); break
        }

    }

  @objc func sessionManager(sessionManager: BLESessionManager!, receivedMessage message: BLESessionMessage!, fromPeer peer: BLERemotePeer!) {

    print("Received \(message.type) message")

    // Is data BLEDataMessage
    if message.type != "datatransfer" {
        return;
    }

    // Upcast to concrete BLEDataMessage.
    let message = message as! BLEDataMessage

    let fromBytes = String(data: message.data, encoding: NSUTF8StringEncoding)!

    if let data = fromBytes.dataUsingEncoding(NSUTF8StringEncoding) {
      print("\(peer.alias) sent: \(data).")
    }
  }
}

License

Chris Ballinger

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

airshare's People

Contributors

chrisballinger avatar danielkoehler avatar onlyinamerica 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

airshare's Issues

Fence: onClientEventRegionState, invalid state message while initialising Local peer

I can successfully initialise Local peer and connect to remote peers at very first time. If I stop advertising and initialise again, I am getting following error message and I can not initialise local peer and connect to remote peers.

{"msg":"Fence: onClientEventRegionState, invalid state", "regionState":{"type":"decode failure","raw value":0,"expected type":"Generic"}}

Can you please help me?

Can't install "libsodium" dependency

I am trying to run the sample of Airshare. I have download the code and trying to install "AirShare" via cocoapod. When I run the command pod install, I am facing error by saying:

[!] Error installing libsodium
[!] /usr/bin/curl -f -L -o /var/folders/hr/ky479zwd2glczcq254_2bypc0000gn/T/d20200117-1502-8m0tln/file.tgz https://github.com/jedisct1/libsodium/releases/download/1.0.2/libsodium-1.0.2.tar.gz --create-dirs --netrc-optional --retry 2

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found

Kindly help me to resolve it.

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.