-
Notifications
You must be signed in to change notification settings - Fork 325
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
Init ipfs-api or js-ipfs #320
Changes from 4 commits
e030a36
7913c2e
4f2eba9
2033c83
f603614
b1c6dbe
67f8003
c3ce095
00f913e
e0e17d8
d3989ec
f440bb3
ffc36f8
eda6abf
4c50055
8529944
7ff69af
5a4a4f8
84b2ada
a0c38aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
const Ipfs = require('ipfs') | ||
|
||
let node = null | ||
|
||
exports.init = function init () { | ||
console.log('[ipfs-companion] Embedded ipfs init') | ||
|
||
node = new Ipfs({ | ||
config: { | ||
Addresses: { | ||
Swarm: [] | ||
} | ||
} | ||
}) | ||
|
||
if (node.isOnline()) { | ||
return Promise.resolve(node) | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
// TODO: replace error listener after a 'ready' event. | ||
node.once('error', (err) => reject(err)) | ||
node.once('ready', () => resolve(node)) | ||
}) | ||
} | ||
|
||
exports.destroy = async function () { | ||
if (!node) return | ||
|
||
await node.stop() | ||
node = null | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
/* eslint-env browser */ | ||
|
||
const IpfsApi = require('ipfs-api') | ||
|
||
exports.init = async function (opts) { | ||
console.log('[ipfs-companion] External ipfs init') | ||
|
||
const url = new URL(opts.ipfsApiUrl) | ||
const api = IpfsApi({host: url.hostname, port: url.port, procotol: url.protocol}) | ||
return api | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const embedded = require('./embedded') | ||
const external = require('./external') | ||
|
||
let client = null | ||
|
||
exports.initIpfsClient = async function (opts) { | ||
if (client && client.destroy) { | ||
await client.destroy() | ||
} | ||
|
||
if (opts.ipfsNodeType === 'embedded') { | ||
client = await embedded.init(opts) | ||
} else { | ||
client = await external.init(opts) | ||
} | ||
|
||
return client | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,11 @@ | |
"build:copy": "run-s build:copy:*", | ||
"build:copy:src": "shx mkdir -p add-on/dist && shx cp -R add-on/src/* add-on/dist", | ||
"build:copy:wx-polyfill-lib": "shx cp node_modules/webextension-polyfill/dist/browser-polyfill.min.js add-on/dist/contentScripts/browser-polyfill.min.js", | ||
"build:js": "browserify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js ] -o add-on/dist/ipfs-companion-common.js", | ||
"build:js": "browserify -p prundupify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js ] -o add-on/dist/ipfs-companion-common.js", | ||
"build:minimize-dist": "shx rm -rf add-on/dist/lib", | ||
"build:bundle-extension": "web-ext build -s add-on/ -i src/ -a build/", | ||
"watch": "run-p watch:*", | ||
"watch:js": "watchify add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js ] -o add-on/dist/ipfs-companion-common.js -v", | ||
"watch:js": "watchify -p prundupify -t [ browserify-package-json --global ] add-on/src/background/background.js add-on/src/options/options.js add-on/src/popup/browser-action/index.js add-on/src/popup/quick-upload.js -p [ factor-bundle -o add-on/dist/background/background.js -o add-on/dist/options/options.js -o add-on/dist/popup/browser-action/browser-action.js -o add-on/dist/popup/quick-upload.js ] -o add-on/dist/ipfs-companion-common.js -v", | ||
"test": "run-s test:*", | ||
"test:functional": "mocha test/functional/**/*.test.js", | ||
"lint": "run-s lint:*", | ||
|
@@ -68,9 +68,11 @@ | |
}, | ||
"dependencies": { | ||
"choo": "6.6.0", | ||
"ipfs": "^0.26.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try to keep all versions locked, so that we don't have big divergence between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, for IPFS land, always use |
||
"ipfs-api": "17.1.3", | ||
"is-ipfs": "0.3.2", | ||
"lru_map": "0.3.3", | ||
"prundupify": "^1.0.0", | ||
"webextension-polyfill": "0.1.2" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some feedback from the last IPFS all hands was that
embedded
might confuse devs to think that know there is awindow.ipfs
in every page. Is that one of the goals too? It would be a good feature to have (optionally)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be simple to add. Is the idea that users would write scripts against
window.ipfs
but not bundle it with their script? It sounds a little bit like those browser extensions that add jquery to every page, so you can noodle around in the dev console.Do people have a use-case in mind? T feel like we should be directing devs to the js-ipfs examples, to show them how to bundle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference between adding jquery and ipfs is that on one you would be just packing more code, the second you are opening more ports and doing more crypto which are both expensive operations.
The Metamask team has been injecting Web3 to every page to let devs use Ethereum directly if WebPages are there.
I feel this should be one of the options for the extension and until we have concrete use cases, just refer to an example on how to use it to seed it to developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of benefits for embedding an already running IPFS node in webpages, too many to list here, but for starter, it makes startup times a lot better as nothing has to initialized, just start using it directly (node in background is already running so!). Performance of loading pages and loading content will be faster as well. Things can be shared via MFS between applications, as long as they agree on a standard structure. ID can follow between applications as well. Just a few reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool! I like the idea of making ipfs available to webapps and seeing what people do with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #330, I created it to track
window.ipfs
effort :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This! https://github.com/VictorBjelkholm/js-ipfs-in-the-browser