-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Conversation
This lets you construct a Buffer even in browser code that doesn't have access to the Node Buffer global, so that you can pass it back to IPFS API calls that want a Buffer. Add some usage documentation Mentions the `ipfs.Buffer` field you can use to stamp out `Buffer`s so you can actually insert stuff given just an `IPFS` instance and no Node.js APIs in scope. Also add examples for using IPFS in browser with a script tag, and for using libp2p-webrtc-star.
README.md
Outdated
@@ -85,6 +85,9 @@ You can check the development status at: | |||
- [HTTP-API](#http-api) | |||
- [IPFS Core (use IPFS as a module in Node.js or in the Browser)](#ipfs-core-examples-use-ipfs-as-a-module) | |||
- [Create a IPFS node instance](#create-a-ipfs-node-instance) | |||
- [Add a file](#add-a-file) | |||
- [Retrieve a file](#retrieve-a-file) |
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 believe this is well demonstrated in the examples folder, we can trim the README by just pointing to those examples.
README.md
Outdated
* [`ipfs.types.PeerId`](https://github.com/libp2p/js-peer-id) | ||
* [`ipfs.types.PeerInfo`](https://github.com/libp2p/js-peer-info) | ||
* [`ipfs.types.multiaddr`](https://github.com/multiformats/js-multiaddr) | ||
* [`ipfs.types.multihash`](https://github.com/multiformats/js-multihash) |
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.
👌🏽
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.
Also add CID https://github.com/ipld/js-cid
examples/browser-script/README.md
Outdated
@@ -0,0 +1,13 @@ | |||
# Use IPFS in the browser with `<script>` tags |
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.
call the folder 'browser-script-tag'
@@ -0,0 +1,14 @@ | |||
# Robust Initialization and libp2p-webrtc-star Signaling |
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.
Let's call this example 'how-to-use-webrtc-star'
@diasdavid I think I addressed everything. |
README.md
Outdated
@@ -229,6 +232,10 @@ node.init({ emptyRepo: true, bits: 2048 }, (err) => { | |||
|
|||
> We are working on making this init process better, see https://github.com/ipfs/js-ipfs/issues/556 for the discussion. | |||
|
|||
More examples can be found in the [examples folder](./examples) | |||
|
|||
> If you have built an example, please share it with the community by submitting a Pull Request to this repo!. |
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.
Let's remove this line, we don't necessarily want to have thousands of examples, instead we want to have a selected few that cover it all
Done @diasdavid 👍 |
// Set this if you have a libp2p-webrtc-star server | ||
// Something like | ||
// const SIGNALING_SERVER = '/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/' | ||
const SIGNALING_SERVER = null |
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.
Let's set this one with the sig server hosted by us https://github.com/libp2p/js-libp2p-webrtc-star#hosted-signalling-server
// const SIGNALING_SERVER = '/libp2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/' | ||
const SIGNALING_SERVER = null | ||
|
||
// Make an IPFS node |
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.
s/Make/Create
const SIGNALING_SERVER = null | ||
|
||
// Make an IPFS node | ||
var ipfs = new Ipfs() |
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.
s/ipfs/node
// Init a repo in the given IPFS node it if hasn't got one already. Calls the | ||
// setup callback, passing the normal callback, after first initialization. | ||
// Calls the normal callback directly after subsequent initializations. Calls | ||
// the normal callback with an error parameter if there is an error. |
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 sentence is super confusing, let's say instead:
Attempt to initialize the Repo, if one already exists, it uses that one.
// Methods requiring buffers can use ipfs.Buffer | ||
}) | ||
}) | ||
}) |
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.
Wanna try to improve this section 19-76, the code isn't super clear.
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.
Shall we make this compatible with ES5 or no need for it?
</head> | ||
<body> | ||
<h1>IPFS in the Browser</h1> | ||
<p>This page creates an IPFS node in your browser and drops it into the global Javascript namespace as <em>ipfs</em>. Open the console to play around with it.</p> |
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.
Add some suggestions of the commands that can be run. Like cat an hash that returns hello world :)
@@ -0,0 +1,99 @@ | |||
<!doctype html> |
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.
Sorry to be asking this now, but can you make this example a separate PR? I'm not super happy with the explanation provided and I know you are building on top of another contributor work, so don't feel the pressure to change it now. I can improve it :)
@JGAntunes almost there, one more round :) |
src/core/index.js
Outdated
@@ -63,6 +73,9 @@ class IPFS { | |||
this.ping = components.ping(this) | |||
this.pubsub = components.pubsub(this) | |||
|
|||
// expose Buffer for browser applications | |||
this.Buffer = Buffer |
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.
Do we still need this @diasdavid?
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.
we can take it it, since we know have it under types.
Ok, I think this is it @diasdavid. I refactored a bit of the browser script tag example but tried to keep it simple without adding any unnecessary patterns given that is just an example, let me know what you think. |
2156ea5
to
ebb0717
Compare
woot, thank you @JGAntunes :D |
Finishing the awesome work started by @interfect on #525.
I think I've addressed all your requests @diasdavid. Check it and let me know what you think.