fix browser examples

This commit is contained in:
anders
2020-12-09 18:42:27 -06:00
committed by Mark Robert Henderson
parent aafa7e3483
commit 2ca2604474
4 changed files with 17 additions and 15 deletions

View File

@@ -6,8 +6,8 @@
but we inject the Node.js modules of OrbitDB and IPFS into
the example.
In the html example, IPFS and OrbitDB are loaded from the
minified distribution builds (in '../lib')
In the html example, IPFS and OrbitDB are loaded by ../browser.html from the
minified distribution builds
*/
// Import IPFS module

View File

@@ -52,7 +52,7 @@
<div id="writerText"></div>
<script type="text/javascript" src="../../dist/orbitdb.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript" src="example.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
// Start the example

View File

@@ -22,7 +22,7 @@ function handleError(e) {
statusElm.innerHTML = e.message
}
const main = (IPFS, ORBITDB) => {
const main = async (IPFS, ORBITDB) => {
let orbitdb, db
let count = 0
let interval = Math.floor((Math.random() * 300) + (Math.random() * 2000))
@@ -45,7 +45,7 @@ const main = (IPFS, ORBITDB) => {
statusElm.innerHTML = "Starting IPFS..."
// Create IPFS instance
const ipfs = new Ipfs({
const ipfs = await Ipfs.create({
repo: '/orbitdb/examples/browser/new/ipfs/0.33.1',
start: true,
preload: {
@@ -59,21 +59,23 @@ const main = (IPFS, ORBITDB) => {
Swarm: [
// Use IPFS dev signal server
// '/dns4/star-signal.cloud.ipfs.team/wss/p2p-webrtc-star',
'/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
// Use IPFS dev webrtc signal server
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star/',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star/',
'/dns4/webrtc-star.discovery.libp2p.io/tcp/443/wss/p2p-webrtc-star/',
// Use local signal server
// '/ip4/0.0.0.0/tcp/9090/wss/p2p-webrtc-star',
]
},
}
})
window.ipfs = ipfs
ipfs.on('error', (e) => handleError(e))
ipfs.on('ready', async () => {
openButton.disabled = false
createButton.disabled = false
statusElm.innerHTML = "IPFS Started"
orbitdb = await OrbitDB.createInstance(ipfs)
})
openButton.disabled = false
createButton.disabled = false
statusElm.innerHTML = "IPFS Started"
orbitdb = await OrbitDB.createInstance(ipfs)
const load = async (db, statusText) => {
// Set the status text

View File

@@ -80,8 +80,8 @@
"test:browser-multiple-tabs": "npm run build:dist && cpy dist/orbitdb.min.js ./test/browser --rename=orbitdb.js && cpy node_modules/ipfs/dist/index.min.js ./test/browser --rename=ipfs.js && cpy node_modules/orbit-db-identity-provider/dist/index-browser.min.js ./test/browser --rename=identities.js && cpy node_modules/ipfs-log/dist/ipfslog.min.js ./test/browser && mocha ./test/browser/concurrent.spec.js",
"build": "npm run build:es5 && npm run build:debug && npm run build:dist && npm run build:examples && npm run build:docs/toc",
"build:examples": "webpack --config conf/webpack.example.config.js --sort-modules-by size",
"build:dist": "webpack --config conf/webpack.config.js --sort-modules-by size && mkdirp examples/browser/lib && cpy dist/orbitdb.min.js examples/browser/lib",
"build:debug": "webpack --config conf/webpack.debug.config.js --sort-modules-by size && mkdirp examples/browser/lib && cpy dist/orbitdb.js examples/browser/lib && cpy dist/orbitdb.js.map examples/browser/lib",
"build:dist": "webpack --config conf/webpack.config.js --sort-modules-by size",
"build:debug": "webpack --config conf/webpack.debug.config.js --sort-modules-by size",
"build:docs/toc": "markdown-toc --no-first1 -i README.md && markdown-toc --no-first1 -i API.md && markdown-toc --no-first1 -i GUIDE.md && markdown-toc --no-first1 -i CHANGELOG.md && markdown-toc --no-first1 -i FAQ.md ",
"build:es5": "babel src --out-dir ./dist/es5/ --presets babel-preset-env --plugins babel-plugin-transform-runtime",
"release": "npm run build && npm publish"