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

Commit 795e1ec

Browse files
authoredNov 27, 2017
docs: disable WebRTC by default and add how to support it + websocket-star to the FAQ (#1111)
* fix: disable WebRTC by default * add websocket-star to FAQ * fix typo * update exchange files example * chore: update
1 parent b4f629f commit 795e1ec

File tree

3 files changed

+85
-27
lines changed

3 files changed

+85
-27
lines changed
 

‎README.md

+67-21
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ You can check the development status at the [Waffle Board](https://waffle.io/ipf
4242

4343
[![Throughput Graph](https://graphs.waffle.io/ipfs/js-ipfs/throughput.svg)](https://waffle.io/ipfs/js-ipfs/metrics/throughput)
4444

45-
**Important to note:** DHT and Relay are not finalized yet, you won't have resource discovery happening by default as you get in go-ipfs, we are working actively on these pieces, please follow:
45+
**Please read this:** DHT (automatic content discovery) and Circuit Relay (pierce through NATs and dial between any node in the network) are two fundamental pieces that are not finalized yet. There are multiple applications that can be built without these two services but nevertheless they are fundamental to get that magic IPFS experience. If you want to track progress or contribute, please follow:
46+
4647
- DHT: https://github.com/ipfs/js-ipfs/pull/856
47-
- Relay: https://github.com/ipfs/js-ipfs/pull/830
48+
- Relay: https://github.com/ipfs/js-ipfs/pull/1063
4849

4950
## Table of Contents
5051

@@ -54,10 +55,10 @@ You can check the development status at the [Waffle Board](https://waffle.io/ipf
5455
- [Through command line tool](#through-command-line-tool)
5556
- [Use in the browser](#use-in-the-browser)
5657
- [Usage](#usage)
57-
- [CLI](#cli)
58-
- [HTTP-API](#http-api)
59-
- [IPFS Core (use IPFS as a module in Node.js or in the Browser)](#ipfs-core-use-ipfs-as-a-module)
60-
- [Create a IPFS node instance](#create-a-ipfs-node-instance)
58+
- [IPFS CLI](#ipfs-cli)
59+
- [IPFS Daemon](#ipfs-daemon)
60+
- [IPFS Module (use IPFS as a module in Node.js or in the Browser)](#ipfs-module)
61+
- [How to create a IPFS node instance](#create-a-ipfs-node-instance)
6162
- [Tutorials and Examples](#tutorials-and-examples)
6263
- [API Docs](#api)
6364
- [Files](#files)
@@ -124,7 +125,7 @@ Inserting one of the above lines will make an `Ipfs` object available in the glo
124125

125126
## Usage
126127

127-
### CLI
128+
### IPFS CLI
128129

129130
The `jsipfs` CLI, available when `js-ipfs` is installed globally, follows(should, it is a WIP) the same interface defined by `go-ipfs`, you can always use the `help` command for help menus.
130131

@@ -150,11 +151,13 @@ Commands:
150151
- default Bootstrap is off, to enable it set `IPFS_BOOTSTRAP=1`
151152

152153

153-
### HTTP-API
154+
### IPFS Daemon
155+
156+
The IPFS Daemon exposes the API defined [`http-api-spec`](https://github.com/ipfs/http-api-spec). You can use any of the IPFS HTTP-API client libraries with it, such as: [js-ipfs-api](https://github.com/ipfs/js-ipfs-api).
154157

155-
The HTTP-API exposed by the js-ipfs daemon follows the [`http-api-spec`](https://github.com/ipfs/http-api-spec). You can use any of the IPFS HTTP-API client libraries with it, such as: [js-ipfs-api](https://github.com/ipfs/js-ipfs-api).
158+
### IPFS Module
156159

157-
### IPFS Core (use IPFS as a module)
160+
Use the IPFS Module as a dependency of a project to spawn in process instances of IPFS.
158161

159162
#### Create a IPFS node instance
160163

@@ -191,14 +194,14 @@ const node = new IPFS({
191194
// init: {
192195
// bits: 1024 // size of the RSA key generated
193196
// },
194-
start: true,
197+
start: true, // default
195198
// start: false,
196199
EXPERIMENTAL: { // enable experimental features
197200
pubsub: true,
198201
sharding: true, // enable dir sharding
199202
dht: true // enable KadDHT, currently not interopable with go-ipfs
200203
},
201-
config: { // overload the default IPFS node config
204+
config: { // overload the default IPFS node config, find defaults at https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime
202205
Addresses: {
203206
Swarm: [
204207
'/ip4/127.0.0.1/tcp/1337'
@@ -322,6 +325,28 @@ A set of data types are exposed directly from the IPFS instance under `ipfs.type
322325

323326
## FAQ
324327

328+
#### How to enable WebRTC support for js-ipfs in the Browser
329+
330+
To add a WebRTC transport to your js-ipfs node, you must add a WebRTC multiaddr. To do that, simple override the config.Addresses.Swarm array which contains all the multiaddrs which the IPFS node will use. See below:
331+
332+
```JavaScript
333+
const node = new IPFS({
334+
config: {
335+
Addresses: {
336+
Swarm: [
337+
'/dns4/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star'
338+
]
339+
}
340+
}
341+
})
342+
343+
node.on('ready', () => {
344+
// your instance with WebRTC is ready
345+
})
346+
```
347+
348+
**Important:** This transport usage is kind of unstable and several users have experienced crashes. Track development of a solution at https://github.com/ipfs/js-ipfs/issues/1088.
349+
325350
#### Is there WebRTC support for js-ipfs with Node.js?
326351

327352
Yes, however, bare in mind that there isn't a 100% stable solution to use WebRTC in Node.js, use it at your own risk. The most tested options are:
@@ -344,7 +369,7 @@ const node = new IPFS({
344369
Swarm: [
345370
"/ip4/0.0.0.0/tcp/4002",
346371
"/ip4/127.0.0.1/tcp/4003/ws",
347-
"/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star"
372+
"/dns4/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star"
348373
]
349374
}
350375
},
@@ -369,15 +394,9 @@ npm install wrtc --global
369394
npm install electron-webrtc --global
370395
```
371396

372-
Then, update your IPFS Daemon config to include the multiaddr for this new transport on the `Addresses.Swarm` array. Add: `"/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star"`
373-
374-
#### I see some slowness when hopping between tabs Chrome with IPFS nodes, is there a reason why?
375-
376-
Yes, unfortunately, due to [Chrome aggressive resource throttling policy](https://github.com/ipfs/js-ipfs/issues/611), it cuts freezes the execution of any background tab, turning an IPFS node that was running on that webpage into a vegetable state.
397+
Then, update your IPFS Daemon config to include the multiaddr for this new transport on the `Addresses.Swarm` array. Add: `"/dns4/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star"`
377398

378-
A way to mitigate this in Chrome, is to run your IPFS node inside a Service Worker, so that the IPFS instance runs in a background process. You can learn how to install an IPFS node as a service worker in here the repo [ipfs-service-worker](https://github.com/ipfs/ipfs-service-worker)
379-
380-
#### How can I configure an IPFS node to use a custom `signaling server`?
399+
#### How can I configure an IPFS node to use a custom `signaling endpoint` for my WebRTC transport?
381400

382401
You'll need to execute a compatible `signaling server` ([libp2p-webrtc-star](https://github.com/libp2p/js-libp2p-webrtc-star) works) and include the correct configuration param for your IPFS node:
383402

@@ -398,6 +417,33 @@ const node = new IPFS({
398417

399418
The code above assumes you are running a local `signaling server` on port `9090`. Provide the correct values accordingly.
400419

420+
#### Is there a more stable alternative to webrtc-star that offers a similar functionality?
421+
422+
Yes, websocket-star! A WebSockets based transport that uses a Relay to route the messages. To enable it, just do:
423+
424+
```JavaScript
425+
const node = new IPFS({
426+
config: {
427+
Addresses: {
428+
Swarm: [
429+
'/dns4/ws-star.discovery.libp2p.io/wss/p2p-websocket-star'
430+
]
431+
}
432+
}
433+
})
434+
435+
node.on('ready', () => {
436+
// your instance with websocket-star is ready
437+
})
438+
```
439+
440+
#### I see some slowness when hopping between tabs Chrome with IPFS nodes, is there a reason why?
441+
442+
Yes, unfortunately, due to [Chrome aggressive resource throttling policy](https://github.com/ipfs/js-ipfs/issues/611), it cuts freezes the execution of any background tab, turning an IPFS node that was running on that webpage into a vegetable state.
443+
444+
A way to mitigate this in Chrome, is to run your IPFS node inside a Service Worker, so that the IPFS instance runs in a background process. You can learn how to install an IPFS node as a service worker in here the repo [ipfs-service-worker](https://github.com/ipfs/ipfs-service-worker)
445+
446+
401447
## Packages
402448

403449
| Package | Version | Deps | DevDeps | Build |

‎examples/exchange-files-in-browser/public/js/app.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ function start () {
3232
if (!node) {
3333
updateView('starting', node)
3434

35-
// DEV: To test with latest js-ipfs
36-
const IPFS = require('ipfs')
37-
node = new IPFS({ repo: 'ipfs-' + Math.random() })
35+
const options = {
36+
repo: 'ipfs-' + Math.random(),
37+
config: {
38+
Addresses: {
39+
Swarm: [
40+
// '/dns4/wrtc-star.discovery.libp2p.io/wss/p2p-webrtc-star'
41+
'/dns4/ws-star.discovery.libp2p.io/wss/p2p-websocket-star'
42+
]
43+
}
44+
}
45+
}
46+
47+
// IFDEV: To test with latest js-ipfs
48+
// const IPFS = require('ipfs')
49+
// node = new IPFS(options)
50+
// VEDIF
3851

3952
// EXAMPLE
40-
// node = new self.Ipfs({ repo: 'ipfs-' + Math.random() })
53+
node = new self.Ipfs(options)
4154

4255
node.once('start', () => node.id((err, id) => {
4356
if (err) { return onError(err) }
@@ -121,7 +134,7 @@ function onDrop (event) {
121134

122135
const files = []
123136
for (let i = 0; i < filesDropped.length; i++) {
124-
files.pUsh(filesDropped[i])
137+
files.push(filesDropped[i])
125138
}
126139

127140
files.forEach((file) => {

‎src/core/runtime/config-browser.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"Addresses": {
33
"Swarm": [
4-
"/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star"
54
],
65
"API": "",
76
"Gateway": ""

0 commit comments

Comments
 (0)
This repository has been archived.