Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 75ab123

Browse files
committed
feat(pubsub): Add pubsub api
1 parent bb1c292 commit 75ab123

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2224
-1582
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
test/setup/tmp-disposable-nodes-addrs.json
44
dist
55
coverage
6+
**/*.swp

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
<a name="13.0.0"></a>
2+
# [13.0.0](https://github.com/ipfs/js-ipfs-api/compare/v12.1.7...v13.0.0) (2017-03-22)
3+
4+
5+
### Features
6+
7+
* change window to self for webworker support ([e2e3213](https://github.com/ipfs/js-ipfs-api/commit/e2e3213))
8+
9+
10+
11+
<a name="12.1.7"></a>
12+
## [12.1.7](https://github.com/ipfs/js-ipfs-api/compare/v12.1.6...v12.1.7) (2017-02-09)
13+
14+
15+
16+
<a name="12.1.6"></a>
17+
## [12.1.6](https://github.com/ipfs/js-ipfs-api/compare/v12.1.5...v12.1.6) (2017-02-01)
18+
19+
20+
21+
<a name="12.1.5"></a>
22+
## [12.1.5](https://github.com/ipfs/js-ipfs-api/compare/v12.1.4...v12.1.5) (2017-01-31)
23+
24+
25+
### Bug Fixes
26+
27+
* lint ([dfb07a3](https://github.com/ipfs/js-ipfs-api/commit/dfb07a3))
28+
29+
30+
31+
<a name="12.1.4"></a>
32+
## [12.1.4](https://github.com/ipfs/js-ipfs-api/compare/v12.1.3...v12.1.4) (2017-01-11)
33+
34+
35+
36+
<a name="12.1.3"></a>
37+
## [12.1.3](https://github.com/ipfs/js-ipfs-api/compare/v12.1.2...v12.1.3) (2017-01-10)
38+
39+
40+
141
<a name="12.1.2"></a>
242
## [12.1.2](https://github.com/ipfs/js-ipfs-api/compare/v12.1.1...v12.1.2) (2016-12-21)
343

README.md

Lines changed: 153 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ ipfs-api
1212
![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
1313
![](https://img.shields.io/badge/Node.js-%3E%3D4.0.0-orange.svg?style=flat-square)
1414

15-
[![Sauce Test Status](https://saucelabs.com/browser-matrix/js-ipfs-api.svg)](https://saucelabs.com/u/ipfs-js-api)
16-
17-
> **Note: If you see CI red, that is due a failing test when adding nested directories in the browser, all the other features work as expect, if this is something you also need, please consider helping us identifying the solution for it, join the discussion at: https://github.com/ipfs/js-ipfs-api/issues/339**
15+
<!-- Hidding this until we have the SauceLabs situation figured out.
16+
[![Sauce Test Status](https://saucelabs.com/browser-matrix/js-ipfs-api.svg)](https://saucelabs.com/u/ipfs-js-api)
17+
-->
1818

1919
> A client library for the IPFS HTTP API, implemented in JavaScript. This client library implements the [interface-ipfs-core](https://github.com/ipfs/interface-ipfs-core) enabling applications to change between a embebed js-ipfs node and any remote IPFS node without having to change the code. In addition, this client library implements a set of utility functions.
2020
@@ -39,25 +39,25 @@ ipfs-api
3939
This module uses node.js, and can be installed through npm:
4040

4141
```bash
42-
$ npm install --save ipfs-api
42+
> npm install --save ipfs-api
4343
```
4444

45-
**Note:** ipfs-api requires Node v4.x (LTS) or higher.
45+
**Note:** ipfs-api requires Node.js v4 (LTS) or higher.
4646

4747
### Running the daemon with the right port
4848

4949
To interact with the API, you need to have a local daemon running. It needs to be open on the right port. `5001` is the default, and is used in the examples below, but it can be set to whatever you need.
5050

5151
```sh
5252
# Show the ipfs config API port to check it is correct
53-
$ ipfs config Addresses.API
53+
> ipfs config Addresses.API
5454
/ip4/127.0.0.1/tcp/5001
5555
# Set it if it does not match the above output
56-
$ ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
56+
> ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
5757
# Restart the daemon after changing the config
5858

5959
# Run the daemon
60-
$ ipfs daemon
60+
> ipfs daemon
6161
```
6262

6363
### Importing the module and usage
@@ -72,7 +72,7 @@ var ipfs = ipfsAPI('localhost', '5001', {protocol: 'http'}) // leaving out the a
7272
var ipfs = ipfsAPI('/ip4/127.0.0.1/tcp/5001')
7373

7474
// or using options
75-
var ipfs = ipfsAPI({host: 'localhost', port: '5001', procotol: 'http'})
75+
var ipfs = ipfsAPI({host: 'localhost', port: '5001', protocol: 'http'})
7676
```
7777

7878
### In a web browser through Browserify
@@ -111,7 +111,7 @@ integrity="sha384-5bXRcW9kyxxnSMbOoHzraqa7Z0PQWIao+cgeg327zit1hz5LZCEbIMx/LWKPRe
111111
crossorigin="anonymous"></script>
112112
```
113113

114-
CDN-based IPFS API provides the `IpfsApi` constructor as a method of the global `window` object. Example:
114+
CDN-based IPFS API provides the `IpfsApi` constructor as a method of the global `window` object. Example:
115115

116116
```
117117
var ipfs = window.IpfsApi('localhost', '5001')
@@ -137,7 +137,144 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P
137137

138138
### API
139139

140-
> `js-ipfs-api` follows the spec defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor - expect it to be complete in the next few weeks (August 2016). You can use it today to consult the methods available.
140+
> `js-ipfs-api` follows the spec defined by [`interface-ipfs-core`](https://github.com/ipfs/interface-ipfs-core), which concerns the interface to expect from IPFS implementations. This interface is a currently active endeavor. You can use it today to consult the methods available.
141+
142+
#### Caveats
143+
144+
##### Pubsub
145+
146+
**Currently, the [PubSub API only works in Node.js envinroment](https://github.com/ipfs/js-ipfs-api/issues/518)**
147+
148+
We currently don't support pubsub when run in the browser, and we test it with separate set of tests to make sure if it's being used in the browser, pubsub errors.
149+
150+
More info: https://github.com/ipfs/js-ipfs-api/issues/518
151+
152+
This means:
153+
- You can use pubsub from js-ipfs-api in Node.js
154+
- You can use pubsub from js-ipfs-api in Electron
155+
(when js-ipfs-api is ran in the main process of Electron)
156+
- You can't use pubsub from js-ipfs-api in the browser
157+
- You can't use pubsub from js-ipfs-api in Electron's
158+
renderer process
159+
- You can use pubsub from js-ipfs in the browsers
160+
- You can use pubsub from js-ipfs in Node.js
161+
- You can use pubsub from js-ipfs in Electron
162+
(in both the main process and the renderer process)
163+
- See https://github.com/ipfs/js-ipfs for details on
164+
pubsub in js-ipfs
165+
166+
##### [bitswap]()
167+
168+
- [`ipfs.bitswap.wantlist()`]()
169+
- [`ipfs.bitswap.stat()`]()
170+
- [`ipfs.bitswap.unwant()`]()
171+
172+
##### [block](https://github.com/ipfs/interface-ipfs-core/tree/master/API/block)
173+
174+
- [`ipfs.block.get(cid, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#get)
175+
- [`ipfs.block.put(block, cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#put)
176+
- [`ipfs.block.stat(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/block#stat)
177+
178+
##### [bootstrap]()
179+
180+
- [`ipfs.bootstrap.list()`]()
181+
- [`ipfs.bootstrap.add()`]()
182+
- [`ipfs.bootstrap.rm()`]()
183+
184+
##### [config](https://github.com/ipfs/interface-ipfs-core/tree/master/API/config)
185+
186+
- [`ipfs.config.get([key, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/config#configget)
187+
- [`ipfs.config.set(key, value, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/config#configset)
188+
- [`ipfs.config.replace(config, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/config#configreplace)
189+
190+
##### [dag (not implemented, yet!)](https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag)
191+
192+
- [`ipfs.dag.put(dagNode, options, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag#dagput)
193+
- [`ipfs.dag.get(cid [, path, options], callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag#dagget)
194+
- [`ipfs.dag.tree(cid [, path, options], callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/dag#dagtree)
195+
196+
##### [dht]()
197+
198+
- [`ipfs.dht.findprovs()`]()
199+
- [`ipfs.dht.get()`]()
200+
- [`ipfs.dht.put()`]()
201+
202+
##### [files](https://github.com/ipfs/interface-ipfs-core/tree/master/API/files)
203+
204+
- [`ipfs.files.add(data, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/files#add)
205+
- alias to `ipfs.add`
206+
- [`ipfs.files.createAddStream([options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/files#createaddstream)
207+
- [`ipfs.files.cat(multihash, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/files#cat)
208+
- alias to `ipfs.cat`
209+
- [`ipfs.files.get(hash, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/files#get)
210+
- alias to `ipfs.get`
211+
- [`ipfs.ls`]()
212+
- mfs (mutable file system) specific:
213+
- [`ipfs.files.cp`]()
214+
- [`ipfs.files.ls`]()
215+
- [`ipfs.files.mkdir`]()
216+
- [`ipfs.files.stat`]()
217+
- [`ipfs.files.rm`]()
218+
- [`ipfs.files.read`]()
219+
- [`ipfs.files.write`]()
220+
- [`ipfs.files.mv`]()
221+
222+
##### [generic operations](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic)
223+
224+
- [`ipfs.id([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#id)
225+
- [`ipfs.version([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/generic#version)
226+
- [`ipfs.ping()`]()
227+
- [`ipfs.log()`]()
228+
229+
##### [name]()
230+
231+
- [`ipfs.name.publish()`]()
232+
- [`ipfs.name.resolve()`]()
233+
234+
##### [object](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object)
235+
236+
- [`ipfs.object.new([template][, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectnew)
237+
- [`ipfs.object.put(obj, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectput)
238+
- [`ipfs.object.get(multihash, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectget)
239+
- [`ipfs.object.data(multihash, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectdata)
240+
- [`ipfs.object.links(multihash, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectlinks)
241+
- [`ipfs.object.stat(multihash, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectstat)
242+
- [`ipfs.object.patch.addLink(multihash, DAGLink, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchaddlink)
243+
- [`ipfs.object.patch.rmLink(multihash, DAGLink, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchrmlink)
244+
- [`ipfs.object.patch.appendData(multihash, data, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchappenddata)
245+
- [`ipfs.object.patch.setData(multihash, data, [options, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/object#objectpatchsetdata)
246+
247+
##### [pin]()
248+
249+
- [`ipfs.pin.add()`]()
250+
- [`ipfs.pin.rm()`]()
251+
- [`ipfs.pin.ls()`]()
252+
253+
##### [pubsub (not implemented, yet!)](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub)
254+
255+
> active branch: https://github.com/ipfs/js-ipfs-api/pull/493
256+
257+
- [`ipfs.pubsub.subscribe(topic, options, handler, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub#pubsubsubscribe)
258+
- [`ipfs.pubsub.unsubscribe(topic, handler)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub#pubsubunsubscribe)
259+
- [`ipfs.pubsub.publish(topic, data, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub#pubsubpublish)
260+
- [`ipfs.pubsub.ls(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub#pubsubls)
261+
- [`ipfs.pubsub.peers(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/pubsub#pubsubpeers)
262+
263+
##### [refs]()
264+
265+
- [`ipfs.refs.local()`]()
266+
267+
##### [repo]()
268+
269+
- [`ipfs.repo.stat()`]()
270+
- [`ipfs.repo.gc()`]()
271+
272+
##### [swarm](https://github.com/ipfs/interface-ipfs-core/tree/master/API/swarm)
273+
274+
- [`ipfs.swarm.addrs([callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/swarm#addrs)
275+
- [`ipfs.swarm.connect(addr, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/swarm#connect)
276+
- [`ipfs.swarm.disconnect(addr, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/swarm#disconnect)
277+
- [`ipfs.swarm.peers([opts] [, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/API/swarm#peers)
141278

142279
### Utility functions
143280

@@ -150,10 +287,13 @@ Complete documentation for these methods is coming with: https://github.com/ipfs
150287

151288
> `ipfs.util.addFromFs(path, option, callback)`
152289
153-
Reads a file from `path` on the filesystem and adds it to IPFS. If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
290+
Reads a file or folder from `path` on the filesystem and adds it to IPFS. Options:
291+
- **recursive**: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
292+
- **ignore**: To exclude fileglobs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
293+
- **hidden**: hidden/dot files (files or folders starting with a `.`, for example, `.git/`) are not included by default. To add them, use the option `{ hidden: true }`.
154294

155295
```JavaScript
156-
ipfs.util.addFromFs('path/to/a/file', { recursive: true }, (err, result) => {
296+
ipfs.util.addFromFs('path/to/a/folder', { recursive: true , ignore: ['subfolder/to/ignore/**']}, (err, result) => {
157297
if (err) {
158298
throw err
159299
}

examples/bundle-webpack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "bundle-browserify",
2+
"name": "bundle-webpack",
33
"version": "1.0.0",
4-
"description": "Bundle js-ipfs-api with Browserify",
4+
"description": "Bundle js-ipfs-api with Webpack",
55
"scripts": {
66
"start": "node server.js"
77
},

gulpfile.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
const gulp = require('gulp')
44

5-
require('./test/setup/spawn-daemons')
6-
require('./test/factory/factory-tasks')
5+
require('./test/ipfs-factory/tasks')
76

8-
gulp.task('test:node:before', ['daemons:start', 'factory:start'])
9-
gulp.task('test:node:after', ['daemons:stop', 'factory:stop'])
10-
gulp.task('test:browser:before', ['daemons:start', 'factory:start'])
11-
gulp.task('test:browser:after', ['daemons:stop', 'factory:stop'])
7+
gulp.task('test:node:before', ['factory:start'])
8+
gulp.task('test:node:after', ['factory:stop'])
9+
gulp.task('test:browser:before', ['factory:start'])
10+
gulp.task('test:browser:after', ['factory:stop'])
1211

1312
require('aegir/gulp')(gulp)

0 commit comments

Comments
 (0)