Coder Social home page Coder Social logo

textileio / react-native-sdk Goto Github PK

View Code? Open in Web Editor NEW
40.0 11.0 5.0 1.45 MB

[DEPRECATED] React Native bindings for https://github.com/textileio/go-textile

Java 40.02% Objective-C 32.65% Ruby 0.50% TypeScript 26.64% JavaScript 0.18%
textile ipfs react-native mobile ios android decentralized

react-native-sdk's Introduction

react-native-sdk

Made by Textile Chat on Slack GitHub license CircleCI branch standard-readme compliant Platform Version


Deprecation Warning

Textile Threads v1 are being deprecated. Please follow our ongoing work on v2 on both the go-textile-threads repo and the early preview.

Until Threads v2 release and integration into the React Native SDK, this repo should be used for experimental purposes only.

For instructions on running the v2 delopment library in React Native, see here.


Textile provides encrypted, recoverable, schema-based, and cross-application data storage built on IPFS and libp2p. We like to think of it as a decentralized data wallet with built-in protocols for sharing and recovery, or more simply, an open and programmable iCloud.

Table of Contents

Install

Textile is available through npm:

npm install @textile/react-native-sdk

Usage

To learn about Textile usage, please head over to the Textile documentation and be sure to read the JavaScript getting started guide.

See the boilerplate repo for example usage.

Maintainers

@andrewxhill @asutula @sanderpick

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2019 Textile

react-native-sdk's People

Contributors

andrewxhill avatar asutula avatar carsonfarmer avatar flyskywhy avatar pcowgill avatar sanderpick avatar songjiayang 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-sdk's Issues

Prune RN events API to common set

ios-textile provides a certain set of delegate callbacks. We need to unify those with whatever events are coming from the android native module and add any additional events we want.

My initial feeling is that we can reduce the number of events coming from the RN sdk. We can also look at providing different subscription methods for each event type, so they are strongly typed by TS.

Use of Ignores API not consistent with JS lib or CLI

Noticed there is an ignores.add method here. It's not consistent.

Seems like a nice helper, we could add it in the other clients as well

Or maybe we leave it here for now, but add the standard ignores paths too?

Standard README

Just wandered over here... this needs a standard readme at some point.

React Native 0.6 + AndroidX upgrade

Needed to support newer react-native projects. The main thing is the AndoirdX upgrade, we should be good to go on the iOS side because react-native 0.6's big change is using Cocoapods to manage dependencies and we already require Cocoapods to install the SDK.

Use ios-textile

The react-native-sdk should use the native sdks as much as possible. The ios-textile native SDK is ready more or less. This epic is to track work on getting react-native-sdk to use ios-textile.

Can't determine join time of a contact

Right now the easiest way is to look for when they first share or message.

Related: #118

Three possible fixes

  1. Add the seconds to feed entries (maybe it is hidden in payload. It would also be nice to add contact address to join/leave payload if not there (see ticket above for not knowing)
  2. In textile.thread.peers it would be nice to include their join time for that thread in the response.
  3. It seems pretty common in chat interfaces that you want to include Join announcements. It might be handy to create a join/leave message type that can be folded into that single textile.messages query

Wrap contact search into a more assistive endpoint

Currently,

  const queryId = await Textile.contacts.search(query, options)
  return eventChannel<SearchEvent>((emitter) => {
    const resultsSub = Textile.events.addContactQueryResultListener((receivedQueryId, contact) => {
      if (receivedQueryId === queryId) {
        emitter({ contact, type: 'contact' })
      }
    })
    const errorSub = Textile.events.addQueryErrorListener((receivedQueryId, error) => {
      if (receivedQueryId === queryId) {
        emitter({ error, type: 'error' })
        emitter(END)
      }
    })
    const doneSub = Textile.events.addQueryDoneListener((receivedQueryId) => {
      if (receivedQueryId === queryId) {
        emitter(END)
      }
    })
    return () => {
      Textile.contacts.cancelSearch()
      resultsSub.cancel()
      errorSub.cancel()
      doneSub.cancel()
    }
  })

Could we just have,

const queryId = await Textile.contacts.search(<query>, onResult, onDone, onError)

related:

#93

Not clear how to decode the feed result

when collecting results from Textile.feed it isn't clear how to get those results back into JS/TS types. I'm guessing it is something to do with the result.payload.value content, but I don't see any section in the docs about Feed so it's tricky still.

Better events API

Currently, we're just sending base64 strings of protobuf data for any events that include data. It's up the the SDK user to parse this data into the correct JS type (using the generated JS protobuf classes).

A better setup would be at least for the SDK to convert to the JS protobuf classes.

Even better would be to create explicit addListener function for each type, removing the general addListener method that takes an event type arg. So for example:

function addThreadAddedListener(listener: (thread: pb.Thread) => void)

CI not showing errors in PR

CI on my branch/PR was passing fine. When I merged and tagged a release, that CI build failed with tsc compilation errors. Seems like those should be surfaced in the PR CI workflow.

Listener events are not working in SDK, maybe in native libs too

I can setup some listener, e.g.

      Textile.events.addThreadUpdateReceivedListener((update) => {
        const { type_url } = update.payload
        if (
          type_url === '/Join' ||
          type_url === '/Leave') {
            store.dispatch(MainActions.refreshContacts(update.thread))
        }
        if (
          type_url === '/File' ) {
            store.dispatch(MainActions.refreshGameInfo(update.thread))
        }
        if ( type_url === '/Comment') {
          store.dispatch(MainActions.refreshMessagesRequest(update.thread))
        }
      })

and it will never fire (maybe sometimes but rarely).

either the events don't come as soon as the node has them, or they are getting lost along the way.

I can verify it by "polling" the node via something like,

    let messages: ITextList = yield call([Textile.messages, 'list'], '', 100, thread.id)

which will show me updates that are never coming as events.

Wrap files.prepare and files.add into single api helper

currently the following could just be one call

const result = await textile.files.prepare(input, "12D3KooWSYT6SUL9fx15pwjHSVUsuymnbixmRtPGySmFYtWE51Sc")
const block = await textile.files.add(result.dir, "12D3KooWSYT6SUL9fx15pwjHSVUsuymnbixmRtPGySmFYtWE51Sc")

Fix linking so go-mobile remains discoverable

Currently after I link the file into textile-mobile, I need to go Xcode -> LIbraries -> RNTextile and change all the search paths for go-mobile to $(SRCROOT)/../../go-mobile/ios

Any time react-native-sdk is updated I need to repeat that step...

Fix base64 input to addData

Just flagging this for later and adding the context. There seems to be an issue with how Objective-C is decoding base64 strings in the RN bridge method addData:

  1. This is the same weirdness we saw with pb.Strings
  2. The actual error we saw is from hitting the textile JSON mill with invalid JSON:
error adding data  (\351\307\370\272&start","target":"P7W358aNqdqeYFCSQJL5LobnKYfcQRaXMPogafxkE4sWHokf","duration":86400}: invalid character '(' looking for beginning of value

There seems to be some additional characters added to the start of the string (looks sorta like ASCII, but not quite?).

As a temp fix, we're just passing an encoded string all the way down to the textile lib. However, this should not effect the user TS API, which can internally encode the Buffer to base64 and pass the result to the RN bridge. This makes for a nicer API (the user should not need to deal with base64):

addData(Buffer.from(myString), <threadID>, <caption>)

vs.

addData(Buffer.from(myString).toString('base64'), <threadID>, <caption>)

This would still work with the current temporary fix in the RN bridge, because the issue is not with the JS Buffer module.

Create helper method for Contact search

  const query: IContactQuery = {
    username: searchString,
    address: ''
  }
  const options: IQueryOptions = {
    localOnly: false,
    remoteOnly: false,
    limit: 20,
    wait: 8,
    filter: QueryOptions.FilterType.NO_FILTER,
    exclude: []
  }
  const queryId = await Textile.contacts.search(query, options)

Ideally you could have the option to just pass

  const queryId = await Textile.contacts.search("Andrew")

Before close, update a tour of textile docs to reflect new sig

Calling API.stop() does not result in newNodeState event

With listeners setup,

    this.events.addListener('NODE_STOP', () => {
      console.info('@textile/NODE_STOP')
    })
    this.events.addListener('NODE_START', () => {
      console.info('@textile/NODE_START')
    })
    this.events.addListener('newNodeState', (payload) => {
      console.info('@textile/newNodeState', payload.state)
    })

If you call

this.textile.setup()

You get very nice state changes,

03-27 10:41:08.441 12825 14734 I ReactNativeJS: '@textile/newNodeState', 'creating'
03-27 10:41:08.471 12825 14734 I ReactNativeJS: '@textile/newNodeState', 'created'
03-27 10:41:08.491 12825 14734 I ReactNativeJS: '@textile/newNodeState', 'starting'
03-27 10:41:08.538 12825 14734 I ReactNativeJS: @textile/NODE_START
03-27 10:41:08.545 12825 14734 I ReactNativeJS: '@textile/newNodeState', 'started'

However, if you call,

API.stop()
// and/or
API.start()

You will only get

@textile/NODE_STOP
@textile/NODE_START

Extra/wrong method

invites.ts implements a method remove which is calling the node's removeThread. Not correct.

Move textile.invites.add to textile.invites.create

The JS lib has a nice signature here,

textile.invites.create(threadId: string, address?: string)

if address is undefined it is the same as RN's addExternal method, otherwise it's the same as add

  • be sure to update Tour of Textile code snippets

Add the blocks api methods

Feels like we should boil up all the APIs the same way, which means adding blocks endpoints for mobile (and other i'm sure)

advanced-react0native-biolerplate failed at launch

The example of advanced-react-native-boilerplate was cloned to macOS Catalina running Xcode 11.3.1 with its command line tool. Follow the How to use to launch it:

yarn react-native run-is

The simulator is iPhone 11 Pro Max. The error is about missing simulator:

yarn react-native run-ios
yarn run v1.19.2
$ /Users/zhouyiyun/Documents/js/advanced-react-native-boilerplate/node_modules/.bin/react-native run-ios
Found Xcode workspace TApp.xcworkspace

Could not find iPhone X simulator

Error: Could not find iPhone X simulator
at resolve (/Users/zhouyiyun/Documents/js/advanced-react-native-boilerplate/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise ()
at runOnSimulator (/Users/zhouyiyun/Documents/js/advanced-react-native-boilerplate/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/zhouyiyun/Documents/js/advanced-react-native-boilerplate/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/zhouyiyun/Documents/js/advanced-react-native-boilerplate/node_modules/react-native/local-cli/cliEntry.js:117:22)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

But there is no iPhone X simulator on my Mac.

Update notes app with latest

For lack of a better zenhub repo

Good for testing out the latest SDK, also needed for updated pairing with desktop

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.