Add deno-only bootstrap peer implementation. Uses libdatachannel for the RTCDatachannel implementation.
Fix Typescript sourcemap serving PeerManager: more robust when RTCPeerConnection fails or is not present Separate source maps so the main files arent bloated
This commit is contained in:
39
src/App.ts
39
src/App.ts
@@ -60,35 +60,35 @@ class StatusBar {
|
||||
peerStatus = new Map();
|
||||
headless = false;
|
||||
|
||||
setMessageHTML(html:string) {
|
||||
setMessageHTML(html: string) {
|
||||
let statusBarElement = document.getElementById('status_bar');
|
||||
|
||||
if (!statusBarElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
statusBarElement.innerHTML = html;
|
||||
statusBarElement.innerHTML = html;
|
||||
|
||||
}
|
||||
|
||||
setHeadless(headless:boolean) {
|
||||
setHeadless(headless: boolean) {
|
||||
this.headless = headless;
|
||||
}
|
||||
updatePeerMessage(peerID: string, message: string) {
|
||||
this.peerStatus.set(peerID, {message, data:this.peerStatus.get(peerID)?.data});
|
||||
this.peerStatus.set(peerID, { message, data: this.peerStatus.get(peerID)?.data });
|
||||
this.render();
|
||||
}
|
||||
|
||||
updatePeerData(peerID:PeerID, data:any) {
|
||||
this.peerStatus.set(peerID, {message:this.peerStatus.get(peerID)?.message, data:data});
|
||||
updatePeerData(peerID: PeerID, data: any) {
|
||||
this.peerStatus.set(peerID, { message: this.peerStatus.get(peerID)?.message, data: data });
|
||||
}
|
||||
|
||||
updatePeerStatus(peerID:PeerID, message:string="", data={}) {
|
||||
this.peerStatus.set(peerID, {message, data});
|
||||
updatePeerStatus(peerID: PeerID, message: string = "", data = {}) {
|
||||
this.peerStatus.set(peerID, { message, data });
|
||||
this.render();
|
||||
}
|
||||
|
||||
getPeerData(peerID:PeerID) {
|
||||
getPeerData(peerID: PeerID) {
|
||||
let status = this.peerStatus.get(peerID);
|
||||
if (status) {
|
||||
return status.data;
|
||||
@@ -105,8 +105,8 @@ class StatusBar {
|
||||
|
||||
let newStatus = "";
|
||||
for (let [peerID, status] of this.peerStatus.entries()) {
|
||||
let statusBarItem = `<span>(${logID(peerID)} | ${status.message}) </span>`;
|
||||
newStatus += statusBarItem;
|
||||
let statusBarItem = `<span>(${logID(peerID)} | ${status.message}) </span>`;
|
||||
newStatus += statusBarItem;
|
||||
}
|
||||
|
||||
this.setMessageHTML(newStatus);
|
||||
@@ -187,7 +187,7 @@ export class App {
|
||||
if (neededPostIDs.length > 0) {
|
||||
console.log.apply(null, log(`[app] Need (${neededPostIDs.length}) posts for user ${logID(userID)} from peer ${logID(peerID)}`));
|
||||
let neededPostCount = neededPostIDs.length;
|
||||
this.statusBar.updatePeerStatus(peerID, `need(${logID(userID)} | ${neededPostCount})`, {havePostCount:0, neededPostCount:neededPostCount});
|
||||
this.statusBar.updatePeerStatus(peerID, `need(${logID(userID)} | ${neededPostCount})`, { havePostCount: 0, neededPostCount: neededPostCount });
|
||||
|
||||
let neededPosts = await this.peerManager?.rpc.getPostsForUser(peerID, this.peerID, userID, neededPostIDs);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ export class App {
|
||||
this.statusBar.updatePeerStatus(sendingPeerID, `getPostIDs(${logID(userID)})⬆️`);
|
||||
|
||||
let postIDs = await this.peerManager?.rpc.getPostIDsForUser(sendingPeerID, userID);
|
||||
|
||||
|
||||
this.statusBar.updatePeerStatus(sendingPeerID, `syncing(${logID(userID)} ${postIDs.length})`);
|
||||
|
||||
console.log.apply(null, log(`[app] Got (${postIDs.length}) post IDs for user [${logID(userID)}] from peer [${logID(sendingPeerID)}]`));
|
||||
@@ -272,8 +272,9 @@ export class App {
|
||||
}
|
||||
|
||||
let knownUsers = await this.sync.getKnownUsers();
|
||||
this.peerManager.rpc.announceUsers(event.peerID, this.peerID, knownUsers);
|
||||
|
||||
// rpc saying what peers we have
|
||||
this.peerManager.rpc.announceUsers(event.peerID, this.peerID, knownUsers);
|
||||
});
|
||||
|
||||
this.peerManager.addEventListener(PeerEventTypes.PEER_DISCONNECTED, async (event: any) => {
|
||||
@@ -310,7 +311,7 @@ export class App {
|
||||
this.peerManager.registerRPC('getPostsForUser', async (requestingPeerID: string, userID: string, postIDs: string[]) => {
|
||||
let posts = await this.sync.getPostsForUser(userID, postIDs);
|
||||
|
||||
let i=0;
|
||||
let i = 0;
|
||||
for (let post of posts) {
|
||||
console.log.apply(null, log(`[app] sendPostForUser sending post [${logID(post.post_id)}] to [${logID(requestingPeerID)}]`, userID, post.author, post.text));
|
||||
|
||||
@@ -330,7 +331,7 @@ export class App {
|
||||
// if (post.text === "image...") {
|
||||
// debugger;
|
||||
// }
|
||||
|
||||
|
||||
let peerData = this.statusBar.getPeerData(sendingPeerID);
|
||||
if (peerData) {
|
||||
this.statusBar.updatePeerMessage(sendingPeerID, `⬇️${logID(userID)} ${peerData.havePostCount}/${peerData.neededPostCount}}`);
|
||||
@@ -342,7 +343,7 @@ export class App {
|
||||
peerData.havePostCount++
|
||||
this.statusBar.updatePeerMessage(sendingPeerID, `⬇️${logID(userID)} ${peerData.havePostCount}/${peerData.neededPostCount}}`);
|
||||
}
|
||||
|
||||
|
||||
if (this.renderTimer) {
|
||||
clearTimeout(this.renderTimer);
|
||||
}
|
||||
@@ -1198,9 +1199,9 @@ export class App {
|
||||
|
||||
console.log(`[headless]${this.isHeadless} [archive] ${this.isArchivePeer} [bootstrap] ${this.isBootstrapPeer}`);
|
||||
|
||||
|
||||
|
||||
this.statusBar.setHeadless(this.isHeadless);
|
||||
|
||||
|
||||
|
||||
let limitPostsParam = urlParams.get('limitPosts');
|
||||
if (limitPostsParam) {
|
||||
|
||||
Reference in New Issue
Block a user