p2p-graph live demo, made with esnextbin
Last active
April 10, 2018 18:44
-
-
Save roccomuso/6d2ede2438db14c108d30343f352ad8c to your computer and use it in GitHub Desktop.
p2p-graph esnextbin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "p2p-graph-example", | |
"version": "0.0.1", | |
"dependencies": { | |
"faker": "4.1.0", | |
"p2p-graph": "1.2.1" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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