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

docs: update browser ipns publish example #3596

Merged
merged 4 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions examples/browser-ipns-publish/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ <h1 class="aqua fw2 montserrat dib ma0 pv2 ph1 v-mid fr f3 lh-copy">
>
Connect
</button>
<div
class="custom-block callout"
style="font-size: 0.75em; width: 75%; margin: 1em;"
>
For connecting to a local go-ipfs node, you can check its listening address similar to:
<pre>/ip4/127.0.0.1/tcp/4003/ws/p2p/QmTheirServerPeerId</pre>
</div>
</div>

<div class="ph3 mb3">
Expand Down
15 changes: 15 additions & 0 deletions examples/browser-ipns-publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const cryptoKeys = require("human-crypto-keys"); // { getKeyPairFromSeed }
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')

const WS = require('libp2p-websockets')
const transportKey = WS.prototype[Symbol.toStringTag]
const filters = require('libp2p-websockets/src/filters')

const { sleep, Logger, onEnterPress, catchAndLog } = require("./util");

async function main() {
Expand Down Expand Up @@ -39,6 +43,17 @@ async function main() {
ipfsBrowser = await IPFS.create({
pass: "01234567890123456789",
EXPERIMENTAL: { ipnsPubsub: true },
libp2p: {
config: {
transport: {
// This is added for local demo!
// In a production environment the default filter should be used
// where only DNS + WSS addresses will be dialed by websockets in the browser.
[transportKey]: {
filter: filters.all
}
}
}}
});
const { id } = await ipfsBrowser.id();
log(`Browser IPFS ready! Node id: ${id}`);
Expand Down