48 lines
1.7 KiB
HTML
48 lines
1.7 KiB
HTML
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
</head>
|
|
<body>
|
|
<div id="result">Loading...</div>
|
|
|
|
<script type="text/javascript" src="../../dist/orbitdb.min.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">
|
|
const network = '178.62.241.75:3333'
|
|
const username = 'user1'
|
|
const password = ''
|
|
const channel = 'browsertest2.dist'
|
|
const key = 'greeting'
|
|
const value = 'Hello world'
|
|
|
|
const elm = document.getElementById("result")
|
|
const ipfs = new window.Ipfs()
|
|
OrbitDB.connect(network, username, password, ipfs).then((orbit) => {
|
|
orbit.kvstore(channel).then((db) => {
|
|
let count = 1
|
|
const query = () => {
|
|
const startTime = new Date().getTime()
|
|
db.put(key, value + " " + count).then((res) => {
|
|
const endTime = new Date().getTime()
|
|
console.log(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
|
|
count ++
|
|
|
|
const result = db.get(key)
|
|
const output = `
|
|
---------------------------------------------------
|
|
Key | Value
|
|
---------------------------------------------------
|
|
${key} | ${result}
|
|
---------------------------------------------------`
|
|
|
|
elm.innerHTML = output.split("\n").join("<br>")
|
|
console.log(output)
|
|
}).catch((e) => console.error(e))
|
|
};
|
|
setInterval(query, 1000)
|
|
}).catch((e) => console.error(e))
|
|
}).catch((e) => console.error(e))
|
|
</script>
|
|
</body>
|
|
</html>
|