1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00
This commit is contained in:
Enrico Fasoli 2015-11-19 12:59:19 +01:00
parent 65375896be
commit acd05deb15
2 changed files with 27 additions and 13 deletions

View File

@ -8,15 +8,21 @@ Needs to be browserified to work in the browser
// EventEmitter used to communicate with clients // EventEmitter used to communicate with clients
var EventEmitter = require('wolfy87-eventemitter') var EventEmitter = require('wolfy87-eventemitter')
var asyncjs = require('async')
function asObj(str,done){ function asObj(str,done){
if(typeof str === 'string'){
var obj var obj
try { try {
obj = JSON.parse(str) obj = JSON.parse(str)
} catch (e) { } catch (e) {
console.log('error parsing:',str,'Error:',e)
return done(e,null) return done(e,null)
} }
done(null,obj) done(null,obj)
} else {
done(null,str)
}
} }
function replyAsObj(res,isJson,done){ function replyAsObj(res,isJson,done){
@ -136,17 +142,22 @@ BoardsAPI.prototype.searchUsers = function(){
this.ipfs.swarm.peers((err,r) => { this.ipfs.swarm.peers((err,r) => {
if(err) return console.log(err) if(err) return console.log(err)
replyAsObj(r,true,(e,reply) => { replyAsObj(r,true,(e,reply) => {
if(e){
this.ee.emit('error',e)
return console.log('There was an error while getting swarm peers:',e)
}
console.log('Checking',reply.Strings.length,'peers') console.log('Checking',reply.Strings.length,'peers')
reply.Strings.forEach(item => { //reply.Strings.forEach(item => {
var f = (item, done) => {
var ss = item.split('/') var ss = item.split('/')
var n = ss[ss.length-1] var n = ss[ss.length-1]
this.ee.once(n,(res,err) => done(err))
this.resolveIPNS(n) this.resolveIPNS(n)
}) }
asyncjs.eachSeries(reply.Strings,f.bind(this))
}) })
}) })
// Look for who has the correct version file, they probably have a profile // Look for who has the correct version file, they probably have a profile
// Disabled at the moment
/*
this.ipfs.dht.findprovs(this.version_hash, (err,res) => { this.ipfs.dht.findprovs(this.version_hash, (err,res) => {
if(err){ if(err){
console.log('DHT FINDPROVS err',err) console.log('DHT FINDPROVS err',err)
@ -156,7 +167,6 @@ BoardsAPI.prototype.searchUsers = function(){
console.log('DHT FINDPROVS string',res) console.log('DHT FINDPROVS string',res)
} }
}) })
*/
return this.ee return this.ee
} }
@ -362,4 +372,8 @@ BoardsAPI.prototype.getEventEmitter = function(){
return this.ee return this.ee
} }
BoardsAPI.prototype.getUsers = function(){
return Object.keys(this.users)
}
module.exports = BoardsAPI module.exports = BoardsAPI

View File

@ -258,7 +258,7 @@ var Board = React.createClass({
var Users = React.createClass({ var Users = React.createClass({
getInitialState: function(){ getInitialState: function(){
return { users: [ boards.id ] } return { users: boards.getUsers() }
}, },
componentDidMount: function(){ componentDidMount: function(){
boards.searchUsers().on('user',(id) => { boards.searchUsers().on('user',(id) => {
@ -269,7 +269,7 @@ var Users = React.createClass({
render: function(){ render: function(){
return <div> return <div>
<h1><Icon name="users" /> Users</h1> <h1><Icon name="users" /> Users</h1>
<p>Found <b>{this.state.users.length}</b> users, looking for more...</p> <p>Found <b>{this.state.users.length}</b> users</p>
<ul> <ul>
{this.state.users.map(user => { {this.state.users.map(user => {
return <UserID key={user} id={user} /> return <UserID key={user} id={user} />