Giter Site home page Giter Site logo

y-ipfs-connector's Introduction

y-ipfs-connector

NOT BEING ACTIVELY MAINTAINED

IPFS Connector for Yjs

(Demo video)

Use it!

Retrieve this with npm:

$ npm install y-ipfs-connector --save

Example

// you need to create and inject a IPFS object
const IPFS = require('ipfs')

const Y = require('yjs')
require('y-ipfs-connector')(Y)

// other Yjs deps:
require('y-memory')(Y)
require('y-array')(Y)
require('y-text')(Y)


// create IPFS node
const ipfs = new IPFS({
  EXPERIMENTAL: {
    pubsub: true // need this to work
  }
})

Y({
  db: {
    name: 'memory'
  },
  connector: {
    name: 'ipfs', // use the IPFS connector
    ipfs: ipfs, // inject the IPFS object
    room: 'Textarea-example-dev'
  },
  sourceDir: '/bower_components', // location of the y-* modules
  share: {
    textarea: 'Text' // y.share.textarea is of type Y.Text
  }
}).then(function (y) {
  // bind the textarea to a shared text element
  y.share.textarea.bind(document.getElementById('textfield'))
}

Signature

options.sign

You can sign messages. For that, you have to provide a sign option, which needs to be a function that accepts a message (string) and calls back with a buffer containing the signature for it (string):

Y({
  connector: {
    name: 'ipfs',
    sign: (m, callback) => { ... }
    // ...
  }
  // ...
})

Using this, messages will be sent alongside with a signature, which can be validated.

options.verifySignature

You can also verify a signature for a given message by providing a function like this:

Y({
  connector: {
    name: 'ipfs',
    verifySignature: (peer, message, signature, callback) => { ... }
    // ...
  }
  // ...
})

options.encode

Optional function that receives the message and encodes it. Useful if you want to encrypt the content before sending.

options.encode = (message) => {
  return encrypt(message)
}

options.decode

Optional function that receives the message and decodes it. Useful if you want to decrypt the content after receiving.

options.decode = (message) => {
  return decrypt(message)
}

Debug

Activate y-ipfs-connector on debug to see log messages.

License

MIT

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT

y-ipfs-connector's People

Contributors

aquigorka avatar daviddias avatar hacdias avatar pgte 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

Watchers

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

y-ipfs-connector's Issues

Allow Promise-based encode/decode functions

It would be great to allow async processing of encoding and decoding of messages. For example openpgpjs encrypts and decrypts data asynchronously. The connector would need to allow to pass in async encode/decode functions via options.

Y({
  connector: 
    encode: *async* (message) => { ... }
...

Needs tests

I was going to update dependencies (to prune out old libp2p-crypto and bring new js-ipfs) but I was afraid to actually move forward without tests.

Also, I don't have publish perms on npm. Mind sharing it with me?

Can I use it with js-ipfs-api

Hello,
I'm looking to create a key-value store using IPFS. I was told that Y.js could be used for this. I'm using the go-ipfs implementation with the js-ipfs-api in node.js. I tried adapting this example to get the connector working with the js-ipfs-api, but without success. Can they work together or does the connector only work with js-ipfs?
Thanks! :)

Debugging interface

A debugging interface should exist that allows us to observe the messages exchanged and peers connecting / disconnecting.

Proposal:

A simple event emitter, that, once enabled, emits the messages received and the messages sent:

emitter.on('received message', (fromPeerId, message) => {
  console.log('received message from %s: %j', fromPeerId, message)
})

emitter.on('sent message', (toPeerId, message) => {
  console.log('sent message to %s: %j', toPeerId, message)
})

Also, it should report the peers coming in ant out of the room:

emitter.on('peer joined', (peerId) => {
  console.log('peer joined: %s', peerId)
})

emitter.on('peer left', (peerId) => {
  console.log('peer left: %s', peerId)
})

whenSynced only firing once when user is connected to same peer in more than one room

From what I can see/understand if nodes A and B both have two instances of Y configured to two different rooms and want to connect to each other in both rooms the whenSynced listener is only executed for the last room joined.

Sync done should be aware a user can be connected in more than one room and fire more than once (whenSynced callback) right?

js-ipfs 0.33.0 and above do not work well with yjs "y-ipfs-connector"

js-ipfs 0.33.0 and above do not work well with yjs "y-ipfs-connector".
i found that after yjs init ok,the "await ipfs.pubsub.ls()" would list an empty topic array....this is not in normal state....it means "y-ipfs-connector" subscribe nothing from ipfs, so it will receive nothing from ipfs

Uncaught Error: underlying socket has been closed

When disconnecting the network, the following error is logged:

index.js:477 Uncaught Error: underlying socket has been closed
    at index.js:477
    at Array.forEach (<anonymous>)
    at Multiplex.destroy (index.js:475)
    at index.js:43
    at call (index.js:50)
    at Array.forEach (<anonymous>)
    at index.js:70
    at f (once.js:25)
    at Stream.<anonymous> (index.js:29)
    at Stream.f (once.js:25)

The error seams to come from node_modules/multiplex/src/index.js:477.

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.