mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
44 lines
1.9 KiB
HTML
44 lines
1.9 KiB
HTML
<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>
|