mirror of
https://github.com/vitorpamplona/Nostryfied.git
synced 2025-06-06 18:31:07 +00:00
Enhancing visual of sending events.
This commit is contained in:
parent
0100def187
commit
611a52d3ba
@ -32,7 +32,7 @@ const fetchAndBroadcast = async () => {
|
|||||||
|
|
||||||
$('#checking-relays-header-box').css('display', 'flex')
|
$('#checking-relays-header-box').css('display', 'flex')
|
||||||
$('#checking-relays-box').css('display', 'flex')
|
$('#checking-relays-box').css('display', 'flex')
|
||||||
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th>From Key</th><th>About Key</th><th>Events</th>")
|
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th>From Key</th><th>About Key</th><th>Events</th><th></th>")
|
||||||
|
|
||||||
// get all events from relays
|
// get all events from relays
|
||||||
const filters =[{ authors: [pubkey] }, { "#p": [pubkey] }]
|
const filters =[{ authors: [pubkey] }, { "#p": [pubkey] }]
|
||||||
@ -78,7 +78,7 @@ const fetchAndBroadcast = async () => {
|
|||||||
|
|
||||||
$('#checking-relays-header-box').css('display', 'flex')
|
$('#checking-relays-header-box').css('display', 'flex')
|
||||||
$('#checking-relays-box').css('display', 'flex')
|
$('#checking-relays-box').css('display', 'flex')
|
||||||
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th></th><th></th><th>Events</th>")
|
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th></th><th></th><th>Events</th><th>Message</th>")
|
||||||
|
|
||||||
await broadcastEvents(data)
|
await broadcastEvents(data)
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ const broadcast = async (data) => {
|
|||||||
|
|
||||||
$('#checking-relays-header-box').css('display', 'flex')
|
$('#checking-relays-header-box').css('display', 'flex')
|
||||||
$('#checking-relays-box').css('display', 'flex')
|
$('#checking-relays-box').css('display', 'flex')
|
||||||
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th></th><th></th><th>Events</th>")
|
$('#checking-relays-header').html("<th>Relay</th><th>Status</th><th></th><th></th><th>Events</th><th>Message</th>")
|
||||||
|
|
||||||
await broadcastEvents(data)
|
await broadcastEvents(data)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ const downloadFile = (data, fileName) => {
|
|||||||
tempLink.click()
|
tempLink.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateRelayStatus = (relay, status, addToCount, subscription, until, relayStatusAndCount) => {
|
const updateRelayStatus = (relay, status, addToCount, subscription, until, message, relayStatusAndCount) => {
|
||||||
if (relayStatusAndCount[relay] == undefined) {
|
if (relayStatusAndCount[relay] == undefined) {
|
||||||
relayStatusAndCount[relay] = {}
|
relayStatusAndCount[relay] = {}
|
||||||
}
|
}
|
||||||
@ -71,6 +71,9 @@ const updateRelayStatus = (relay, status, addToCount, subscription, until, relay
|
|||||||
if (subscription)
|
if (subscription)
|
||||||
relayStatusAndCount[relay].until[subscription] = until
|
relayStatusAndCount[relay].until[subscription] = until
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
relayStatusAndCount[relay].message = message
|
||||||
|
|
||||||
if (relayStatusAndCount[relay].count != undefined)
|
if (relayStatusAndCount[relay].count != undefined)
|
||||||
relayStatusAndCount[relay].count = relayStatusAndCount[relay].count + addToCount
|
relayStatusAndCount[relay].count = relayStatusAndCount[relay].count + addToCount
|
||||||
else
|
else
|
||||||
@ -98,9 +101,14 @@ const displayRelayStatus = (relayStatusAndCount) => {
|
|||||||
} else {
|
} else {
|
||||||
untilStr += "<td> </td> <td> </td>"
|
untilStr += "<td> </td> <td> </td>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let msg = ""
|
||||||
|
|
||||||
|
if (relayStatusAndCount[it].message)
|
||||||
|
msg = relayStatusAndCount[it].message
|
||||||
|
|
||||||
const relayName = it.replace("wss://", "").replace("ws://", "")
|
const relayName = it.replace("wss://", "").replace("ws://", "")
|
||||||
const line = "<td>" + relayName + "</td><td>" + relayStatusAndCount[it].status + "</td>" + untilStr + "<td>" + relayStatusAndCount[it].count + "</td>"
|
const line = "<td>" + relayName + "</td><td>" + relayStatusAndCount[it].status + "</td>" + untilStr + "<td>" + relayStatusAndCount[it].count + "</td>" + "<td>" + msg + "</td>"
|
||||||
|
|
||||||
const elemId = relayName.replaceAll(".", "-")
|
const elemId = relayName.replaceAll(".", "-")
|
||||||
|
|
||||||
@ -123,7 +131,7 @@ const displayRelayStatus = (relayStatusAndCount) => {
|
|||||||
const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, relayStatus) =>
|
const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, relayStatus) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
updateRelayStatus(relay, "Starting", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Starting", 0, undefined, undefined, undefined, relayStatus)
|
||||||
// open websocket
|
// open websocket
|
||||||
const ws = new WebSocket(relay)
|
const ws = new WebSocket(relay)
|
||||||
|
|
||||||
@ -166,7 +174,7 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
ws.close()
|
ws.close()
|
||||||
reject(relay)
|
reject(relay)
|
||||||
}, 10_000)
|
}, 10_000)
|
||||||
updateRelayStatus(relay, "Downloading", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Downloading", 0, undefined, undefined, undefined, relayStatus)
|
||||||
|
|
||||||
for (const [key, sub] of Object.entries(subscriptions)) {
|
for (const [key, sub] of Object.entries(subscriptions)) {
|
||||||
ws.send(JSON.stringify(['REQ', sub.id, sub.filter]))
|
ws.send(JSON.stringify(['REQ', sub.id, sub.filter]))
|
||||||
@ -210,7 +218,7 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
until = subscriptions[subscriptionId].lastEvent.created_at
|
until = subscriptions[subscriptionId].lastEvent.created_at
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRelayStatus(relay, undefined, 1, subscriptionId, until, relayStatus)
|
updateRelayStatus(relay, undefined, 1, subscriptionId, until, undefined, relayStatus)
|
||||||
|
|
||||||
// prevent duplicated events
|
// prevent duplicated events
|
||||||
if (events[id]) return
|
if (events[id]) return
|
||||||
@ -232,7 +240,7 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
|
|
||||||
let alldone = Object.values(subscriptions).every(filter => filter.done === true);
|
let alldone = Object.values(subscriptions).every(filter => filter.done === true);
|
||||||
if (alldone) {
|
if (alldone) {
|
||||||
updateRelayStatus(relay, "Done", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Done", 0, undefined, undefined, undefined, relayStatus)
|
||||||
ws.close()
|
ws.close()
|
||||||
resolve(relay)
|
resolve(relay)
|
||||||
}
|
}
|
||||||
@ -270,7 +278,7 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
|
|
||||||
let alldone = Object.values(subscriptions).every(filter => filter.done === true);
|
let alldone = Object.values(subscriptions).every(filter => filter.done === true);
|
||||||
if (alldone) {
|
if (alldone) {
|
||||||
updateRelayStatus(relay, "Done", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Done", 0, undefined, undefined, undefined, relayStatus)
|
||||||
ws.close()
|
ws.close()
|
||||||
resolve(relay)
|
resolve(relay)
|
||||||
}
|
}
|
||||||
@ -285,7 +293,7 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws.onerror = (err) => {
|
ws.onerror = (err) => {
|
||||||
updateRelayStatus(relay, "Done", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Done", 0, undefined, undefined, undefined, relayStatus)
|
||||||
try {
|
try {
|
||||||
ws.close()
|
ws.close()
|
||||||
reject(relay)
|
reject(relay)
|
||||||
@ -294,12 +302,12 @@ const fetchFromRelay = async (relay, filters, addedFilters, pubkey, events, rela
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws.onclose = (socket, event) => {
|
ws.onclose = (socket, event) => {
|
||||||
updateRelayStatus(relay, "Done", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Done", 0, undefined, undefined, undefined, relayStatus)
|
||||||
resolve(relay)
|
resolve(relay)
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception)
|
console.log(exception)
|
||||||
updateRelayStatus(relay, "Error", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Error", 0, undefined, undefined, undefined, relayStatus)
|
||||||
try {
|
try {
|
||||||
ws.close()
|
ws.close()
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
@ -378,7 +386,7 @@ const sendToRelay = async (relay, data, relayStatus) =>
|
|||||||
try {
|
try {
|
||||||
const ws = new WebSocket(relay)
|
const ws = new WebSocket(relay)
|
||||||
|
|
||||||
updateRelayStatus(relay, "Starting", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Starting", 0, undefined, undefined, undefined, relayStatus)
|
||||||
|
|
||||||
// prevent hanging forever
|
// prevent hanging forever
|
||||||
let myTimeout = setTimeout(() => {
|
let myTimeout = setTimeout(() => {
|
||||||
@ -388,7 +396,7 @@ const sendToRelay = async (relay, data, relayStatus) =>
|
|||||||
|
|
||||||
// fetch events from relay
|
// fetch events from relay
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
updateRelayStatus(relay, "Sending", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Sending", 0, undefined, undefined, undefined, relayStatus)
|
||||||
|
|
||||||
clearTimeout(myTimeout)
|
clearTimeout(myTimeout)
|
||||||
myTimeout = setTimeout(() => {
|
myTimeout = setTimeout(() => {
|
||||||
@ -406,13 +414,14 @@ const sendToRelay = async (relay, data, relayStatus) =>
|
|||||||
reject('timeout')
|
reject('timeout')
|
||||||
}, 10_000)
|
}, 10_000)
|
||||||
|
|
||||||
const [msgType, subscriptionId, inserted] = JSON.parse(event.data)
|
const [msgType, subscriptionId, inserted, message] = JSON.parse(event.data)
|
||||||
// event messages
|
// event messages
|
||||||
// end of subscription messages
|
// end of subscription messages
|
||||||
if (msgType === 'OK') {
|
if (msgType === 'OK') {
|
||||||
if (inserted == true) {
|
if (inserted == true) {
|
||||||
updateRelayStatus(relay, undefined, 1, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, undefined, 1, undefined, undefined, message, relayStatus)
|
||||||
} else {
|
} else {
|
||||||
|
updateRelayStatus(relay, undefined, 0, undefined, undefined, message, relayStatus)
|
||||||
console.log(relay, event.data)
|
console.log(relay, event.data)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -420,19 +429,19 @@ const sendToRelay = async (relay, data, relayStatus) =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws.onerror = (err) => {
|
ws.onerror = (err) => {
|
||||||
updateRelayStatus(relay, "Error", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Error", 0, undefined, undefined, undefined, relayStatus)
|
||||||
console.log("Error", err)
|
console.log("Error", err)
|
||||||
ws.close()
|
ws.close()
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
ws.onclose = (socket, event) => {
|
ws.onclose = (socket, event) => {
|
||||||
updateRelayStatus(relay, "Done", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Done", 0, undefined, undefined, undefined, relayStatus)
|
||||||
console.log("OnClose", relayStatus)
|
console.log("OnClose", relayStatus)
|
||||||
resolve()
|
resolve()
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception)
|
console.log(exception)
|
||||||
updateRelayStatus(relay, "Error", 0, undefined, undefined, relayStatus)
|
updateRelayStatus(relay, "Error", 0, undefined, undefined, undefined, relayStatus)
|
||||||
try {
|
try {
|
||||||
ws.close()
|
ws.close()
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user