mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Add browser build and examples
This commit is contained in:
parent
2c6d9d7101
commit
4660908636
22
dist/orbitdb.min.js
vendored
Normal file
22
dist/orbitdb.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
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>
|
42
examples/browser.js
Normal file
42
examples/browser.js
Normal file
@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
const ipfsAPI = require('ipfs-api');
|
||||
const Logger = require('logplease');
|
||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false });
|
||||
const OrbitDB = require('../src/Client');
|
||||
|
||||
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);
|
||||
}
|
69416
examples/bundle.js
Normal file
69416
examples/bundle.js
Normal file
File diff suppressed because it is too large
Load Diff
8
examples/index.html
Normal file
8
examples/index.html
Normal file
@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript" src="bundle.js" charset="utf-8"></script>
|
||||
</body>
|
||||
</html>
|
19
package.json
19
package.json
@ -13,20 +13,33 @@
|
||||
},
|
||||
"main": "src/Client.js",
|
||||
"dependencies": {
|
||||
"buffer": "^4.5.1",
|
||||
"ipfs-log": "^1.1.5",
|
||||
"lazy.js": "^0.4.2",
|
||||
"logplease": "^1.2.2",
|
||||
"orbit-common": "^0.2.4",
|
||||
"socket.io-client": "^1.4.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"asyncawait": "^1.0.1",
|
||||
"babel-core": "^6.7.6",
|
||||
"babel-loader": "^6.2.4",
|
||||
"babel-plugin-transform-runtime": "^6.7.5",
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"eslint": "^2.3.0",
|
||||
"ipfs-api": "^3.0.0",
|
||||
"ipfsd-ctl": "^0.10.1",
|
||||
"json-loader": "^0.5.4",
|
||||
"lodash": "^4.3.0",
|
||||
"mocha": "^2.3.4"
|
||||
"logplease": "^1.2.2",
|
||||
"mocha": "^2.4.5",
|
||||
"stream-http": "^2.2.1",
|
||||
"webpack": "^1.12.15"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"lint": "$(npm bin)/eslint ./src || true"
|
||||
"lint": "$(npm bin)/eslint ./src || true",
|
||||
"build": "npm run build:dist && npm run build:examples",
|
||||
"build:dist": "./node_modules/.bin/webpack --config webpack.config.js",
|
||||
"build:examples": "./node_modules/.bin/webpack --config webpack.example.config.js"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const Buffer = require('buffer').Buffer;
|
||||
const Post = require('./BasePost');
|
||||
const TextPost = require('./TextPost');
|
||||
const FilePost = require('./FilePost');
|
||||
|
59
webpack.config.js
Normal file
59
webpack.config.js
Normal file
@ -0,0 +1,59 @@
|
||||
const webpack = require('webpack');
|
||||
|
||||
module.exports = {
|
||||
entry: './src/Client.js',
|
||||
output: {
|
||||
libraryTarget: 'var',
|
||||
library: 'OrbitDB',
|
||||
filename: './dist/orbitdb.min.js'
|
||||
},
|
||||
node: {
|
||||
console: false,
|
||||
process: 'mock',
|
||||
Buffer: 'buffer'
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
mangle: true,
|
||||
compress: { warnings: false }
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
modulesDirectories: [
|
||||
'node_modules'
|
||||
],
|
||||
alias: {
|
||||
fs: require.resolve('./node_modules/logplease/src/fs-mock'),
|
||||
http: 'stream-http',
|
||||
https: 'https-browserify',
|
||||
Buffer: 'buffer'
|
||||
}
|
||||
},
|
||||
module: {
|
||||
loaders: [{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel',
|
||||
query: {
|
||||
presets: ['es2015'],
|
||||
plugins: ['transform-runtime']
|
||||
}
|
||||
}, {
|
||||
test: /\.js$/,
|
||||
include: /node_modules\/(hoek|qs|wreck|boom)/,
|
||||
loader: 'babel',
|
||||
query: {
|
||||
presets: ['es2015'],
|
||||
plugins: ['transform-runtime']
|
||||
}
|
||||
}, {
|
||||
test: /\.json$/,
|
||||
loader: 'json'
|
||||
}]
|
||||
},
|
||||
externals: {
|
||||
net: '{}',
|
||||
tls: '{}',
|
||||
'require-dir': '{}'
|
||||
}
|
||||
};
|
51
webpack.example.config.js
Normal file
51
webpack.example.config.js
Normal file
@ -0,0 +1,51 @@
|
||||
const webpack = require('webpack');
|
||||
|
||||
module.exports = {
|
||||
entry: './examples/browser.js',
|
||||
output: {
|
||||
filename: './examples/bundle.js'
|
||||
},
|
||||
node: {
|
||||
console: false,
|
||||
process: 'mock',
|
||||
Buffer: 'buffer'
|
||||
},
|
||||
resolve: {
|
||||
modulesDirectories: [
|
||||
'node_modules'
|
||||
],
|
||||
alias: {
|
||||
fs: require.resolve('./node_modules/logplease/src/fs-mock'),
|
||||
http: 'stream-http',
|
||||
https: 'https-browserify',
|
||||
Buffer: 'buffer'
|
||||
}
|
||||
},
|
||||
module: {
|
||||
loaders: [{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
loader: 'babel',
|
||||
query: {
|
||||
presets: ['es2015'],
|
||||
plugins: ['transform-runtime']
|
||||
}
|
||||
}, {
|
||||
test: /\.js$/,
|
||||
include: /node_modules\/(hoek|qs|wreck|boom)/,
|
||||
loader: 'babel',
|
||||
query: {
|
||||
presets: ['es2015'],
|
||||
plugins: ['transform-runtime']
|
||||
}
|
||||
}, {
|
||||
test: /\.json$/,
|
||||
loader: 'json'
|
||||
}]
|
||||
},
|
||||
externals: {
|
||||
net: '{}',
|
||||
tls: '{}',
|
||||
'require-dir': '{}'
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user