mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Add browser build and examples
This commit is contained in:
48
examples/browser.html
Normal file
48
examples/browser.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<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-api/dist/ipfsapi.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 host = '178.62.241.75'
|
||||
const port = 3333;
|
||||
const username = 'user1';
|
||||
const password = '';
|
||||
const channel = 'testing123';
|
||||
const key = 'greeting';
|
||||
const value = 'Hello world';
|
||||
|
||||
try {
|
||||
const ipfs = ipfsAPI();
|
||||
OrbitDB.connect(host, port, username, password, ipfs).then((orbit) => {
|
||||
orbit.channel(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.stack);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user