Code Monkey home page Code Monkey logo

orbit-core's Introduction

orbit-core

npm version CircleCI Status Gitter Matrix

Communication protocol on IPFS

Orbit is a serverless, distributed, p2p communication library and protocol that enables feed-based information sharing, such as real-time chat, in the IPFS peer-to-peer network.

This repository is the core library of Orbit. This library is intended to be used in your Node.js or Browser applications.

Used in the various Orbit projects:

Table of Contents

Install

This module uses npm and node.

npm install orbit_

Usage

See examples/browser/index.html for a more detailed example.

'use strict'

const Orbit = require('orbit_')

const ipfs = new Ipfs()

ipfs.on('ready', () => {
  const orbit = new Orbit(ipfs)

  const username = 'Example Bot'
  const channel = 'HelloWorld'

  orbit.events.on('connected', () => {
    console.log(`-!- Orbit connected`)
    orbit.join(channel)
  })

  orbit.events.on('joined', channelName => {
    orbit.send(channelName, '/me is now caching this channel')
    console.log(`-!- Joined #${channelName}`)
  })

  // Listen for new messages
  orbit.events.on('entry', (entry, channelName) => {
    const post = entry.payload.value
    console.log(`[${post.meta.ts}] <${post.meta.from.name}> ${post.content}`)
  })

  // Connect to Orbit network
  orbit.connect(username).catch(e => console.error(e))
})

API

See API documentation for full details.

Development

Install Dependencies

git clone https://github.com/orbitdb/orbit-core.git
cd orbit-core/
npm install

Run example development environment

npm run dev

Run Tests

npm test

Build Library and Distributables

npm run build

Distributable (ES5 minified for browsers) will be located in dist/.

Contribute

We would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us on Gitter, or in the issues section.

We also have regular community calls, which we announce in the issues in the @orbitdb welcome repository. Join us!

If you want to code but don't know where to start, check out the issues labelled "help wanted".

For specific guidelines for contributing to this repository, check out the Contributing guide. For more on contributing to OrbitDB in general, take a look at the @OrbitDB welcome repository. Please note that all interactions in @OrbitDB fall under our Code of Conduct.

License

MIT © 2016-2019 Protocol Labs Inc., Haja Networks Oy

orbit-core's People

Contributors

adam-palazzo avatar aphelionz avatar haadcode avatar janianttonen avatar latenssi avatar richardlitt 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  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

orbit-core's Issues

getting TypeError: "listener" argument must be a function on orbit.join()

Hi, I'm following the example on the readme page of this repository and having my very first interactions with orbit and ipfs.

I manage to start the ipfs deamon with the command jsipfs init and jsipfs daemon.

This is my script:

/* NOTE! To run this example, you need to have an IPFS daemon running */

'use strict'

const IpfsApi = require('ipfs-api')
const Orbit = require('orbit_')

//const ipfs = IpfsApi()
const ipfs = IpfsApi('/ip4/127.0.0.1/tcp/5002')

const orbit = new Orbit(ipfs)

const username = 'username'

const channel = 'HelloWorld'

orbit.events.on('connected', (network) => {
  //console.log(`-!- Connected to ${network.name}`)
  console.log(`Connected to ${network.name} as ${orbit.user.name}`)
  //orbit.join(channel)
})

orbit.events.on('joined', (channel) => {
  orbit.send(channel, "/me is now caching this channel")
  console.log(`-!- Joined #${channel}`)
})

// Listen for new messages
orbit.events.on('message', (channel, post) => {
  console.log(`[${post.meta.ts}] < ${post.meta.from.name}> ${post.content}`)
})

however, when I call orbit.join(channel), I get this error:


TypeError: "listener" argument must be a function
    at _addListener (events.js:239:11)
    at EventEmitter.addListener (events.js:297:10)
    at subscribe (/Users/olmo/sandobx/chat/orbit_based/node_modules/ipfs-api/src/pubsub.js:138:8)
    at Object.subscribe (/Users/olmo/sandobx/chat/orbit_based/node_modules/ipfs-api/src/pubsub.js:58:7)
    at IPFSPubsub.subscribe (/Users/olmo/sandobx/chat/orbit_based/node_modules/orbit-db-pubsub/src/ipfs-pubsub.js:23:27)
    at OrbitDB._createStore (/Users/olmo/sandobx/chat/orbit_based/node_modules/orbit-db/src/OrbitDB.js:71:20)
    at OrbitDB.eventlog (/Users/olmo/sandobx/chat/orbit_based/node_modules/orbit-db/src/OrbitDB.js:29:17)
    at Orbit.join (/Users/olmo/sandobx/chat/orbit_based/node_modules/orbit_/src/Orbit.js:125:27)

any help is highly appreciated.

thanks.

test failure

> [email protected] test /home/whyrusleeping/code/orbit-core
> LOG=none ./node_modules/.bin/mocha



  Orbit with js-ipfs-api
    constructor
      ✓ creates an instance
      ✓ creates an instance with options
    connect
      ✓ connects to a network
{ AssertionError: 'QmfM5YmnSGBkLjramPvFSvbCuKqnagVtmGb4yXanPPntbu' == 'QmXWWRTZzygRCnWP8sBcTuygreYBTaQR73zVpZvyxeuUqA'
    at EventEmitter.orbit.events.on (/home/whyrusleeping/code/orbit-core/test/orbit.test.js:94:18)
    at emitTwo (events.js:106:13)
    at EventEmitter.emit (events.js:191:7)
    at IdentityProviders.authorizeUser.then.then.then.then (/home/whyrusleeping/code/orbit-core/src/Orbit.js:85:21)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  name: 'AssertionError',
  actual: 'QmfM5YmnSGBkLjramPvFSvbCuKqnagVtmGb4yXanPPntbu',
  expected: 'QmXWWRTZzygRCnWP8sBcTuygreYBTaQR73zVpZvyxeuUqA',
  operator: '==',
  message: '\'QmfM5YmnSGBkLjramPvFSvbCuKqnagVtmGb4yXanPPntbu\' == \'QmXWWRTZzygRCnWP8sBcTuygreYBTaQR73zVpZvyxeuUqA\'',
  generatedMessage: true }
      1) emits 'connected' event when connected to a network


  3 passing (1m)
  1 failing

  1) Orbit with js-ipfs-api connect emits 'connected' event when connected to a network:
     Error: timeout of 60000ms exceeded. Ensure the done() callback is being called in this test.





npm ERR! Linux 4.8.7-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "test"
npm ERR! node v7.1.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test: `LOG=none ./node_modules/.bin/mocha`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script 'LOG=none ./node_modules/.bin/mocha'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the orbit_ package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     LOG=none ./node_modules/.bin/mocha
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs orbit_
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls orbit_
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/whyrusleeping/code/orbit-core/npm-debug.log
make: *** [Makefile:8: test] Error 1

erro when running tests

Hi

When running npm test I get
internal/modules/cjs/loader.js:583
throw err;
^

Error: Cannot find module '/home/user/orbit-core/orbit-core/node_modules/wrtc/build/wrtc/v0.0.61/Release/node-v64-linux-x64/wrtc.node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/home/user/orbit-core/orbit-core/node_modules/wrtc/lib/peerconnection.js:6:15)

RFI: Distributed Nodes

Using orbit-core (as chat) - is it possible to join on the same channel from different nodes? By sharing usernames key?

I try to abstract from orbitdb-db and orbit_ on how ipfs p2p is used in orbitdb.

Thanks,
Thorsten

build failure

[ npm install output.....]

> [email protected] test /home/whyrusleeping/code/orbit-core
> LOG=none ./node_modules/.bin/mocha



  Orbit with js-ipfs-api
    1) "before all" hook

  0 passing (3s)
  1 failing

  1) Orbit with js-ipfs-api "before all" hook:
     Error: non-zero exit code 1
  while running: /home/whyrusleeping/code/orbit-core/node_modules/subcomandante/subcom 22100 /home/whyrusleeping/code/orbit-core/node_modules/@haad/go-ipfs-dep/go-ipfs/ipfs daemon --enable-pubsub-experiment

  Error: serveHTTPApi: manet.Listen(/ip4/127.0.0.1/tcp/5001) failed: listen tcp4 127.0.0.1:5001: bind: address already in use

      at ChildProcess.<anonymous> (node_modules/subcomandante/fork.js:21:23)
      at maybeClose (internal/child_process.js:885:16)
      at Socket.<anonymous> (internal/child_process.js:334:11)
      at Pipe._handle.close [as _onclose] (net.js:501:12)




npm ERR! Linux 4.8.7-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "test"
npm ERR! node v7.1.0
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE
npm ERR! [email protected] test: `LOG=none ./node_modules/.bin/mocha`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script 'LOG=none ./node_modules/.bin/mocha'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the orbit_ package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     LOG=none ./node_modules/.bin/mocha
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs orbit_
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls orbit_
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/whyrusleeping/code/orbit-core/npm-debug.log
make: *** [Makefile:8: test] Error 1

Error after running

Hello,
I tried running the script on the readme after installing the modules with node, but this error came up:

/Users/behrad/Desktop/Test/node_modules/node-localstorage/LocalStorage.js:160
            throw e;
            ^

Error: ENOENT: no such file or directory, mkdir '/Users/behrad/Desktop/Test/orbit/keys'
    at Object.fs.mkdirSync (fs.js:895:18)
    at LocalStorage._init (/Users/behrad/Desktop/Test/node_modules/node-localstorage/LocalStorage.js:156:14)
    at new LocalStorage (/Users/behrad/Desktop/Test/node_modules/node-localstorage/LocalStorage.js:121:12)
    at Function.useKeyStore (/Users/behrad/Desktop/Test/node_modules/orbit-crypto/index.js:21:18)
    at new Orbit (/Users/behrad/Desktop/Test/node_modules/orbit_/src/Orbit.js:40:12)
    at Object.<anonymous> (/Users/behrad/Desktop/Test/test.js:9:15)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)

I tracked it with the console and it seems to be generating from the line
const orbit = new Orbit(ipfs)
I'm not sure exactly what to do to fix it, I would appreciate the help.
Thank you

Can't add orbit-core to yarn project.

yarn add orbit_ returns:

yarn add v1.13.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^6.x.x". Got "11.9.0
"
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

yarn add orbit_ --ignore-engines seems to be a workaround.

pub/sub not workin

Upon running the browser example, there is a 404 on the console with regards to the pubsub endpoint in the API. Afterwards I tried running the ipfs daemon with ipfs daemon --enable-pubsub-experiment but I get Error: Unrecognized option 'enable-pubsub-experiment'. Is there a particular version of ipfs I need to run? Currently I have 0.4.4

Go Implementation

Hello,

Is there going to be a Golang implementation anytime soon?

Thank you

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.