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

Commit

Permalink
Allow custom js-ipfs (#5)
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
icidasset authored Feb 24, 2020
1 parent 90e92be commit 9ac5dbd
Show file tree
Hide file tree
Showing 6 changed files with 7,650 additions and 6,404 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 1.1.0

Allows you to define your own version of js-ipfs instead of the predefined fallback. Before it would load js-ipfs v0.38, now it loads the latest version from unpkg by default, which you can override as follows using this configuration property:

```
jsIpfs: "https://unpkg.com/ipfs@latest/dist/index.min.js",
jsIpfs: async () => await import("ipfs"),
jsIpfs: () => Promise.resolve(Ipfs)
```
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ A one-stop shop for loading an ipfs instance into a webpage.
Attempts to load ipfs in the following order and returns the result in a Promise:
1. `window.ipfs.enable`: the current `window.ipfs` api. Available if the user is using Opera or has the ipfs-companion extension installed.
2. `window.ipfs`: the old `window.ipfs` api. Does not include enabling permissions all at once.
3. `js-ipfs`: an in-browser ipfs node that communicates via WebRTC/Websockets. The `js-ipfs` code is only loaded if required.
3. `js-ipfs`: an in-browser ipfs node that communicates via WebRTC/Websockets. The `js-ipfs` code is only loaded if required. Can be configured using the `jsIpfs` setting.



## Usage
```

```js
import getIpfs from 'get-ipfs'

const ipfs = await getIpfs([config])
const ipfs = await getIpfs(config)
```

### Config
```

### Config

```js
{
// `permissions` are enabled if the browser is ipfs-capable (Opera or extension)
// passed to `window.ipfs.enable` if available
Expand All @@ -35,25 +39,37 @@ const ipfs = await getIpfs([config])

// `peers` is a list of peer multiaddrs to connect to on load
// to work with the `js-ipfs` fallback, these must have available websocket ports
peers: []
peers: [],

// `browserPeers` is a list of peer multiaddrs to connect to only on fallback to an in-browser js-ipfs daemon
// note: these must be secure websocket or WebRTC addresses
browserPeers: []
browserPeers: [],

// `localPeers` is a list of peer multiaddrs to connect to if using a local ipfs daemon (through ipfs companion for instance)
localPeers: []
localPeers: [],

// (optional) Configure how to load js-ipfs. By default this'll be an unpkg url that points to the latest minified distribution.
jsIpfs: "https://unpkg.com/ipfs@latest/dist/index.min.js",
jsIpfs: async () => await import("ipfs"),
jsIpfs: () => Promise.resolve(Ipfs)
}
```



## Testing

### Tests coming soon!!

- Run `npm i`
- Run tests with: `npm run test`
- Continuously watch with `npm run test:watch`



## Notes
This repo currently makes use of types from [typestub-ipfs](https://github.com/beenotung/typestub-ipfs).

This repo currently makes use of types from [typestub-ipfs](https://github.com/beenotung/typestub-ipfs).

Give your support [here](https://github.com/ipfs/js-ipfs/issues/1166) for types to be merged into `js-ipfs` or `DefinitelyTyped`.

Expand Down
Loading

0 comments on commit 9ac5dbd

Please sign in to comment.