diff --git a/.gitignore b/.gitignore index 1f5aa33552..1f90ef6ecd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/node_modules/ **/*.log test/repo-tests* +**/bundle.js # Logs logs @@ -35,4 +36,4 @@ lib dist test/test-data/go-ipfs-repo/LOCK test/test-data/go-ipfs-repo/LOG -test/test-data/go-ipfs-repo/LOG.old \ No newline at end of file +test/test-data/go-ipfs-repo/LOG.old diff --git a/README.md b/README.md index 9817c736cd..e8953f17c0 100644 --- a/README.md +++ b/README.md @@ -7,59 +7,28 @@

The JavaScript implementation of the IPFS protocol.

- - - - - - - - - + + +
- - - - - - - - - + + +

- - - - - - - - - + + +
- - - - - - - - - - - - - - - + + + + +
+ -->

### Project status @@ -138,18 +107,17 @@ In order to use js-ipfs as a CLI, you must install it with the `global` flag. Ru $ npm install ipfs --global ``` -The CLI is available by using the command `jsipfs` in your terminal. This is aliased, instead of using `ipfs`, to make sure it does not conflict with the Go implementation. - -### Use in the browser with browserify, webpack or any bundler +The CLI is available by using the command `jsipfs` in your terminal. This is aliased, instead of using `ipfs`, to make sure it does not conflict with the [Go implementation](https://github.com/ipfs/go-ipfs). -You can find examples of how to do this bundling at: `https://github.com/ipfs/js-ipfs/tree/master/examples`. If you are using webpack, make sure to use version 2 or above, otherwise it won't work. +### Use in the browser -### Use in a browser using a script tag +##### With browserify, webpack or any bundler -Loading this module in a browser (using a ` + + diff --git a/examples/electron/main.js b/examples/electron/main.js new file mode 100755 index 0000000000..ac40ba2e8a --- /dev/null +++ b/examples/electron/main.js @@ -0,0 +1,58 @@ +'use strict' + +const electron = require('electron') +const app = electron.app +const BrowserWindow = electron.BrowserWindow + +const IPFS = require('ipfs') +const path = require('path') +const url = require('url') + +let mainWindow + +function createWindow () { + mainWindow = new BrowserWindow({width: 800, height: 600}) + + // and load the index.html of the app. + mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + })) + + // Open the DevTools. + mainWindow.webContents.openDevTools() + + // Emitted when the window is closed. + mainWindow.on('closed', () => { + mainWindow = null + }) +} + +app.on('ready', () => { + createWindow() + + // Spawn your IPFS node \o/ + const node = new IPFS() + + node.on('ready', () => { + node.id((err, id) => { + if (err) { + return console.log(err) + } + console.log(id) + }) + }) +}) + +// Quit when all windows are closed. +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { app.quit() } +}) + +app.on('activate', () => { + if (mainWindow === null) { createWindow() } +}) + +// In this file you can include the rest of your app's specific main process +// code. You can also put them in separate files and require them here. diff --git a/examples/electron/package.json b/examples/electron/package.json new file mode 100755 index 0000000000..579cabbc15 --- /dev/null +++ b/examples/electron/package.json @@ -0,0 +1,22 @@ +{ + "name": "js-ipfs-in-electron", + "version": "0.0.0", + "description": "A minimal Electron application with js-ipfs", + "main": "main.js", + "scripts": { + "start": "electron .", + "postinstall": "electron-rebuild" + }, + "keywords": [ + "Electron", + "IPFS", + "Example" + ], + "author": "David Dias ", + "license": "MIT", + "devDependencies": { + "electron": "~1.6.11", + "electron-rebuild": "^1.5.11", + "ipfs": "ipfs/js-ipfs#feat\/no-wrtc-by-default" + } +} diff --git a/examples/electron/renderer.js b/examples/electron/renderer.js new file mode 100755 index 0000000000..e69de29bb2 diff --git a/package.json b/package.json index 35d134e302..634237a757 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "expose-loader": "^0.7.3", "form-data": "^2.2.0", "gulp": "^3.9.1", - "interface-ipfs-core": "~0.29.0", + "interface-ipfs-core": "~0.29.1", "ipfsd-ctl": "~0.21.0", "left-pad": "^1.1.3", "lodash": "^4.17.4", @@ -81,14 +81,14 @@ "nexpect": "^0.5.0", "pre-commit": "^1.2.2", "pretty-bytes": "^4.0.2", - "qs": "^6.4.0", + "qs": "^6.5.0", "random-fs": "^1.0.3", "rimraf": "^2.6.1", "stream-to-promise": "^2.2.0", "transform-loader": "^0.2.4" }, "dependencies": { - "async": "^2.4.1", + "async": "^2.5.0", "bl": "^1.2.1", "boom": "^5.1.0", "cids": "^0.5.0", @@ -98,7 +98,7 @@ "hapi": "^16.4.3", "hapi-set-header": "^1.0.2", "hoek": "^4.1.1", - "ipfs-api": "^14.0.3", + "ipfs-api": "^14.0.4", "ipfs-bitswap": "~0.13.1", "ipfs-block": "~0.6.0", "ipfs-block-service": "~0.9.1", @@ -111,8 +111,8 @@ "isstream": "^0.1.2", "joi": "^10.6.0", "libp2p-floodsub": "~0.9.4", - "libp2p-ipfs-browser": "~0.24.1", - "libp2p-ipfs-nodejs": "~0.25.2", + "libp2p-ipfs-browser": "~0.25.0", + "libp2p-ipfs-nodejs": "~0.26.0", "lodash.flatmap": "^4.5.0", "lodash.get": "^4.4.2", "lodash.has": "^4.5.2", @@ -132,13 +132,13 @@ "pull-file": "^1.0.0", "pull-paramap": "^1.2.2", "pull-pushable": "^2.1.1", - "pull-sort": "^1.0.0", + "pull-sort": "^1.0.1", "pull-stream": "^3.6.0", "pull-stream-to-stream": "^1.3.4", "pull-zip": "^2.0.1", "read-pkg-up": "^2.0.0", "readable-stream": "1.1.14", - "safe-buffer": "^5.1.0", + "safe-buffer": "^5.1.1", "stream-to-pull-stream": "^1.7.2", "tar-stream": "^1.5.4", "temp": "^0.8.3", diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index c0dbb79b59..1cc3ed490a 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -18,7 +18,8 @@ module.exports = function libp2p (self) { mdns: get(config, 'Discovery.MDNS.Enabled'), webRTCStar: get(config, 'Discovery.webRTCStar.Enabled'), bootstrap: get(config, 'Bootstrap'), - dht: self._options.EXPERIMENTAL.dht + dht: get(self._options, 'EXPERIMENTAL.dht'), + modules: get(self._options, 'libp2p.modules') } self._libp2pNode = new Node(self._peerInfo, self._peerInfoBook, options) diff --git a/src/http-api/index.js b/src/http-api/index.js index 0c93b889e2..cd8106657d 100644 --- a/src/http-api/index.js +++ b/src/http-api/index.js @@ -8,6 +8,7 @@ const setHeader = require('hapi-set-header') const once = require('once') const IPFS = require('../core') +const WStar = require('libp2p-webrtc-star') const errorHandler = require('./error-handler') function uriToMultiaddr (uri) { @@ -31,6 +32,22 @@ function HttpApi (repo, config) { series([ (cb) => { + const libp2p = { + modules: {} + } + + // Attempt to use any of the WebRTC versions available globally + let electronWebRTC + let wrtc + try { electronWebRTC = require('electron-webrtc')() } catch (err) {} + try { wrtc = require('wrtc') } catch (err) {} + + if (electronWebRTC || wrtc) { + const wstar = new WStar(electronWebRTC || wrtc) + libp2p.modules.transport = [wstar] + libp2p.modules.discovery = [wstar.discovery] + } + // try-catch so that programmer errors are not swallowed during testing try { // start the daemon