fix logging console function names. Attempt to connect to initial peers
This commit is contained in:
182
src/main2.ts
182
src/main2.ts
@@ -116,7 +116,7 @@ function logID(ID: string) {
|
||||
|
||||
|
||||
// function log(message:string) {
|
||||
// console.log(message);
|
||||
// console.log.apply(null, log(message);
|
||||
// let log = document.getElementById("log");
|
||||
// let newlog = document.createElement('span');
|
||||
// newlog.innerHTML = `<pre>${message}</pre>`;
|
||||
@@ -175,8 +175,8 @@ window.addEventListener('scroll', () => {
|
||||
|
||||
// Check if scrolled to bottom
|
||||
if (scrollPoint >= totalPageHeight) {
|
||||
console.log('Scrolled to the bottom!');
|
||||
console.log(scrollPoint, totalPageHeight);
|
||||
console.log.apply(null, log('Scrolled to the bottom!'));
|
||||
console.log.apply(null, log(scrollPoint, totalPageHeight));
|
||||
}
|
||||
|
||||
});
|
||||
@@ -268,20 +268,20 @@ interface PeerMessage {
|
||||
// try {
|
||||
// this.websocket = new WebSocket(`wss://${window.location.hostname}:${window.location.port}/ws`);
|
||||
// } catch (error: any) {
|
||||
// console.log(error.message);
|
||||
// console.log.apply(null, log(error.message);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// this.websocket.onopen = async (event) => {
|
||||
// log("ws:connected");
|
||||
// console.log.apply(null, log("ws:connected"));;
|
||||
// await this.sendHello();
|
||||
|
||||
// // If we're running as a headless peer, send a hello message every N seconds to refresh the posts we have.
|
||||
// let helloRefreshIntervalPeriod = 120;
|
||||
// if (app.isHeadless) {
|
||||
// console.log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// console.log.apply(null, log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// this.helloRefreshInterval = window.setInterval(() => {
|
||||
// console.log("wsConnection: Hello refresh.")
|
||||
// console.log.apply(null, log("wsConnection: Hello refresh.")
|
||||
|
||||
// if (!navigator.onLine) {
|
||||
// return;
|
||||
@@ -299,9 +299,9 @@ interface PeerMessage {
|
||||
// };
|
||||
|
||||
// this.websocket.onclose = (event) => {
|
||||
// log("ws:disconnected");
|
||||
// console.log.apply(null, log("ws:disconnected"));;
|
||||
// // this.retry *= 2;
|
||||
// log(`Retrying in ${this.retry} seconds`);
|
||||
// console.log.apply(null, log(`Retrying in ${this.retry} seconds`));;
|
||||
// window.setTimeout(() => { this.connect(); }, this.retry * 1000);
|
||||
// };
|
||||
|
||||
@@ -322,7 +322,7 @@ interface PeerMessage {
|
||||
// };
|
||||
|
||||
// this.websocket.onerror = (event) => {
|
||||
// log('ws:error: ' + event);
|
||||
// console.log.apply(null, log('ws:error: ' + event));;
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
@@ -403,9 +403,9 @@ class wsConnection {
|
||||
let json = ""
|
||||
try {
|
||||
json = JSON.stringify(message);
|
||||
// console.log("*******", (await compressString(json)).byteLength, json.length);
|
||||
// console.log.apply(null, log("*******", (await compressString(json)).byteLength, json.length);
|
||||
} catch (e) {
|
||||
console.log(e, "wsConnection send: Couldn't serialize message", message);
|
||||
console.log.apply(null, log(e, "wsConnection send: Couldn't serialize message", message));
|
||||
}
|
||||
// log(`ws->${json.slice(0, 240)}`)
|
||||
this.websocket!.send(json);
|
||||
@@ -418,7 +418,7 @@ class wsConnection {
|
||||
|
||||
async sendWebRTCDescription(description: RTCSessionDescription | null) {
|
||||
|
||||
console.log("description:", description);
|
||||
console.log.apply(null, log("description:", description));
|
||||
this.send({ type: "rtc_session_description", description: description });
|
||||
}
|
||||
|
||||
@@ -426,19 +426,19 @@ class wsConnection {
|
||||
// log(`getPostsForUserResponse: ${data}`)
|
||||
|
||||
let message = data.message;
|
||||
log(`Net: got ${message.post_ids.length} post IDs for user ${logID(message.user_id)} from peer ${logID(data.from)}`);
|
||||
console.log.apply(null, log(`Net: got ${message.post_ids.length} post IDs for user ${logID(message.user_id)} from peer ${logID(data.from)}`));;
|
||||
|
||||
|
||||
let startTime = app.timerStart();
|
||||
let postIds = await checkPostIds(message.user_id, message.post_ids);
|
||||
log(`ID Check for user ${logID(message.user_id)} took ${app.timerDelta().toFixed(2)}ms`);
|
||||
log(`Need ${postIds.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`);
|
||||
console.log.apply(null, log(`ID Check for user ${logID(message.user_id)} took ${app.timerDelta().toFixed(2)}ms`));;
|
||||
console.log.apply(null, log(`Need ${postIds.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`));;
|
||||
|
||||
if (postIds.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
log(`Net: Req ${postIds.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`)
|
||||
console.log.apply(null, log(`Net: Req ${postIds.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`));
|
||||
let responseMessage = { type: "peer_message", from: app.peerID, to: data.from, from_username: app.username, from_peername: app.peername, message: { type: "get_posts_for_user", post_ids: postIds, user_id: message.user_id } }
|
||||
|
||||
this.send(responseMessage);
|
||||
@@ -472,10 +472,10 @@ class wsConnection {
|
||||
let postIds = await getAllIds(message.user_id) ?? [];
|
||||
postIds = postIds.filter((postID: string) => !this.postBlockList.has(postID));
|
||||
if (postIds.length === 0) {
|
||||
log(`Net: I know about user ${logID(message.user_id)} but I have 0 posts, so I'm not sending any to to peer ${logID(data.from)}`);
|
||||
console.log.apply(null, log(`Net: I know about user ${logID(message.user_id)} but I have 0 posts, so I'm not sending any to to peer ${logID(data.from)}`));;
|
||||
return;
|
||||
}
|
||||
log(`Net: Sending ${postIds.length} post Ids for user ${logID(message.user_id)} to peer ${logID(data.from)}`)
|
||||
console.log.apply(null, log(`Net: Sending ${postIds.length} post Ids for user ${logID(message.user_id)} to peer ${logID(data.from)}`));
|
||||
|
||||
let responseMessage = { type: "peer_message", from: app.peerID, to: data.from, from_username: app.username, from_peername: app.peername, message: { type: "get_post_ids_for_user_response", post_ids: postIds, user_id: message.user_id } }
|
||||
this.send(responseMessage);
|
||||
@@ -489,7 +489,7 @@ class wsConnection {
|
||||
}
|
||||
|
||||
for (let [peerID, peerInfo] of this.seenPeers.entries()) {
|
||||
log(`broadcastNewPost: sending new post to ${logID(peerID)}:${peerInfo.peerName}:${peerInfo.userName}`);
|
||||
console.log.apply(null, log(`broadcastNewPost: sending new post to ${logID(peerID)}:${peerInfo.peerName}:${peerInfo.userName}`));;
|
||||
|
||||
this.sendPostsForUser(peerID, app.userID, [newPost])
|
||||
}
|
||||
@@ -519,18 +519,18 @@ class wsConnection {
|
||||
let message = data.message;
|
||||
let posts = await getPostsByIds(message.user_id, message.post_ids) ?? [];
|
||||
|
||||
log(`Net: Sending ${posts.length} posts for user ${logID(message.user_id)} to peer ${logID(data.from)}`);
|
||||
console.log.apply(null, log(`Net: Sending ${posts.length} posts for user ${logID(message.user_id)} to peer ${logID(data.from)}`));;
|
||||
|
||||
app.timerStart();
|
||||
let output = [];
|
||||
|
||||
console.log("Serializing images");
|
||||
console.log.apply(null, log("Serializing images"));
|
||||
for (let post of posts) {
|
||||
let newPost = (post as any).data;
|
||||
|
||||
if (newPost.image_data) {
|
||||
// let compressedData = await wsConnection.compressArrayBuffer(newPost.image_data);
|
||||
// console.log((newPost.image_data.byteLength - compressedData.byteLength) / 1024 / 1024);
|
||||
// console.log.apply(null, log((newPost.image_data.byteLength - compressedData.byteLength) / 1024 / 1024);
|
||||
|
||||
// TODO don't do this, use Blobs direclty!
|
||||
// https://developer.chrome.com/blog/blob-support-for-Indexeddb-landed-on-chrome-dev
|
||||
@@ -540,16 +540,16 @@ class wsConnection {
|
||||
}
|
||||
|
||||
// let megs = JSON.stringify(newPost).length/1024/1024;
|
||||
// console.log(`getPostsForUserHandler id:${newPost.post_id} post length:${megs}`);
|
||||
// console.log.apply(null, log(`getPostsForUserHandler id:${newPost.post_id} post length:${megs}`);
|
||||
output.push(newPost);
|
||||
}
|
||||
|
||||
let responseMessage = { type: "peer_message", from: app.peerID, to: data.from, from_username: app.username, from_peername: app.peername, message: { type: "get_posts_for_user_response", posts: output, user_id: message.user_id } }
|
||||
|
||||
console.log("Sending posts");
|
||||
console.log.apply(null, log("Sending posts"));
|
||||
await this.sendPostsForUser(data.from, message.user_id, output);
|
||||
let sendTime = app.timerDelta();
|
||||
log(`getPostsForUserHandler send took: ${sendTime.toFixed(2)}ms`);
|
||||
console.log.apply(null, log(`getPostsForUserHandler send took: ${sendTime.toFixed(2)}ms`));;
|
||||
|
||||
}
|
||||
|
||||
@@ -559,13 +559,13 @@ class wsConnection {
|
||||
async getPostsForUserReponseHandler(data: any) {
|
||||
app.timerStart();
|
||||
let message = data.message;
|
||||
console.log(`Net: got ${message.posts.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`);
|
||||
console.log.apply(null, log(`Net: got ${message.posts.length} posts for user ${logID(message.user_id)} from peer ${logID(data.from)}`));
|
||||
for (let post of message.posts) {
|
||||
|
||||
// HACK: Some posts have insanely large images, so I'm gonna skip them.
|
||||
// Once we support delete then we we could delete these posts in a sensible way.
|
||||
if (this.postBlockList.has(post.post_id)) {
|
||||
log(`Skipping blocked post: ${post.post_id}`);
|
||||
console.log.apply(null, log(`Skipping blocked post: ${post.post_id}`));;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -579,12 +579,12 @@ class wsConnection {
|
||||
post.image_data = await base64ToArrayBuffer(post.image_data);
|
||||
}
|
||||
}
|
||||
console.log(`Merging same user peer posts...`)
|
||||
console.log.apply(null, log(`Merging same user peer posts...`));
|
||||
await mergeDataArray(message.user_id, data.message.posts);
|
||||
|
||||
let receiveTime = app.timerDelta();
|
||||
|
||||
log(`getPostsForUserReponseHandler receive took: ${receiveTime.toFixed(2)}ms`);
|
||||
console.log.apply(null, log(`getPostsForUserReponseHandler receive took: ${receiveTime.toFixed(2)}ms`));;
|
||||
|
||||
|
||||
if (message.user_id === app.getPreferentialUserID() || app.following.has(message.user_id)) {
|
||||
@@ -644,7 +644,7 @@ class wsConnection {
|
||||
.filter(userID => !this.userBlockList.has(userID))
|
||||
.filter(async userID => (await getAllIds(userID)).length > 0); // TODO:EASYOPT getting all the IDs is unecessary, replace it with a test to get a single ID.
|
||||
|
||||
console.log('Net: Sending known users', knownUsers.map(userID => logID(userID ?? "")));
|
||||
console.log.apply(null, log('Net: Sending known users', knownUsers.map(userID => logID(userID ?? ""))));
|
||||
return await this.send({ type: "hello", user_id: this.userID, user_name: app.username, peer_id: this.peerID, peer_name: app.peername, known_users: knownUsers });
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ class wsConnection {
|
||||
|
||||
let users = [];
|
||||
let receivedUsers = Object.entries(data.userPeers);
|
||||
log(`Net: got ${receivedUsers.length} users from bootstrap peer.`)
|
||||
console.log.apply(null, log(`Net: got ${receivedUsers.length} users from bootstrap peer.`));
|
||||
|
||||
try {
|
||||
let preferentialUserID = app.getPreferentialUserID();
|
||||
@@ -664,7 +664,7 @@ class wsConnection {
|
||||
users.push([preferentialUserID, currentUserPeers]);
|
||||
delete data.userPeers[preferentialUserID];
|
||||
} catch (e) {
|
||||
console.log('helloResponseHandler', e);
|
||||
console.log.apply(null, log('helloResponseHandler', e));
|
||||
}
|
||||
|
||||
let getAllUsers = app.router.route !== App.Route.USER
|
||||
@@ -676,7 +676,7 @@ class wsConnection {
|
||||
|
||||
for (let [userID, peerIDs] of users) {
|
||||
if (this.userBlockList.has(userID)) {
|
||||
console.log("Skipping user on blocklist:", userID)
|
||||
console.log.apply(null, log("Skipping user on blocklist:", userID));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -687,7 +687,7 @@ class wsConnection {
|
||||
continue;
|
||||
}
|
||||
|
||||
log(`Net: Req post IDs for user ${logID(userID)} from peer ${logID(peerID)}`);
|
||||
console.log.apply(null, log(`Net: Req post IDs for user ${logID(userID)} from peer ${logID(peerID)}`));;
|
||||
this.send({
|
||||
type: "peer_message",
|
||||
from: this.peerID,
|
||||
@@ -711,20 +711,20 @@ class wsConnection {
|
||||
try {
|
||||
this.websocket = new WebSocket(`wss://${window.location.hostname}:${window.location.port}/ws`);
|
||||
} catch (error: any) {
|
||||
console.log(error.message);
|
||||
console.log.apply(null, log(error.message));
|
||||
return;
|
||||
}
|
||||
|
||||
this.websocket.onopen = async (event) => {
|
||||
log("ws:connected");
|
||||
console.log.apply(null, log("ws:connected"));;
|
||||
await this.sendHello2();
|
||||
|
||||
// If we're running as a headless peer, send a hello message every N seconds to refresh the posts we have.
|
||||
// let helloRefreshIntervalPeriod = 120;
|
||||
// if (app.isHeadless) {
|
||||
// console.log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// console.log.apply(null, log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// this.helloRefreshInterval = window.setInterval(() => {
|
||||
// console.log("wsConnection: Hello refresh.")
|
||||
// console.log.apply(null, log("wsConnection: Hello refresh.")
|
||||
|
||||
// if (!navigator.onLine) {
|
||||
// return;
|
||||
@@ -742,15 +742,15 @@ class wsConnection {
|
||||
};
|
||||
|
||||
// this.websocket.onopen = async (event) => {
|
||||
// log("ws:connected");
|
||||
// console.log.apply(null, log("ws:connected"));;
|
||||
// await this.sendHello();
|
||||
|
||||
// // If we're running as a headless peer, send a hello message every N seconds to refresh the posts we have.
|
||||
// let helloRefreshIntervalPeriod = 120;
|
||||
// if (app.isHeadless) {
|
||||
// console.log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// console.log.apply(null, log("wsConnection: Setting hello refresh interval to ", helloRefreshIntervalPeriod)
|
||||
// this.helloRefreshInterval = window.setInterval(() => {
|
||||
// console.log("wsConnection: Hello refresh.")
|
||||
// console.log.apply(null, log("wsConnection: Hello refresh.")
|
||||
|
||||
// if (!navigator.onLine) {
|
||||
// return;
|
||||
@@ -768,9 +768,9 @@ class wsConnection {
|
||||
// };
|
||||
|
||||
this.websocket.onclose = (event) => {
|
||||
log("ws:disconnected");
|
||||
console.log.apply(null, log("ws:disconnected"));;
|
||||
// this.retry *= 2;
|
||||
log(`Retrying in ${this.retry} seconds`);
|
||||
console.log.apply(null, log(`Retrying in ${this.retry} seconds`));;
|
||||
window.setTimeout(() => { this.connect(); }, this.retry * 1000);
|
||||
};
|
||||
|
||||
@@ -791,7 +791,7 @@ class wsConnection {
|
||||
};
|
||||
|
||||
this.websocket.onerror = (event) => {
|
||||
log('ws:error: ' + event);
|
||||
console.log.apply(null, log('ws:error: ' + event));;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -821,7 +821,8 @@ class App {
|
||||
|
||||
async connect() {
|
||||
this.peerManager = new PeerManager(this.userID, this.peerID, this.isBootstrapPeer);
|
||||
log("*************** before peerManager.connect");
|
||||
this.registerRPCs();
|
||||
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.
|
||||
@@ -836,17 +837,16 @@ class App {
|
||||
});
|
||||
|
||||
await this.peerManager.connect();
|
||||
log("*************** after peerManager.connect");
|
||||
console.log.apply(null, log("*************** after peerManager.connect"));;
|
||||
|
||||
|
||||
if (!this.isBootstrapPeer) {
|
||||
let postIDs = await this.peerManager.rpc.getPostIDsForUser(this.peerManager.bootstrapPeerID, this.userID);
|
||||
console.log("peerManager.rpc.getPostIDsForUser", postIDs);
|
||||
console.log.apply(null, log("peerManager.rpc.getPostIDsForUser", postIDs));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
getPreferentialUserID() {
|
||||
@@ -964,7 +964,7 @@ class App {
|
||||
|
||||
let output = [];
|
||||
|
||||
console.log("Serializing images");
|
||||
console.log.apply(null, log("Serializing images"));
|
||||
for (let post of posts) {
|
||||
let newPost = (post as any).data;
|
||||
|
||||
@@ -990,7 +990,7 @@ class App {
|
||||
}
|
||||
|
||||
async importTweetArchive(userID: string, tweetArchive: any[]) {
|
||||
log("Importing tweet archive")
|
||||
console.log.apply(null, log("Importing tweet archive"));
|
||||
let postsTestData: any[] = [];
|
||||
|
||||
// let response = await fetch("./tweets.js");
|
||||
@@ -1022,9 +1022,9 @@ class App {
|
||||
// if (response.status === 200) {
|
||||
// imageData = await response.arrayBuffer();
|
||||
// }
|
||||
// console.log(imageData);
|
||||
// console.log.apply(null, log(imageData);
|
||||
// } catch (e) {
|
||||
// console.log(e);
|
||||
// console.log.apply(null, log(e);
|
||||
// }
|
||||
|
||||
// }
|
||||
@@ -1037,7 +1037,7 @@ class App {
|
||||
|
||||
count++;
|
||||
if (count % 100 === 0) {
|
||||
log(`Imported ${count} posts...`);
|
||||
console.log.apply(null, log(`Imported ${count} posts...`));;
|
||||
// render(postsTestData);
|
||||
}
|
||||
|
||||
@@ -1062,14 +1062,14 @@ class App {
|
||||
|
||||
let registrations = await navigator.serviceWorker.getRegistrations();
|
||||
if (registrations.length > 0) {
|
||||
console.log("Service worker already registered.");
|
||||
console.log.apply(null, log("Service worker already registered."));
|
||||
return registrations[0];
|
||||
}
|
||||
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js")
|
||||
.then((registration) => {
|
||||
console.log("Service Worker registered with scope:", registration.scope);
|
||||
console.log.apply(null, log("Service Worker registered with scope:", registration.scope));
|
||||
return registration;
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -1079,7 +1079,7 @@ class App {
|
||||
|
||||
async compressImage(imageData: ArrayBuffer, mimeType: string, quality = 0.5): Promise<ArrayBuffer | null> {
|
||||
let uncompressedByteLength = imageData.byteLength;
|
||||
log(`compressImage input:${mimeType} size:${(uncompressedByteLength / 1024).toFixed(2)}KBi quality:${quality}`);
|
||||
console.log.apply(null, log(`compressImage input:${mimeType} size:${(uncompressedByteLength / 1024).toFixed(2)}KBi quality:${quality}`));;
|
||||
|
||||
try {
|
||||
// Convert ArrayBuffer to Blob
|
||||
@@ -1145,7 +1145,7 @@ class App {
|
||||
let compressedByteLength = compressedArrayBuffer.byteLength;
|
||||
|
||||
let percent = (uncompressedByteLength / compressedByteLength)
|
||||
log(`compressImage: compressedSize:${(compressedArrayBuffer.byteLength / 1024).toFixed(2)}KBi ${percent.toFixed(2)}:1 compression`);
|
||||
console.log.apply(null, log(`compressImage: compressedSize:${(compressedArrayBuffer.byteLength / 1024).toFixed(2)}KBi ${percent.toFixed(2)}:1 compression`));;
|
||||
return compressedArrayBuffer;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -1155,7 +1155,7 @@ class App {
|
||||
|
||||
async createNewPost(userID: string, postText: string, mediaData?: ArrayBuffer, mimeType?: "image/png" | "image/gif" | "image/jpg" | "image/jpeg" | "video/mp4") {
|
||||
if ((typeof postText !== "string") || postText.length === 0) {
|
||||
log("Not posting an empty string...")
|
||||
console.log.apply(null, log("Not posting an empty string..."));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1183,7 +1183,7 @@ class App {
|
||||
let id = localStorage.getItem("peer_id");
|
||||
|
||||
if (!id) {
|
||||
log(`Didn't find a peer ID, generating one`);
|
||||
console.log.apply(null, log(`Didn't find a peer ID, generating one`));;
|
||||
id = generateID();
|
||||
localStorage.setItem("peer_id", id);
|
||||
}
|
||||
@@ -1195,7 +1195,7 @@ class App {
|
||||
let id = localStorage.getItem("dandelion_id");
|
||||
|
||||
if (!id) {
|
||||
log(`Didn't find a user ID, generating one`);
|
||||
console.log.apply(null, log(`Didn't find a user ID, generating one`));;
|
||||
id = generateID();
|
||||
localStorage.setItem("dandelion_id", id);
|
||||
}
|
||||
@@ -1270,17 +1270,17 @@ class App {
|
||||
initOffline(connection: wsConnection) {
|
||||
// Event listener for going offline
|
||||
window.addEventListener('offline', () => {
|
||||
log("offline")
|
||||
console.log.apply(null, log("offline"));
|
||||
});
|
||||
|
||||
// Event listener for going online
|
||||
window.addEventListener('online', async () => {
|
||||
log("online")
|
||||
connection.connect();
|
||||
console.log.apply(null, log("online"));
|
||||
// connection.connect();
|
||||
this.render();
|
||||
});
|
||||
|
||||
log(`Online status: ${navigator.onLine ? "online" : "offline"}`)
|
||||
console.log.apply(null, log(`Online status: ${navigator.onLine ? "online" : "offline"}`));
|
||||
|
||||
}
|
||||
|
||||
@@ -1423,7 +1423,7 @@ class App {
|
||||
|
||||
let filePickerLabel = document.getElementById('file-input-label');
|
||||
filePickerLabel?.addEventListener('click', () => {
|
||||
console.log("Add pic...")
|
||||
console.log.apply(null, log("Add pic..."));
|
||||
})
|
||||
|
||||
|
||||
@@ -1436,7 +1436,7 @@ class App {
|
||||
// importTweetsButton.addEventListener('click', async () => {
|
||||
// let file = await this.selectFile('text/*');
|
||||
|
||||
// console.log(file);
|
||||
// console.log.apply(null, log(file);
|
||||
// if (file == null) {
|
||||
// return;
|
||||
// }
|
||||
@@ -1496,7 +1496,7 @@ class App {
|
||||
let posts: StoragePost[] = [];
|
||||
for (let followedID of this.following.keys()) {
|
||||
posts = posts.concat(await getData(followedID, new Date(2022, 8), new Date()));
|
||||
// console.log(followedID);
|
||||
// console.log.apply(null, log(followedID);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
@@ -1551,7 +1551,7 @@ class App {
|
||||
posts = await getData(userID, new Date(2022, 8), new Date());
|
||||
|
||||
if (posts.length > 0) {
|
||||
log(`Loaded ${posts.length} posts in ${this.timerDelta().toFixed(2)}ms`);
|
||||
console.log.apply(null, log(`Loaded ${posts.length} posts in ${this.timerDelta().toFixed(2)}ms`));;
|
||||
return posts;
|
||||
}
|
||||
|
||||
@@ -1576,14 +1576,14 @@ class App {
|
||||
|
||||
// let ids = await getAllIds(userID);
|
||||
// if (ids.length === 0) {
|
||||
// console.log(`Purging user ${userID}`);
|
||||
// console.log.apply(null, log(`Purging user ${userID}`);
|
||||
// indexedDB.deleteDatabase(`user_${userID}`);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
console.log(`${document.location.origin}/user/${userID}`);
|
||||
console.log.apply(null, log(`${document.location.origin}/user/${userID}`));
|
||||
|
||||
// console.log(`https://ddln.app/${this.username}/${uuidToBase58(userID)}`, userID);
|
||||
// console.log.apply(null, log(`https://ddln.app/${this.username}/${uuidToBase58(userID)}`, userID);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1608,12 +1608,12 @@ class App {
|
||||
}
|
||||
|
||||
this.peerManager.registerRPC('ping', (args: any) => {
|
||||
return {id:this.peerID};
|
||||
return {id:this.peerID, user:this.userID, user_name:this.username, peer_name:this.peername};
|
||||
});
|
||||
|
||||
if (!this.isBootstrapPeer) {
|
||||
let pong = await this.peerManager.rpc.ping(this.peerManager.bootstrapPeerID);
|
||||
console.log(pong);
|
||||
console.log.apply(null, log('pong from: ', pong));
|
||||
}
|
||||
|
||||
|
||||
@@ -1636,7 +1636,7 @@ class App {
|
||||
|
||||
let postIDs = await this.peerManager.rpc.getPostIDsForUser("dummy_peer", "bloop");
|
||||
|
||||
console.log("peerManager.rpc.getPostIDsForUser", postIDs);
|
||||
console.log.apply(null, log("peerManager.rpc.getPostIDsForUser", postIDs));
|
||||
|
||||
// this.peerManager.registerSearchQuery('find_peers_for_user', this.query_findPeersForUser);
|
||||
|
||||
@@ -1656,7 +1656,7 @@ class App {
|
||||
this.isHeadless = /\bHeadlessChrome\//.test(navigator.userAgent);
|
||||
this.isBootstrapPeer = urlParams.has("bootstrap");
|
||||
if (this.isBootstrapPeer) {
|
||||
log(`This is a bootstrap peer`);
|
||||
console.log.apply(null, log(`This is a bootstrap peer`));;
|
||||
}
|
||||
|
||||
this.peerID = this.getPeerID();
|
||||
@@ -1666,7 +1666,7 @@ class App {
|
||||
|
||||
this.connect();
|
||||
|
||||
this.registerRPCs();
|
||||
// this.registerRPCs();
|
||||
// this.testPeerManager();
|
||||
|
||||
// let peer: RTCPeerConnection | null = null;
|
||||
@@ -1687,7 +1687,7 @@ class App {
|
||||
|
||||
// peer.onicecandidate = ({ candidate }) => { log(`WRTC:${candidate?.address} ${candidate?.protocol} ${candidate?.type} ${(candidate as any)?.url}`) };
|
||||
// peer.onnegotiationneeded = async (event) => {
|
||||
// log("on negotiation needed fired");
|
||||
// console.log.apply(null, log("on negotiation needed fired"));;
|
||||
|
||||
// let makingOffer = false;
|
||||
|
||||
@@ -1722,7 +1722,7 @@ class App {
|
||||
|
||||
// peer.createOffer().then((description)=>{
|
||||
// peer.setLocalDescription(description)
|
||||
// log("RTC: " + description.sdp + description.type);
|
||||
// console.log.apply(null, log("RTC: " + description.sdp + description.type));;
|
||||
// });
|
||||
|
||||
// }
|
||||
@@ -1749,7 +1749,7 @@ class App {
|
||||
this.getRoute();
|
||||
|
||||
if (this.router.route === App.Route.CONNECT) {
|
||||
console.log('connect', this.router.userID);
|
||||
console.log.apply(null, log('connect', this.router.userID));
|
||||
localStorage.setItem("dandelion_id", this.router.userID);
|
||||
localStorage.removeItem("dandelion_username");
|
||||
}
|
||||
@@ -1775,7 +1775,7 @@ class App {
|
||||
// if (!isPersisted) {
|
||||
// debugger;
|
||||
// const isPersisted = await navigator.storage.persist();
|
||||
// log(`Persisted storage granted: ${isPersisted}`);
|
||||
// console.log.apply(null, log(`Persisted storage granted: ${isPersisted}`));;
|
||||
// }
|
||||
|
||||
// log(`Persisted: ${(await navigator?.storage?.persisted())?.toString()}`);
|
||||
@@ -1784,7 +1784,7 @@ class App {
|
||||
|
||||
// let main = await fetch("/main.js");
|
||||
// let code = await main.text();
|
||||
// console.log(code);
|
||||
// console.log.apply(null, log(code);
|
||||
// registration.active.postMessage({type:"updateMain", code:code});
|
||||
|
||||
// this.posts = await this.loadPosts(userID) ?? [];
|
||||
@@ -1794,7 +1794,7 @@ class App {
|
||||
await this.render(); // , (postID:string)=>{this.deletePost(userID, postID)}
|
||||
|
||||
if ((performance as any)?.memory) {
|
||||
log(`memory used: ${((performance as any).memory.usedJSHeapSize / 1024 / 1024).toFixed(2)}Mb`)
|
||||
console.log.apply(null, log(`memory used: ${((performance as any).memory.usedJSHeapSize / 1024 / 1024).toFixed(2)}Mb`));
|
||||
}
|
||||
|
||||
// if (navigator?.storage) {
|
||||
@@ -1815,7 +1815,7 @@ class App {
|
||||
|
||||
|
||||
|
||||
log(`username:${this.username} user:${this.userID} peername:${this.peername} peer:${this.peerID}`);
|
||||
console.log.apply(null, log(`username:${this.username} user:${this.userID} peername:${this.peername} peer:${this.peerID}`));;
|
||||
|
||||
// await this.purgeEmptyUsers();
|
||||
|
||||
@@ -1860,7 +1860,7 @@ class App {
|
||||
|
||||
async render() {
|
||||
if (this.isHeadless) {
|
||||
console.log('Headless so skipping render...');
|
||||
console.log.apply(null, log('Headless so skipping render...'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1906,7 +1906,7 @@ class App {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.log("Render: got a route I didn't understand. Rendering HOME:", this.router.route);
|
||||
console.log.apply(null, log("Render: got a route I didn't understand. Rendering HOME:", this.router.route));
|
||||
this.posts = await this.loadPostsFromStorage(this.userID) ?? [];
|
||||
break;
|
||||
}
|
||||
@@ -1938,7 +1938,7 @@ class App {
|
||||
// }
|
||||
// }
|
||||
|
||||
// console.log("added:", addedPosts, "removed:", deletedPosts);
|
||||
// console.log.apply(null, log("added:", addedPosts, "removed:", deletedPosts);
|
||||
|
||||
const fragment = document.createDocumentFragment();
|
||||
|
||||
@@ -1972,14 +1972,14 @@ class App {
|
||||
|
||||
let renderTime = this.timerDelta();
|
||||
|
||||
log(`render took: ${renderTime.toFixed(2)}ms`);
|
||||
console.log.apply(null, log(`render took: ${renderTime.toFixed(2)}ms`));;
|
||||
performance.mark("render-end");
|
||||
performance.measure('render-time', 'render-start', 'render-end');
|
||||
|
||||
|
||||
|
||||
// if ((performance as any)?.memory) {
|
||||
// log(`memory used: ${((performance as any).memory.usedJSHeapSize / 1024 / 1024).toFixed(2)}Mb`)
|
||||
// console.log.apply(null, log(`memory used: ${((performance as any).memory.usedJSHeapSize / 1024 / 1024).toFixed(2)}Mb`));
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -2092,7 +2092,7 @@ class App {
|
||||
|
||||
getRoute() {
|
||||
let path = document.location.pathname;
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>", path);
|
||||
console.log.apply(null, log("router: path ", path));
|
||||
|
||||
const regex = "(user/([a-zA-Z0-9\-]+)/?(post/([a-zA-Z0-9\-]+)?/?)?(media/([0-9]+)?)?)|(connect/([a-zA-Z0-9\-]+))";
|
||||
|
||||
@@ -2118,7 +2118,7 @@ class App {
|
||||
}
|
||||
}
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>", this.router.userID, this.router.postID, this.router.mediaID, App.Route[this.router.route]);
|
||||
console.log.apply(null, log("router: ", this.router.userID, this.router.postID, this.router.mediaID, App.Route[this.router.route]));
|
||||
|
||||
// user = /user/<ID>
|
||||
// post = /user/<ID>/post/<ID>
|
||||
|
||||
Reference in New Issue
Block a user