Coder Social home page Coder Social logo

local-sync's Introduction

Local Sync

Local Sync is a framework created for transfering the data locally, using Multipeer Connectivity.

Table of Contents

How it Works

The communication only happen between different types of devices, masters and slaves. In other words, masters can only transfer and receive data from slaves, and slaves can only transfer and receive data from masters.

LocalSyncCommunication

How to Use it

Master

To become a master, that is be able to transfer and send data to slaves, you need to do the steps above.

  • Import LocalSync:
import LocalSync
  • Implement the Procotol LCMasterFacadeDelegate:

It is through this method that you will receive the data from slaves.

class YourClass: LCMasterFacadeDelegate {

    func didReceiveData(_ data: Data, fromPeer peerID: MCPeerID) {

        // Handle the data that you received from slaves

    }

}
  • Create a master sync variable:

It is through this variable that you will send the data to slaves.

let masterSync = LCMasterFacade()
masterSync.delegate = yourClassThatImplementedLCMasterFacadeDelegate

Slave

To become a slave, that is be able to transfer and send data to masters, you need to do the steps above.

  • Import LocalSync:
import LocalSync
  • Implement the Procotol LCSlaveFacadeDelegate:

It is through this method that you will receive the data from masters.

class YourClass: LCSlaveFacadeDelegate {

    func didReceiveData(_ data: Data, fromPeer peerID: MCPeerID) {

        // Handle the data that you received from masters

    }

}
  • Create a slave sync variable:

It is through this variable that you will send the data to masters.

let slaveSync = LCSlaveFacade()
slaveSync.delegate = yourClassThatImplementedLCSlaveFacadeDelegate

Tips

  • Removing the identifier from master/slave names:

The framework uses the display name of the MCPeerID to identify masters and slaves. So the display name have a UUID attached to it. So if you want to show the name of the peerID that have sended you the data, it's a good practice to remove this UUID, by doing the following

// Removing the slave UUID
peerID.displayName.replacingOccurrences(of: LCConstants.slave, with: "")

// Removing the master UUID
peerID.displayName.replacingOccurrences(of: LCConstants.master, with: "")

local-sync's People

Contributors

luis-gustavo avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

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.