Skip to content
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

fix: suggest ipfs-provider for window.ipfs fallback #207

Merged
merged 1 commit into from
May 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/how-to/companion-window-ipfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Learn about exposing IPFS API in IPFS Companion via "window.ipfs".

IPFS Companion 2.11 stopped injecting `window.ipfs`. It will be restored after the [move to JS API with async await and async iterables](https://github.com/ipfs-shipyard/ipfs-companion/issues/843), with a likely ETA of Q3 2020. This page is provided for reference only.

:::

<!-- below disclaimer will be restored when window.ipfs injection resumes
### Disclaimer

There is a substantial amount of [ongoing work for this interface](https://github.com/ipfs-shipyard/ipfs-companion/issues/589). Want to help with shaping it? See [#589](https://github.com/ipfs-shipyard/ipfs-companion/issues/589) and [issues with the `area/window-ipfs` label](https://github.com/ipfs-shipyard/ipfs-companion/labels/area%2Fwindow-ipfs).
The interface is experimental and might change: there is a substantial amount of [ongoing work](https://github.com/ipfs-shipyard/ipfs-companion/issues/589). Want to help with shaping it? See [#589](https://github.com/ipfs-shipyard/ipfs-companion/issues/589) and [issues with the `area/window-ipfs` label](https://github.com/ipfs-shipyard/ipfs-companion/labels/area%2Fwindow-ipfs).
-->

The interface is experimental and might change. Use [window.ipfs-fallback](https://www.npmjs.com/package/window.ipfs-fallback) to ensure your app follows any future changes
:::

## Background

Expand All @@ -45,6 +45,10 @@ if (window.ipfs && window.ipfs.enable) {

To add and get content, you could update the above example to do something like this:

<!-- TODO: update below example to use async iterators:
https://blog.ipfs.io/2020-02-01-async-await-refactor/
-->

```js
if (window.ipfs && window.ipfs.enable) {
try {
Expand All @@ -67,6 +71,12 @@ if (window.ipfs && window.ipfs.enable) {
}
```

::: tip

Use [ipfs-provider](https://github.com/ipfs-shipyard/ipfs-provider) to ensure your app follows any future changes of this interface. It reduces amount of code needed to implement a robust fallback to HTTP API or embedded js-ipfs when `window.ipfs` is not available.

:::

### Error codes

Errors returned by IPFS proxy can be identified by the value of the `code` attribute.
Expand Down