Skip to content

Instantly share code, notes, and snippets.

@roccomuso
Last active April 10, 2018 18:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roccomuso/6d2ede2438db14c108d30343f352ad8c to your computer and use it in GitHub Desktop.
Save roccomuso/6d2ede2438db14c108d30343f352ad8c to your computer and use it in GitHub Desktop.
p2p-graph esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
<style>
body{
background-color: #7f7a7a;
};
</style>
</head>
<body>
<!-- put markup and other contents here -->
<div class="root">
</div>
</body>
</html>
// Press "Execute" to run your program
var faker = require('faker')
var Graph = require('p2p-graph')
var graph = new Graph('.root')
// select event
graph.on('select', function (id) {
console.log(id + ' selected!')
})
// Add main peer
graph.add({
id: 'me',
me: true,
name: 'You'
})
for (let i = 0; i<10; i++){
// add peers
graph.add({
id: 'peer'+i,
name: faker.internet.ip()
})
// connect them
graph.connect('me', 'peer'+i)
}
{
"name": "p2p-graph-example",
"version": "0.0.1",
"dependencies": {
"faker": "4.1.0",
"p2p-graph": "1.2.1"
}
}
'use strict';
// Press "Execute" to run your program
var faker = require('faker');
var Graph = require('p2p-graph');
var graph = new Graph('.root');
// on click event listener
graph.on('select', function (id) {
console.log(id + ' selected!')
})
// Add main peer
graph.add({
id: 'me',
me: true,
name: 'You'
});
for (var i = 0; i < 10; i++) {
// add peers
graph.add({
id: 'peer' + i,
name: faker.internet.ip()
});
// connect them
graph.connect('me', 'peer' + i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment