Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples Fail on pubsub #154

Closed
vijayee opened this issue Dec 9, 2016 · 4 comments
Closed

Examples Fail on pubsub #154

vijayee opened this issue Dec 9, 2016 · 4 comments

Comments

@vijayee
Copy link

vijayee commented Dec 9, 2016

I've tried this both for js-ipfs example and the ipfs-api example. Is there something special I need to do to make this work like target a specific version of either? There does not appear to be a pubsub module on the ipfs object.

const IpfsApi = require('ipfs-api')
const OrbitDB = require('orbit-db')

const ipfs = IpfsApi('localhost', '5001')
const orbitdb = new OrbitDB(ipfs)

const db = orbitdb.eventlog("feed name")

db.add("hello world")
  .then(() => {
    const latest = db.iterator({ limit: 5 }).collect()
    console.log(JSON.stringify(latest, null, 2))
  })
ipfs-pubsub.js:16
      this._ipfs.pubsub.subscribe(hash, { discover: true }, (err, stream) => {
                       ^

TypeError: Cannot read property 'subscribe' of undefined
    at IPFSPubsub.subscribe (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/orbit-db/node_modules/orbit-db-pubsub/src/ipfs-pubsub.js:16:24)
    at OrbitDB._subscribe (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/orbit-db/src/OrbitDB.js:71:20)
    at OrbitDB._createStore (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/orbit-db/src/OrbitDB.js:62:17)
    at OrbitDB.eventlog (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/orbit-db/src/OrbitDB.js:30:17)
    at Object.<anonymous> (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/index.js:7:20)
    at Module._compile (module.js:573:32)
    at Object.Module._extensions..js (module.js:582:10)
    at Module.load (module.js:490:32)
    at tryModuleLoad (module.js:449:12)
    at Function.Module._load (module.js:441:3)
    at Module.runMain (module.js:607:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3
@haadcode
Copy link
Member

Hi @vijayee, we're currently in the middle of the next release of IPFS and the dependencies are a little wonky atm. Thanks for reporting the issue!

You will be able to get the ipfs-api example working by using a fork of js-ipf-api by installing it with npm npm i @haad/ipfs.api and then requiring it const IpfsApi = require('@haad/ipfs-api'). That version contains support for the missing pubsub both in js-ipfs-api and in the actual go-ipfs daemon.

We're working on getting the js-ipfs version working again, I 'm fairly confident that will land next week.

@vijayee
Copy link
Author

vijayee commented Dec 12, 2016

@haadcode, thanks, I'll give it a shot with this version of the api.

@vijayee
Copy link
Author

vijayee commented Dec 12, 2016

I get another error with the '@haad/ipfs-api' module coming from stream-to-json-value

2016-12-12T16:12:15.355Z [ERROR] orbit-db.IPFSPubSub: SyntaxError: Unexpected token p in JSON at position 4
    at JSON.parse (<anonymous>)
    at streamToValue (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/@haad/ipfs-api/src/stream-to-json-value.js:25:18)
    at res.pipe.concat (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/@haad/ipfs-api/src/stream-to-value.js:9:29)
    at ConcatStream.<anonymous> (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/concat-stream/index.js:36:43)
    at emitNone (events.js:91:20)
    at ConcatStream.emit (events.js:185:7)
    at finishMaybe (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:475:14)
    at afterWrite (/home/victor/Workspace/src/github.com/vijayee/orbit-db-sandbox/node_modules/concat-stream/node_modules/readable-stream/lib/_stream_writable.js:361:3)
    at _combinedTickCallback (internal/process/next_tick.js:80:20)
    at process._tickCallback (internal/process/next_tick.js:98:9)
(node:17389) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Hash can't be null!
(node:17389) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

@haadcode
Copy link
Member

haadcode commented Jan 17, 2017

We just released a new version which includes fixes for the examples. See https://github.com/haadcode/orbit-db/tree/master/examples for all the examples.

You can now do:

npm install orbit-db ipfs-daemon
const IPFS = require('ipfs-daemon/src/ipfs-node-daemon')
const OrbitDB = require('orbit-db')

const ipfs = new IPFS()

ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', (e) => {
  const orbitdb = new OrbitDB(ipfs)

  const db = orbitdb.eventlog("feed name")

  db.add("hello world")
    .then(() => {
      const latest = db.iterator({ limit: 5 }).collect()
      console.log(JSON.stringify(latest, null, 2))
    })  
})

@vijayee, thanks for waiting. If you encounter more problems, let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants