mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Update examples
This commit is contained in:
parent
be277a59c9
commit
73300cdcde
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ node_modules/
|
||||
dump.rdb
|
||||
Vagrantfile
|
||||
orbit-db-cache.json
|
||||
examples/browser/bundle.js
|
@ -1,43 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="../dist/orbitdb.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="../node_modules/logplease/dist/logplease.min.js" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="../node_modules/ipfs-api/dist/index.min.js" charset="utf-8"></script>
|
||||
<script type="text/javascript">
|
||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false });
|
||||
const network = 'QmZjhqUtFK3aWbUfjYEsgS8CMK8fZrQXqUcqW5Q32LznMk'; // 'localhost:3333'
|
||||
const username = 'user1';
|
||||
const password = '';
|
||||
const channel = 'browsertest2.dist';
|
||||
const key = 'greeting';
|
||||
const value = 'Hello world';
|
||||
|
||||
const ipfs = IpfsApi();
|
||||
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();
|
||||
logger.debug(`db.put (#${count}) took ${(endTime - startTime)} ms\n`);
|
||||
count ++;
|
||||
|
||||
const result = db.get(key);
|
||||
logger.debug("---------------------------------------------------")
|
||||
logger.debug("Key | Value")
|
||||
logger.debug("---------------------------------------------------")
|
||||
logger.debug(`${key} | ${result}`);
|
||||
logger.debug("---------------------------------------------------")
|
||||
console.log('\n');
|
||||
}).catch((e) => logger.error(e));
|
||||
};
|
||||
setInterval(query, 1000);
|
||||
}).catch((e) => logger.error(e));
|
||||
}).catch((e) => logger.error(e));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,42 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// const IpfsApi = require('ipfs-api');
|
||||
const IPFS = require('exports?Ipfs!ipfs/dist/index.js')
|
||||
const Logger = require('logplease');
|
||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false });
|
||||
const OrbitDB = require('../src/OrbitDB');
|
||||
|
||||
const network = 'QmYPobvobKsyoCKTw476yTui611XABf927KxUPCf4gRLRr'; // 'localhost:3333'
|
||||
const username = 'user1';
|
||||
const password = '';
|
||||
const channel = 'browsertest1';
|
||||
const key = 'greeting';
|
||||
const value = 'Hello world';
|
||||
|
||||
try {
|
||||
const ipfs = new 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();
|
||||
logger.debug(`db.put (#${count}) took ${(endTime - startTime)} ms\n`);
|
||||
count ++;
|
||||
|
||||
const result = db.get(key);
|
||||
logger.debug("---------------------------------------------------")
|
||||
logger.debug("Key | Value")
|
||||
logger.debug("---------------------------------------------------")
|
||||
logger.debug(`${key} | ${result}`);
|
||||
logger.debug("---------------------------------------------------")
|
||||
console.log('\n');
|
||||
}).catch((e) => logger.error(e.stack));
|
||||
};
|
||||
setInterval(query, 1000);
|
||||
});
|
||||
});
|
||||
} catch(e) {
|
||||
logger.error(e.stack);
|
||||
}
|
49
examples/browser/browser.html
Normal file
49
examples/browser/browser.html
Normal file
@ -0,0 +1,49 @@
|
||||
<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/logplease/dist/logplease.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 logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false })
|
||||
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()
|
||||
logger.debug(`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>")
|
||||
logger.debug(output)
|
||||
}).catch((e) => logger.error(e))
|
||||
};
|
||||
setInterval(query, 1000)
|
||||
}).catch((e) => logger.error(e))
|
||||
}).catch((e) => logger.error(e))
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
45
examples/browser/browser.js
Normal file
45
examples/browser/browser.js
Normal file
@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
const IPFS = require('exports?Ipfs!ipfs/dist/index.js')
|
||||
const Logger = require('logplease')
|
||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false })
|
||||
const OrbitDB = require('../../src/OrbitDB')
|
||||
|
||||
const network = '178.62.241.75:3333'
|
||||
const username = 'user1'
|
||||
const password = ''
|
||||
const channel = 'browsertest1'
|
||||
const key = 'greeting'
|
||||
const value = 'Hello world'
|
||||
|
||||
try {
|
||||
const elm = document.getElementById("result")
|
||||
const ipfs = new 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()
|
||||
logger.debug(`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>")
|
||||
logger.debug(output)
|
||||
}).catch((e) => logger.error(e.stack))
|
||||
}
|
||||
setInterval(query, 1000)
|
||||
})
|
||||
})
|
||||
} catch(e) {
|
||||
logger.error(e.stack)
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div id="result">Loading...</div>
|
||||
<script type="text/javascript" src="bundle.js" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
178491
examples/bundle.js
178491
examples/bundle.js
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user