EOSE and pubkey

This commit is contained in:
Melvin Carvalho
2024-04-29 18:39:02 +02:00
parent b3c2dd56cf
commit faca61b6fe
2 changed files with 12 additions and 4 deletions

View File

@@ -1,21 +1,29 @@
; (() => { ; (() => {
globalThis.qs = Object.fromEntries(new URLSearchParams(document.location.search)) globalThis.qs = Object.fromEntries(new URLSearchParams(document.location.search))
var t = qs.t || 5 const t = qs.t || 5
if (qs.relay) { if (qs.relay) {
var socket = new WebSocket(qs.relay) const socket = new WebSocket(qs.relay)
socket.onopen = function (event) { socket.onopen = function (event) {
console.log('wss open', qs.relay) console.log('wss open', qs.relay)
let now = new Date().getTime() let now = new Date().getTime()
now = Math.floor(now / 1000.0) now = Math.floor(now / 1000.0)
let subscribe = `["REQ", "tail", {"since": ${now} }]` let subscribe = `["REQ", "tail", {"since": ${now} }]`
if (qs.pubkey) {
subscribe = `["REQ", "tail", { "authors": [${qs.pubkey}], "since": ${now} }]`
}
console.log(subscribe) console.log(subscribe)
socket.send(subscribe) socket.send(subscribe)
} }
socket.onmessage = function (event) { socket.onmessage = function (event) {
console.log('refreshing in', t) console.log('refreshing in', t)
const json = JSON.parse(event?.data)
if (json[0] === 'EOSE') {
console.log('EOSE')
return
}
setTimeout(() => { setTimeout(() => {
document.location.reload() document.location.reload()
}, t * 1000) }, t * 1000)

View File

@@ -1,6 +1,6 @@
{ {
"name": "nostrefresh", "name": "nostrefresh",
"version": "0.0.2", "version": "0.0.3",
"description": "refresh via nostr relay", "description": "refresh via nostr relay",
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",