Announce users the local peers knows to remote peers when they connect. Fix RPC system to correctly serialize and multiple params. Add detailed logging for rpc calls.
This commit is contained in:
@@ -555,6 +555,7 @@ class App {
|
||||
this.connectURL = "";
|
||||
this.firstRun = false;
|
||||
this.peerManager = null;
|
||||
this.sync = new Sync();
|
||||
this.time = 0;
|
||||
this.animals = ['shrew', 'jerboa', 'lemur', 'weasel', 'possum', 'possum', 'marmoset', 'planigale', 'mole', 'narwhal'];
|
||||
this.adjectives = ['snazzy', 'whimsical', 'jazzy', 'bonkers', 'wobbly', 'spiffy', 'chirpy', 'zesty', 'bubbly', 'perky', 'sassy'];
|
||||
@@ -573,11 +574,22 @@ class App {
|
||||
}
|
||||
async connect() {
|
||||
this.peerManager = new PeerManager(this.userID, this.peerID, this.isBootstrapPeer);
|
||||
if (this.peerManager === null) {
|
||||
throw new Error();
|
||||
}
|
||||
this.registerRPCs();
|
||||
this.peerManager.addEventListener(PeerEventTypes.PEER_CONNECTED, (event) => {
|
||||
this.peerManager.addEventListener(PeerEventTypes.PEER_CONNECTED, async (event) => {
|
||||
if (!this.peerManager) {
|
||||
throw new Error();
|
||||
}
|
||||
console.log.apply(null, log(`[app]: peer connected:${event.peerID}`));
|
||||
let knownUsers = await this.sync.getKnownUsers();
|
||||
this.peerManager.rpc.announceUsers(event.peerID, this.peerID, knownUsers);
|
||||
// rpc saying what peers we have
|
||||
});
|
||||
this.peerManager.addEventListener(PeerEventTypes.PEER_DISCONNECTED, async (event) => {
|
||||
console.log.apply(null, log(`[app]: peer disconnected:${event.peerID}`));
|
||||
});
|
||||
console.log.apply(null, log("*************** before peerManager.connect"));
|
||||
// We use promises here to only return from this call once we're connected to the boostrap peer
|
||||
// and the datachannel is open.
|
||||
@@ -585,11 +597,18 @@ class App {
|
||||
// we could return progress information as we connect and have the app subscribe to that?
|
||||
// Would be lovely to show a little display of peers connecting, whether you're connected directly to a friend's peer etc.
|
||||
// Basically that live "dandelion" display.
|
||||
this.peerManager.registerRPC('announceUsers', (sendingPeerID, userIDs) => {
|
||||
console.log.apply(null, log(`announceUsers from ${sendingPeerID}`, userIDs));
|
||||
for (let userID of userIDs) {
|
||||
console.log.apply(null, log(`[app] announceUsers, got user:${userID} from peer ${sendingPeerID}`));
|
||||
}
|
||||
});
|
||||
this.peerManager.registerRPC('getPeersForUser', (userID) => {
|
||||
return [1, 2, 3, 4, 5];
|
||||
});
|
||||
this.peerManager.registerRPC('getPostIDsForUser', (userID) => {
|
||||
return [1, 2, 3, 4, 5];
|
||||
let postIDs = this.sync.getPostIdsForUser(userID);
|
||||
return postIDs;
|
||||
});
|
||||
await this.peerManager.connect();
|
||||
console.log.apply(null, log("*************** after peerManager.connect"));
|
||||
@@ -597,11 +616,11 @@ class App {
|
||||
if (this.isBootstrapPeer) {
|
||||
return;
|
||||
}
|
||||
let usersToSync = await Sync.getFollowing(this.userID);
|
||||
for (let userID of usersToSync) {
|
||||
console.log(userID);
|
||||
// this.peerManager.rpc.getPeersForUser(userID);
|
||||
}
|
||||
// let usersToSync = await Sync.getFollowing(this.userID);
|
||||
// for (let userID of usersToSync) {
|
||||
// console.log(userID);
|
||||
// // this.peerManager.rpc.getPeersForUser(userID);
|
||||
// }
|
||||
// for (let userID in this.sync.usersToSync()) {
|
||||
// let peers = await this.peerManager.rpc.getPeersForUser(userID);
|
||||
// for (let peer in peers) {
|
||||
@@ -616,8 +635,8 @@ class App {
|
||||
// this.render();
|
||||
// }
|
||||
// }
|
||||
let postIDs = await this.peerManager.rpc.getPostIDsForUser(this.peerManager.bootstrapPeerID, this.userID);
|
||||
console.log.apply(null, log("peerManager.rpc.getPostIDsForUser", postIDs));
|
||||
// let postIDs = await this.peerManager.rpc.getPostIDsForUser(this.peerManager.bootstrapPeerID, this.userID);
|
||||
// console.log.apply(null, log("peerManager.rpc.getPostIDsForUser", postIDs));
|
||||
}
|
||||
getPreferentialUserID() {
|
||||
return this.router.userID.length !== 0 ? this.router.userID : this.userID;
|
||||
@@ -1238,6 +1257,7 @@ class App {
|
||||
this.peername = this.getPeername();
|
||||
this.userID = this.getUserID();
|
||||
this.username = this.getUsername();
|
||||
this.sync.setUserID(this.userID);
|
||||
this.connect();
|
||||
// this.registerRPCs();
|
||||
// this.testPeerManager();
|
||||
|
||||
Reference in New Issue
Block a user