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

Commit 9ac5dbd

Browse files
authored
Allow custom js-ipfs (#5)
v1.1.0
1 parent 90e92be commit 9ac5dbd

File tree

6 files changed

+7650
-6404
lines changed

6 files changed

+7650
-6404
lines changed

CHANGELOG

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## 1.1.0
4+
5+
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:
6+
7+
```
8+
jsIpfs: "https://unpkg.com/ipfs@latest/dist/index.min.js",
9+
jsIpfs: async () => await import("ipfs"),
10+
jsIpfs: () => Promise.resolve(Ipfs)
11+
```

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@ A one-stop shop for loading an ipfs instance into a webpage.
1515
Attempts to load ipfs in the following order and returns the result in a Promise:
1616
1. `window.ipfs.enable`: the current `window.ipfs` api. Available if the user is using Opera or has the ipfs-companion extension installed.
1717
2. `window.ipfs`: the old `window.ipfs` api. Does not include enabling permissions all at once.
18-
3. `js-ipfs`: an in-browser ipfs node that communicates via WebRTC/Websockets. The `js-ipfs` code is only loaded if required.
18+
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.
19+
1920

2021

2122
## Usage
22-
```
23+
24+
```js
2325
import getIpfs from 'get-ipfs'
2426

25-
const ipfs = await getIpfs([config])
27+
const ipfs = await getIpfs(config)
2628
```
2729

28-
### Config
29-
```
30+
31+
### Config
32+
33+
```js
3034
{
3135
// `permissions` are enabled if the browser is ipfs-capable (Opera or extension)
3236
// passed to `window.ipfs.enable` if available
@@ -35,25 +39,37 @@ const ipfs = await getIpfs([config])
3539

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

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

4448
// `localPeers` is a list of peer multiaddrs to connect to if using a local ipfs daemon (through ipfs companion for instance)
45-
localPeers: []
49+
localPeers: [],
50+
51+
// (optional) Configure how to load js-ipfs. By default this'll be an unpkg url that points to the latest minified distribution.
52+
jsIpfs: "https://unpkg.com/ipfs@latest/dist/index.min.js",
53+
jsIpfs: async () => await import("ipfs"),
54+
jsIpfs: () => Promise.resolve(Ipfs)
4655
}
4756
```
4857

58+
59+
4960
## Testing
61+
5062
### Tests coming soon!!
63+
5164
- Run `npm i`
5265
- Run tests with: `npm run test`
5366
- Continuously watch with `npm run test:watch`
5467

68+
69+
5570
## Notes
56-
This repo currently makes use of types from [typestub-ipfs](https://github.com/beenotung/typestub-ipfs).
71+
72+
This repo currently makes use of types from [typestub-ipfs](https://github.com/beenotung/typestub-ipfs).
5773

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

0 commit comments

Comments
 (0)