Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Feat/expose ipfs utils #784

Merged
merged 10 commits into from
Mar 13, 2017
Merged

Feat/expose ipfs utils #784

merged 10 commits into from
Mar 13, 2017

Conversation

JGAntunes
Copy link
Member

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.

interfect and others added 3 commits March 11, 2017 16:54
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.
@jbenet jbenet added the status/in-progress In progress label Mar 11, 2017
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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏽

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,13 @@
# Use IPFS in the browser with `<script>` tags
Copy link
Member

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
Copy link
Member

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'

@JGAntunes
Copy link
Member Author

@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!.
Copy link
Member

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

@JGAntunes
Copy link
Member Author

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
Copy link
Member

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
Copy link
Member

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()
Copy link
Member

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.
Copy link
Member

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
})
})
})
Copy link
Member

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.

Copy link
Member Author

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>
Copy link
Member

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>
Copy link
Member

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 :)

@daviddias
Copy link
Member

@JGAntunes almost there, one more round :)

@@ -63,6 +73,9 @@ class IPFS {
this.ping = components.ping(this)
this.pubsub = components.pubsub(this)

// expose Buffer for browser applications
this.Buffer = Buffer
Copy link
Member Author

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?

Copy link
Member

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.

@JGAntunes
Copy link
Member Author

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.

@daviddias daviddias merged commit e769719 into master Mar 13, 2017
@daviddias daviddias deleted the feat/expose-ipfs-utils branch March 13, 2017 10:34
@daviddias daviddias removed the status/in-progress In progress label Mar 13, 2017
@daviddias
Copy link
Member

woot, thank you @JGAntunes :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants